我有一个非常令人沮丧的问题
我有一个函数接受一个指向 sqlite3.Connection 对象的游标,然后修改数据库
我的代码是这样的:
#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
我得到错误:
sqlite3.OperationalError:靠近“?”:语法错误
我尝试注释掉第一个 execute("begin;") 语句,因为我不太了解它,但我知道它在其他部分显着加快了我的代码速度,而不必提交每一个输入。有谁知道为什么会这样?