[Tutor] SQLite LIKE question

Alan Gauld alan.gauld at btinternet.com
Fri Apr 11 01:26:06 CEST 2008

"Dinesh B Vadhia" <dineshbvadhia at hotmail.com> wrote

> 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',)

The u is not part of the data its Python telling you that
the string is Unicode.

> The second problem is that I'm using the LIKE operator
> to match a pattern against a string but am getting garbage
> results.

Can you be more specidic?
Can you post the statement and the 'garbage'?

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

Is thios the actual string or have you put the placemarkers (<column> 
in just for the post? You do realise that the things inside <> are 
to be replaced with the actual values from your database. Thus a
realistic string would look like

"SELECT Name FROM Person WHERE Name LIKE '%q%"

Which would return all Names with q in them.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list