python - 错误绑定(bind)参数 0 : probably unsupported type

标签 python python-3.x sqlite

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

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/

相关文章:

sqlite - 安装 HDBC-SQlite3 Haskell

Android 数据库错误 - getWriteableDatabase

python - Shell 脚本 “dvc pull” 无法在 Streamlit 服务器上运行

python - 无法导入已安装的模块(通过 pip)

python - 在类内部实例化对象

python-3.x - Python pandas 按枚举类值对数据帧进行排序

python - 迭代一个 numpy 矩阵行

c# - 是否有 Silverlight 支持的平面文件数据库?

python - “QueryResult”对象不可迭代 - 无法将 Dialogflow API 中的值返回到我的聊天机器人

python - 统计模型 ARIMA : how to get confidence/prediction interval?