python & mysql probelm
Sibylle Koczian
Sibylle.Koczian at Bibliothek.Uni-Augsburg.de
Wed Mar 31 06:21:19 EST 2004
Robert Brewer schrieb:
> james blair wrote:
>
>>I am having a problem executing following query:
>>cursor.execute("select * from projects where projectid between '%s'
>>and '%s'"%(id1,id2))
> Try dropping the single quotes around each %s
>
> cursor.execute("select * from projects where projectid "
> "between %s and %s" % (id1, id2))
But why not use a genuine parametrized query:
cursor.execute("select * from projects where projectid "
"between %s and %s", (id1, id2))
Especially if you need to execute the same query several times with
changing parameters this is faster as far as I know, because the query
is prepared once.
Koczian
--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : Sibylle.Koczian at Bibliothek.Uni-Augsburg.DE
More information about the Python-list
mailing list