错误绑定参数 0:可能不受支持的类型 [英] Error binding parameter 0: probably unsupported type

查看:67
本文介绍了错误绑定参数 0:可能不受支持的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法弄清楚我的代码有什么问题,但我一直收到:

I can't seem to figure out what is wrong with my code, but I keep getting the:

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 的第二个变量,有和没有单独定义的游标,基本上我能想到的所有方法,我已经研究了几个小时,但已经得到无处可去,所以任何帮助将不胜感激.

When I have it where 'EBERT' is in the query and not set to a variable, it works fine, so I know it's a problem with the tuple syntax or something. I've tried it without the brackets, with a second variable for first_name, with and without a separately defined cursor, and basically every method I can think of, and I've researched for hours but have gotten nowhere, so any help would be super appreciated.

推荐答案

嵌套列表,元组用于 executemany,不适用于 执行.

Nested lists, tuples are used for executemany, not for execute.

传递包含参数的平面列表(或元组).

Pass a flat list (or tuple) that contians parameters.

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])

这篇关于错误绑定参数 0:可能不受支持的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆