Re: psycopg2 gets confused by % characters and strict pyformat mode
Cezary Statkiewicz <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On czwartek 11 września 2008, Federico Di Gregorio wrote:
> Il giorno gio, 11/09/2008 alle 11.34 +1000, Alejandro Dubrovsky ha
scritto:
> > > Isn't that likely to break existing applications that depend on
the
> > > current behaviour? From what I can see, the current behaviour
when
> > > parameters are passed matches the DB-API specification.
> > >
> > > It is debatable whether the behaviour when no parameters are
passed is
> > > correct (should it parse the '%' signs in that case?), but this
> > > proposal seem to move things further away.
> > >
> >
> > My suggestion was to have a settable mode whereby strings like '%s'
are
> > ignored, and only %(these)s are taken into account.
> > eg
> > pyscopg2.paramstylestrict = True
> >
> > Default behaviour would remain unchanged.
>
> I'd make it a .strictparamstyle attribute that can be se to "format"
or
> "pyformat" to select a single behaviour. Setting it to None (the
> default) would just make psycopg behave as it currently does.
Please, don't. It's not a psycopg bug, it's python's string
interpolation behaviour:
http://docs.python.org/lib/typesseq-strings.html
It's better to escape two first % chars, and give empty dict to enforce
interpolation of query (and unescape %) when there's no real
parameters.
Best regards,
Cezary Statkiewicz
--
Cezary Statkiewicz - http://thelirium.net
rlu#280280 gg#5223219
jabber://cezio-/[email protected]