Re: [Tutor] SQLite LIKE question

2008-04-12 Thread Dinesh B Vadhia
OTECTED]> Subject: Re: [Tutor] SQLite LIKE question Cc: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Dinesh B Vadhia wrote: > Okay, I've got this now: > >> con = sqlite3.connect(":memory:") >> c

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Alan Gauld
"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote > 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 (q) is not a tuple, it is a variable surrounded by qu

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Tim Golden
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.e

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Dinesh B Vadhia
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

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Steve Willoughby
Simone wrote: > In Python the symbol '%' in a string is a special char: you use it, for > instance, to place a variable inside a string. For completeness, it's worth mentioning in passing that % is only special when you're doing string formatting. It's not otherwise special in strings. > Howeve

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread linuxian iandsd
i forgot to mention that you need to try your sql commands out of your script before trying them inside, ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread linuxian iandsd
I m not sure this is your case but i believe you are missing the "cur.fetchall()" command which does fetch data from sql db i suggest you put a print statement for every data you use in your program that way you know whats empty & whats not... here is example of MySQLdb process: con=MySQLdb.c

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Simone
Dinesh B Vadhia ha scritto: > 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

Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Alan Gauld
"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote > I'm using the LIKE operator to match a pattern against a string > using this SELECT statement: > > for row in con.execute(" > SELECT > FROM > WHERE LIKE '%q%' > limit 25"): > With q="dog" as a test example, I've tried '$q%', '%q%', '%q' Ok,

Re: [Tutor] SQLite LIKE question

2008-04-10 Thread Alan Gauld
"Dinesh B Vadhia" <[EMAIL PROTECTED]> 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 seco

[Tutor] SQLite LIKE question

2008-04-10 Thread Dinesh B Vadhia
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