[Tutor] SQLite LIKE question

Tim Golden mail at timgolden.me.uk
Fri Apr 11 14:20:12 CEST 2008

Dinesh B Vadhia wrote:
> Okay, I've got this now:
>> con = sqlite3.connect(":memory:")
>> cur = con.cursor()
>> cur.execute("""CREATE TABLE db.table(col.a integer, col.b text)""")
>> con.executemany("""INSERT INTO db.table(col.a, col.b) VALUES (?, ?)""", m)
>> con.commit()
>> for row in con.execute("""SELECT col.a, col.b FROM db.table"""):
>>         print row
>> # when run, all rows are printed correctly but as unicode strings
>> q = "dog"
>> for row in con.execute("""SELECT col.b FROM db.table WHERE col.b LIKE ? LIMIT 25""", q):
>>        print row
> .. And, I get the following error:
> Traceback (most recent call last):
>     for row in con.execute("SELECT col.b FROM db.table WHERE col.b LIKE ? LIMIT 25", q):
>     ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 3 supplied.

Whenever you see this in a dbapi context, you can bet your socks
that you're passing a single item (such as a string, q) rather than
a list or tuple of items. Try passing [q] as the second parameter
to that .execute function and see what happens!


More information about the Tutor mailing list