Re: sqlite3, qmarks, and NULL values

2009-05-22 Thread Lawrence D'Oliveiro
In message , Mitchell L Model wrote: > However, COL2 might be NULL. I can't figure out a value for y that would > retrieve rows for which COL2 is NULL. It seems to me that I have to > perform an awkward test to determine whether to execute a query with one > question mark or two. In SQL, NULL is

Re: sqlite3, qmarks, and NULL values

2009-05-20 Thread Marco Mariani
Mitchell L Model wrote: def lookupxy(x, y): if y: conn.execute("SELECT * FROM table WHERE COL1 = ? AND COL2 = ?", (x, y)) else: conn.execute("SELECT * FROM table WHERE COL1 = ? AND COL2 IS NULL", (x,))

Re: sqlite3, qmarks, and NULL values

2009-05-20 Thread Jean-Michel Pichavant
Erratum: please read 'if y is *not* None:'. (think that if y = 0, you won't execute the proper code block with 'if y:'). JM Jean-Michel Pichavant wrote: I fall into the same issue when using postgres. Your main concern is that NULL = NULL will return False. Could seems strange but it has mu

Re: sqlite3, qmarks, and NULL values

2009-05-20 Thread Jean-Michel Pichavant
I fall into the same issue when using postgres. Your main concern is that NULL = NULL will return False. Could seems strange but it has much advantages sometimes, however this is not the purpose. I found your solution quite acceptable. Just replace 'if y:' by 'if y is None:', add a comment to po

Re: sqlite3, qmarks, and NULL values

2009-05-20 Thread Peter Otten
Mitchell L Model wrote: > Suppose I have a simple query in sqlite3 in a function: > > def lookupxy(x, y): > conn.execute("SELECT * FROM table WHERE COL1 = ? AND COL2 = ?", > (x, y)) > > However, COL2 might be NULL. I can't figure out a value for y that would > re

Re: sqlite3, qmarks, and NULL values

2009-05-19 Thread John Machin
On May 20, 10:54 am, MRAB wrote: > Mitchell L Model wrote: > > Suppose I have a simple query in sqlite3 in a function: > > >     def lookupxy(x, y): > >         conn.execute("SELECT * FROM table WHERE COL1 = ? AND COL2 = ?", > >                      (x, y)) > > > However, COL2 might be NULL. I can

Re: sqlite3, qmarks, and NULL values

2009-05-19 Thread MRAB
Mitchell L Model wrote: Suppose I have a simple query in sqlite3 in a function: def lookupxy(x, y): conn.execute("SELECT * FROM table WHERE COL1 = ? AND COL2 = ?", (x, y)) However, COL2 might be NULL. I can't figure out a value for y that would retrieve rows fo