I am trying to create a SQL database which will have many columns (around 4030). Therefore I cannot use
ALTER TABLE table_name ADD column_name
for every column. Now I am trying to do multiple ALTER TABLE operation but I know that, there's no loop in the ADD branch so no repetition is allowed. So I tried another way to implement my table. I tried,
c.execute('''ALTER TABLE table_name ADD (?) ''',k) #k changes in every iteration
The code that I wrote in below.
import scipy.io
import sqlite3
import os
# another irrelevant codes here...
conn = sqlite3.connect('CANBUS.db') #connection to .db
matFile = scipy.io.loadmat('folder/table.mat') #column names comes from here
c = conn.cursor() #cursor function I do not know that function well
c.execute('''CREATE TABLE IF NOT EXISTS table_name (ID integer PRIMARY KEY)''')
for k in matFile:
c.execute('''ALTER TABLE table_name ADD (?) ''',k) #k changes in every loop
I encounter an error which is basically a syntax error, I understood that in SQLite not allowed to do ALTER TABLE table_name ADD (?),k
command.
The message in the console was this. How can I add multiple columns in a single command?
c.executemany('''ALTER TABLE table_name ADD (?) ''',k)
OperationalError: near "(": syntax error
Thank you for your advices.