So I am writing this program that converts the .csv files I have and in return exports the converted files to the database. The .csv files all have the same columns and I am trying to create multiple tables using a loop and i get this error.
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '''(\n
{} int,\n ' at line 1")
CODE:
country_index = input('Country Code: ')
def database_uploader():
conn = pymysql.connect(host='localhost',
user='test_user',
password='',
db='%s'%country_index)
cur = conn.cursor()
path = r'C:\Users\Robin\Desktop\usa_indicator'
filenames = glob.glob(path + '/*.csv')
dfs = []
for files in filenames:
f = open(files)
fString = f.read()
fName = files[37:2]
for lines in fString.split('\n'):
dfs.append(lines.split(','))
DATE = dfs[0][1]; REALTIME_START = dfs[0][2]; VALUE = dfs[0][3]
queryCreateTable = """CREATE TABLE '%s'(
{} int,
{} int,
{} int
)"""%fName.format(DATE, REALTIME_START, VALUE)
cur.execute(queryCreateTable)
conn.close()