DB-API format string conventions
Skip Montanaro
skip at pobox.com
Tue Dec 28 08:45:41 EST 2004
Craig> IMO it'd also be very nice to support **kw calling style, ie to
Craig> make:
Craig> cursor.execute("SELECT somerow FROM table WHERE otherrow = %(name)s",
Craig> {'name': 'fred'})
Craig> equivalent to:
Craig> cursor.execute("SELECT somerow FROM table WHERE otherrow = %(name)s",
Craig> name = 'fred')
Craig> frankly, I simply think it's a nicer and more readable calling
Craig> style when one is passing a list of parameters directly to
Craig> .execute() rather than passing an existing dict.
In my code I most often use locals() to map the local namespace into a
dictionary:
cursor.execute("SELECT somerow FROM table WHERE otherrow = %(name)s",
locals())
That works as long as there's a local variable named "name" in the local
namespace.
Craig> So ... anybody for a DB-API 2.1 with mandatory pyformat support
Craig> and a tuple dbmodule.paramstyles for supported styles?
The sybase-python module supports Sybase's "@" thingie in a straightforward
way:
cursor.execute("SELECT somerow FROM table WHERE otherrow = @name",
{"@name": "fred"})
This works for both selects as well as for the input and output parameters
of stored procedures (cursor.callproc).
Skip
More information about the Python-list
mailing list