[Tutor] Fw: SQLite LIKE question

Dinesh B Vadhia dineshbvadhia at hotmail.com
Fri Apr 11 09:10:58 CEST 2008


Try again:  
I'm using the LIKE operator to match a pattern against a string using this SELECT statement:

for row in con.execute("SELECT <column> FROM <table> WHERE <string> LIKE '%q%' limit 25"):


.. where <column>, <table>, <string> are placeholders!

With q="dog" as a test example, I've tried '$q%', '%q%', '%q' and 'q%' and none of them return what I expect ie. all strings with the characters "dog" in them.

Cheers!

Dinesh


----- Original Message ----- 
From: Dinesh B Vadhia 
To: tutor at python.org 
Sent: Thursday, April 10, 2008 3:24 PM
Subject: SQLite LIKE question


I'm reading a text file into an in-memory pysqlite table.  When I do a SELECT on the table, I get a 'u' in front of each returned row eg.

> (u'QB VII',)
> (u'Quackser Fortune Has a Cousin in the Bronx',)

I've checked the data being INSERT'ed into the table and it has no 'u'.

The second problem is that I'm using the LIKE operator to match a pattern against a string but am getting garbage results.  For example, looking for the characters q='dog' in each string the SELECT statement is as follows:

for row in con.execute("SELECT <column> FROM <table> WHERE <string> LIKE '%q%' limit 25"):
    print row

This doesn't work and I've tried other combinations without luck!  Any thoughts on the correct syntax for the LIKE?

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


More information about the Tutor mailing list