[DB-SIG] API suggestion: expose 'quote' method

M.-A. Lemburg mal at lemburg.com
Thu Jun 5 13:16:10 EDT 2003

Chris Cogdon wrote:
> On Wednesday, Jun 4, 2003, at 01:02 US/Pacific, M.-A. Lemburg wrote:
>> Chris Cogdon wrote:
>>> But... I DO understand the difficulty in exposing a function that 
>>> doesn't currently exist (such as the ODBC driver). And it may NOT be 
>>> worth the difficulty in adding that functionality as a requirement 
>>> for a later API. (Perhaps optional? At least if it's doable, we could 
>>> get a consistent interface).
>> That we could do, but note that quoting would be requiring type
>> information in database specific ways, plus it may sometimes also
>> need encoding or code page information for string values, e.g.
>> a database running with UTF-8 code page will want to see UTF-8
>> in string literals.
> I believe the python driver ALREADY has access to this information, 
> since it needs it to determine how to correctly pass this information to 
> the DBMS, be it in a string or binary format. 

Not necessarily. In ODBC the database can tell the driver to send
the data using a certain data type, but that information is only
known for SQL statements that you actually plan to actually execute
(and not even in all cases).

I wonder whether you've seen a module I've been working on a few
years ago:


This tries to take care of quoting among other things. Note that
the information about how quoting is done can easily be separated
out of the DB-API layer and sometimes that makes more sense than
trying to put more load on the DB API implementors.

We use a much more advanced version of dbinfo.py in our commercial
software -- works great :-) We use it mostly to generate schemas
for various database backends.

Marc-Andre Lemburg

Professional Python Software directly from the Source  (#1, Jun 05 2003)
 >>> Python/Zope Products & Consulting ...         http://www.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
EuroPython 2003, Charleroi, Belgium:                        19 days left

More information about the DB-SIG mailing list