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@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
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to