Error binding parameter 0: probably unsupported ty

2019-01-28 00:44发布

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". 

Here is my code:

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)

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.

3条回答
smile是对你的礼貌
2楼-- · 2019-01-28 00:57

res = sakila.execute( '''SELECT first_name, last_name FROM customer WHERE last_name = {0}'''.format(last))

this worked for me

查看更多
Lonely孤独者°
3楼-- · 2019-01-28 00:58

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

or

res = sakila.execute(
    "SELECT first_name, last_name FROM customer WHERE last_name = ?",
    [last])
查看更多
虎瘦雄心在
4楼-- · 2019-01-28 01:00

I was getting the same error, sorted out that my data type was mismatched. I then converted it into string;

cursor.execute('''INSERT INTO employees VALUES (?);''', (str(data[0]), ))

and it worked fine. Hope this will be helpful for someone.

查看更多
登录 后发表回答