i have function that should make from xlsx file SQLite database, but i have syntax error and i cant find where. Please help. The error is: OperationalError: near "(": syntax error
code is here:
def xlsx_to_db(xlsx_file, con, db_name, cur):
import pandas as pd
cur.execute("""CREATE TABLE IF NOT EXISTS {0}(
{1} INTEGER NOT NULL,
{2} INTEGER NOT NULL,
{3} INTEGER NOT NULL,
{4} INTEGER NOT NULL,
{5} INTEGER NOT NULL
PRIMARY KEY ({1},{2},{3},{4})
)""".format("db1","[TypRefDokl]","[Č.refer.dokladu]","[Číslo dokladu]","[Řádka ref.dok.]","[Účetní řádka]"))
dfs = pd.read_excel(xlsx_file, index_col=([1, 2, 3, 4]))
for line in dfs.keys():
try:
cur.execute("ALTER TABLE {0} ADD {1} NOT NULL".format("db1","[" + line + "]"))
except:
pass
dfs.to_sql(db_name, con, index=True, if_exists="append")
con.commit()
return dfs
Thank you.