我似乎无法弄清楚我的代码有什么问题,但我不断得到:
error "binding parameter 0 - probably unsupported type".
这是我的代码:
last = 'EBERT'
sakila = connect("sakila.db")
res = sakila.execute("SELECT first_name, last_name FROM customer WHERE last_name = ?",[(last,)])
for row in res:
print(row)
当我在查询中找到 'EBERT
' 并且未设置为变量时,它工作正常,所以我知道这是元组语法或其他问题。我已经尝试过不带括号,为 first_name
使用第二个变量,有和没有单独定义的游标,基本上我能想到的每一种方法,我已经研究了几个小时但已经得到无处可去,因此我们将不胜感激。
最佳答案
嵌套列表,元组用于executemany
, 不适用于 execute
.
传递包含参数的平面列表(或元组)。
res = sakila.execute(
"SELECT first_name, last_name FROM customer WHERE last_name = ?",
(last,))
或
res = sakila.execute(
"SELECT first_name, last_name FROM customer WHERE last_name = ?",
[last])
关于python - 错误绑定(bind)参数 0 : probably unsupported type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21981709/