DB-API execute params, am I missing something?
Gabriel Rossetti
gabriel.rossetti at arimaz.com
Fri May 29 02:48:45 EDT 2009
Paul Boddie wrote:
> On 26 Mai, 13:46, Gabriel Rossetti <gabriel.rosse... at arimaz.com>
> wrote:
>
>> def getParams(curs):
>> curs.execute("select * from param where id=%d", 1001)
>>
>
> First of all, you should use the database module's parameter style,
> which is probably "%s" - something I've thought should be deprecated
> for a long time due to the confusion with string substitution that
> this causes, regardless of whether that mechanism is actually used
> internally by the module (as seen in your traceback).
>
> You also have to provide a sequence of parameters: unlike string
> substitution, you cannot provide a single parameter value and expect
> the execute method to do the right thing. Some database modules seem
> to insist on either lists or tuples of parameters, but I think any
> sequence type should work.
>
> Try this:
>
> curs.execute("select * from param where id=%s", (1001,))
>
> Paul
>
Thank you for the explanation Paul!
Gabriel
More information about the Python-list
mailing list