[DB-SIG] pyformat Parameter Style
Federico Di Gregorio
fog at initd.org
Sun May 11 10:39:09 EDT 2003
Il sab, 2003-05-10 alle 20:05, Chris Cogdon ha scritto:
> On Saturday, May 10, 2003, at 10:54 US/Pacific, M.-A. Lemburg wrote:
>
> > The DB API says "Python extended format codes" meaning that all
> > valid Python formatting codes (including their parameters) may
> > be used.
>
> That's very interesting. Looking at some of the code I have, using, for
> example %(key)d would not work, even if the parameter was an integer,
> because the API turns each and every single parameter into a string
> regardless of the type.
>
> This code snippet from pyPgSQL.PgSQL:
>
> if len(parms) == 1 and \
> (type(parms[0]) in [DictType, ListType, TupleType]
> or \
> isinstance(parms[0],
> PgResultSet)):
> parms = _quoteall(parms[0])
> else:
> parms = tuple(map(_quote, parms));
> self.res = self.conn.conn.query(_qstr % parms)
>
> Notice how the parameters are 'quoted' first (which will turn them ALL
not to criticize pypgsql, but if its quoting code quotes integers, it is
quite dumb and does a little bit too much work (i can understand why it
does it that way, though.)
other adapter are a little bit smarter...
--
Federico Di Gregorio
Debian GNU/Linux Developer fog at debian.org
INIT.D Developer fog at initd.org
Viviamo in un mondo reale, Ciccio. -- Lucy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Questa parte del messaggio =?ISO-8859-1?Q?=E8?= firmata
Url : http://mail.python.org/pipermail/db-sig/attachments/20030511/22563133/attachment.bin
More information about the DB-SIG
mailing list