错误:
c = dbConnection.execute(" SELECT compid FROM" + tableToUse +" WHERE id =?",id) sqlite3.ProgrammingError:提供的绑定数量不正确。当前语句使用1,并且提供了2个。
当我这样做时:
def getcompid (dbConnection, tableToUse, id):
c = dbConnection.execute("SELECT compid FROM " + tableToUse + " WHERE id = ?", id)
manualcompid = [('8','from01'),('35','28')]
for manid in manualcompid:
ERROR:
foundid = getcompid (dbConnection, tableToUse, manid[0])
OR SAME ERROR:
r = str(manid[0])
foundid = getcompid (dbConnection, tableToUse, r)
THE BELOW IS FINE:
foundid = getcompid (dbConnection, tableToUse, '8')
它对我的接触r
应该是简单的' string
与' 8'相同,更多manid[0]
已经是字符串。为什么错误?
为什么我必须使用:foundid = getcompid (dbConnection, tableToUse, (manid[0],))
?
答案 0 :(得分:1)
绑定需要在列表或元组中。试试这个:
c = dbConnection.execute(
"SELECT compid FROM " + tableToUse + " WHERE id = ?", [id])