python & mysql probelm
Sibylle Koczian
Sibylle.Koczian at Bibliothek.Uni-Augsburg.de
Wed Mar 31 08:19:21 EST 2004
Michael schrieb:
>
>> 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.
>
>
> Really? I have wondered what the difference was. Is there any other
> difference in doing it this way rather than with string substitution?
>
The result set should be the same in both cases. I think it's more
readable to use parameters: you clearly differentiate between the query
and its parameters. String substitution could just as well change the
query itself.
And if it isn't select but insert or update, you can use
cursor.executemany(SQLstatement, params)
where params is a list of tuples, to execute SQLstatement for every
parameter tuple.
HTH
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