[DB-SIG] PEP249 - Proposed change to DB-API 2.0

Federico Di Gregorio fog@mixadlive.com
Fri, 27 Apr 2001 10:59:08 +0200


Scavenging the mail folder uncovered Chris Cogdon's letter:

> The difference between format and pyformat is really python specific. I
> dont know of any C DB-API's that accept python style formatting... in at
> least that case, and many other DBs where 'format' is used, python is used
> to turn the query and all the arguments into a single string, escaping
> each of the argument types appropriately.
> 
> Just looking at format and pyformat, I'd hate to have to write a wrapper
> function just because some Python API writer chose pyformat rather than
> format.... I /like/ the ability to specify my arguments positionally,
> rather than having to wrap them up in a dictionary.

i don't understand. the following code (taken from psycopg)
implements *both* format and pyformat:

    query = PyString_Format(str, dict_or_tuple)

that wotks both with %(name)s stype and a dict or %s stype and a tuple.

> A wrapper in this case is very difficult, too, since I'd have to parse the
> query for the %s's, then turn them into %(somevarN). Not trivial. It would
> be a /lot/ easier for the API writer to have two pieces of code that turn
> a format, and a pyformat, request into the appropriate chunks to pass to
> the C API.

sometimes it is much easier to format a full query string and simply
pass it to the C library, as we did.

> Of course, this is making a lot of assumptions about what the C API looks
> like. In both Mysql, and Postgresql's case, the API takes a single string.
> So... what's stopping Python API's for those two Databases from supporting
> /all/ the paramstyles?, since they all have to be interpreted one way or
> the other.

lack of time of the authors? we implemented the two param styles most
used, others will follow when somebody will request them or when i'll
have some free time... :)
 
> I can certainly see wanting to place a restriction on the paramstyle
> supported if the C API actually supported one or the other of the given
> types. But for the above two databases, there's no excuse. The python DB
> team could very well supply a library to assist API writers in this
> regard.

a well-written piece of C code that takes the args in python form
(the ones you give to PyArgs_ParseTuple) and parse any of the four
formats spitting out the query string will be much welcome...

ciao,
federico

-- 
Federico Di Gregorio
MIXAD LIVE Chief of Research & Technology              fog@mixadlive.com
Debian GNU/Linux Developer & Italian Press Contact        fog@debian.org
  Generated by Signify v1.07 [http://www.debian.org/]
                                      -- brought to you by One Line Spam