错误绑定参数0:可能是不受支持的类型

发布于 2021-01-29 14:58:23

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

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

关注者
0
被浏览
82
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

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


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看