python提供的绑定数量不正确

时间:2015-11-17 22:38:59

标签: python sqlite

我在sqllite

中执行以下查询
idP = cur.execute('SELECT id from profs where name = ?',name)

我有一个这样的数据库表:

| id |   name   |
| 1  |  xxxxxx  |

但是我收到了一个错误:提供的绑定数量不正确。当前语句使用1,并且提供了6个。

我认为字符串' xxxxxx'被视为六个人物。

2 个答案:

答案 0 :(得分:1)

您可以尝试将参数转换为元组:

idP = cur.execute('SELECT id from profs where name = ?',(name,))

答案 1 :(得分:0)

在这种情况下,execute方法需要长度为1的iterable(list,tuple等)作为bindings参数。因此,当您传入字符串时,它会尝试迭代字符串。您应该将字符串放入列表中并将其传入:

idP = cur.execute('SELECT id from profs where name = ?',[name])