I want to write to multiple tables with sqlite, but I don't want to manually specify the query ahead of time (there are dozens of possible permutations).
So for example:
def insert_sqlite(tablename, data_list)
global dbc
dbc.execute("insert into " + tablename + " values (?)", data_list)
tables_and_data = {
'numbers_table': [1,2,3,4,5],
'text_table': ["pies","cakes"]
}
for key in tables_and_data:
insert_sqlite(key, tables_and_data[key])
I want two things to happen:
a) for the tablename to be set dynamically - I've not found a single example where this is done.
b) The data_list values to be correctly used - note that the length of the list varies (as per the example).
But the above doesn't work - How do I dynamically create a sqlite3.execute statement?
Thanks