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

Kevin Jacobs jacobs at penguin.theopalgroup.com
Thu Jun 5 07:50:51 EDT 2003


On Thu, 5 Jun 2003, M.-A. Lemburg wrote:
> Gerhard Häring wrote:
> > If you want to add support for a new datatype for the DB-API module, 
> > this data type should implement a __quote__ method that returns the 
> > appropriate string.
> 
> Ouch. __xxx__ names are reserved for interpreter internal use.
> You shouldn't use those in your applications, since it is not
> clear what will happen to those names in the future, e.g. they
> could undergo some serious optimizations which could break your
> code.

I Agree: +10**10*10

> Other than that, I don't see why a data type should know about
> 10+ different database backends. The quoting mechanism for
> a particular database should know about the quoting, not the
> various data types.

Ditto.

> > PySQLite and pyPgSQL already have a _quote method like the module-level 
> > quote method Chris was arguing for. But it's currently only an 
> > implementation detail, not part of the public APIs.
> 
> Before going too much into details, we should vote for the kind
> of quoting mechanism you would like to have in the spec:
> 
> 1. quote(sql, parameters) -> quoted SQL statement with embedded SQL
>                               literals

+0 if it is option.  I certainly would _never_ use it, though.

> 2. quote(dataobject, datatype) -> quoted SQL literal

-1 for inclusion in DB-API

+1 for a higher-level API.  I'll even volunteer to manage such a project. 
   The only painful side is that every DB-API driver, even those for the same
   backend database, uses different backend type codes.

-Kevin

-- 
--
Kevin Jacobs
The OPAL Group - Enterprise Systems Architect
Voice: (216) 986-0710 x 19         E-mail: jacobs at theopalgroup.com
Fax:   (216) 986-0714              WWW:    http://www.theopalgroup.com




More information about the DB-SIG mailing list