[Tutor] SQLite LIKE question

Dinesh B Vadhia dineshbvadhia at hotmail.com
Fri Apr 11 14:13:03 CEST 2008


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.

As Python/pysqlite stores the items in the db.table as unicode strings, I've also run the code with q=u"dog" but get the same error. Same with putting the q as a tuple ie. (q) in the Select statement.  Btw, there are 73 instances of the substring 'dog' in db.table.  

Cheers

Dinesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080411/9545ac17/attachment.htm 


More information about the Tutor mailing list