错误绑定参数0:可能是不受支持的类型
我似乎无法弄清楚我的代码出了什么问题,但是我不断得到:
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])