I have a really frustrating problem
I have a function that accepts a cursor to a sqlite3.Connection object and then modifies the database
my code is something like this:
#DOES NOT WORK
def update(dbc, tableName, value, value2):
dbc.execute("update ? set MyValue = ? where Something = ?;",\
[tableName, value, value2])
#WORKS
def update2(dbc, tableName value, value2):
dbc.execute("update {0} set MyValue = {1} where Something = {2};".format(
tableName, value, value2))
db = sqlite3.connect('data.db')
c = db.cursor()
c.execute("begin;")
update(c,"Something","Something Else") #FAILS
update2(c,"Something","Something Else") #OK
I get the error:
sqlite3.OperationalError: near "?": syntax error
I have tried commenting out the first execute("begin;") statement because I don't really understand it but I know that it speeds up my code dramatically in other parts instead of having to commit every single input. Does anyone have a clue why this is happening?