Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

python - Error binding parameter 0: probably unsupported type

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...