MySQLdb select
Gerhard Häring
gh at ghaering.de
Sat Jul 31 10:35:53 EDT 2004
F. GEIGER wrote:
> "John Fabiani" <jfabiani at yolo.com> schrieb:
>
>>Hi,
>> I'm a newbie and I'm attempting to learn howto create a select statement.
>>When I use
>>
>>>>>string1='18 Tadlock Place'
>>>>>cursor.execute("SELECT * FROM mytest where address = %s",string1)
>>
>>All works as expected. But
>>
>>>>>numb=10
>>>>>cursor.execute("SELECT * FROM mytest where clientID = %d",numb)
>> [...] raise errorclass, errorvalue
>>TypeError: int argument required
>>
Then use %i for integers ;-)
> I'm used to do that this way:
>
> cursor.execute("SELECT * FROM mytest where clientID = %d" % numb)
That's particularly BAD STYLE. It's best to keep to letting the DB-API
do the proper quoting for all parameters.
-- Gerhard
More information about the Python-list
mailing list