python & mysql probelm

Robert Brewer fumanchu at amor.org
Fri Mar 26 16:25:37 EST 2004


james blair wrote:
> I am having a problem executing following query:
> cursor.execute("select * from projects where projectid between '%s'
> and '%s'"%(id1,id2))
> But say if i have projectid's from 1 to 20 in database & if i give the
> project range 1 to 2 then it gives me the result 1,2,11,12,13,14.....
> When I execute this query in mysql i.e
> select * from projects where projectid between 1 and 2,I get the
> correct result.
> I also tried doing 
> cursor.execute("select * from projects where projectid between '%s'
> and '%s'"%(int(id1),int(id2))
> but no success
> What should I do??

Try dropping the single quotes around each %s

cursor.execute("select * from projects where projectid "
               "between %s and %s" % (id1, id2))

FuManChu




More information about the Python-list mailing list