【发布时间】:2016-01-01 22:49:09
【问题描述】:
我知道 Stack Overflow 上有很多关于这个错误的问题,但我尝试了很多解决方案,显然它们都失败了。
这是一个列表:
SQLite parameter substitution problem
sqlite3.ProgrammingError: Incorrect number of bindings supplied
Reading from database with SQLite and Python: Incorrect number of binding supplied
SQLite Python Insert - Incorrect Number of Bindings Supplied
我正在尝试将用户名和散列密码(由 PassLib - https://pythonhosted.org/passlib/ 创建)存储在 SQLite3 数据库中。这些分别存储在变量“targetusername”和“password”中。我的问题是,当我实际尝试将这两个变量插入到名为“Passwords”的数据库表中时,会出现以下错误:
Incorrect number of bindings supplied. The current statement uses 1, and there are 11 supplied.
以下是目标用户名和密码将存储的示例:
targetusername = "user4884072"
password = "$5$rounds=535000$ySH31paWMjEDCUUY$jdrBVGsoYnSMkdVBtjCaxQy2f0g3MX1Wts4vSYz7m.4"
这一行给出了错误:
c.executemany("INSERT INTO {tn} ({idf}, {cn}) VALUES(targetusername, %s" % str(password).\
format(tn="Passwords"))
为了解决这个问题已经多次修改(这显然是由 Python 存储变量的方式引起的),但它最初是这样的:
c.execute("INSERT OR IGNORE INTO {tn} ({idf}, {cn}) VALUES (targetusername, password)".\
format(tn="Passwords", idf="Username", cn="Password"))
【问题讨论】:
标签: python database python-3.x sqlite