2012-12-10 186 views
2

我有以下Python代码,当我执行它,它给我的错误,错误说变量替换

sqlite3.OperationalError: near "%": syntax error

statement = "INSERT INTO %s (%s) VALUES " % (table,columns) + "(%s,%s,%s);" 
cur.execute(statement, (index,fullpath,filename)) 

回答

2

SQL参数是由数据库来处理,而不是由Python的,所以语法不一定与Python相同。

SQLite中(以及大多数其他数据库),参数都打上了?

statement = "INSERT INTO %s (%s) VALUES (?,?,?);" % (table,columns) 
cur.execute(statement, (index,fullpath,filename)) 
+0

谢谢它的工作,取代+ “(%S,%S,S);”与?诀窍 –