problem with sqlite3: cannot use < in a SQL query with (?)

lgabiot lgabiot at hotmail.com
Wed Jan 22 21:32:37 EST 2014


Hello,

I'm building an application using a simple sqlite3 database.
At some point, I need to select rows (more precisely some fields in 
rows) that have the following property: their field max_level (an INT),
should not exceed a value stored in a variable called threshold, where 
an int is stored (value 20000).
(threshold needs to be set by the user, so I cannot hard code a value 
there).

My database already exist on my drive (and of course the sqlite3 module 
is imported)

I do the following:

 >>>conn = sqlite3.connect(mydb) # open the database
that's OK

 >>>cursor = conn.execute("SELECT filename, filepath  FROM files WHERE 
max_level<(?)", threshold)
that doesn't work (throw an exception)

if I do:
 >>>cursor = conn.execute("SELECT filename, filepath  FROM files WHERE 
max_level<20000)")
it works...

I did similar operations on UPDATE instead of SELECT, and it works there.
Maybe my mind is fried right now, but I can't figure out the solution...

best regards.



More information about the Python-list mailing list