我似乎无法弄清楚我的代码出了什么问题,但是我不断得到:

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变量,有没有单独定义的游标,基本上我能想到的每种方法,我已经研究了数小时,但是却无济于事,所以任何帮助 super 赞赏。

最佳答案

嵌套列表,元组用于 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])

10-06 00:03