Using pysqlite I am making a procedure to do something with some data. The same kind of operation is done on similar fields in multiple tables and columns, so I thought I could parameterize the sql statement as shown below:
def foo():
column = c
table = t
row = 1
# preferred approach, gives syntax error
c.execute( SELECT ? FROM ? WHERE id=? , (column, table, row))
# sanity check, works fine
c.execute( SELECT c FROM t WHERE id=? , (row))
# workaround, also works, but is this the right way?
c.execute( SELECT % FROM % WHERE id=? % (column, table), row))
我发现的错误并不非常有用(sqlite3.Operationalalal 错误:接近“?”: syntax误差
,但我看上去:Pysqlite并不欣赏以这种方式使用土地持有人。
谁能指出,在这样做的同时,还有哪些进展?