Re: API 3.0 limiting paramstyle to ['named', 'qmark'] is okay. ('format' is not desirable)

Daniele Varrazzo <[email protected]>
Newsgroups gmane.comp.python.db
Message-ID <CA+mi_8aMFLTz-Qwnuz=jwHBw3gL+qZoAC4a3dzCx3arVQzz-TA@mail.gmail.com>
On Fri, May 17, 2013 at 5:22 PM, Michael Bayer <[email protected]> wrote:
>
> The major issue with format/pyformat is that too many DBAPIs take the easy way out and just run their string through Python's "%" operator.   This causes DBAPIs that use the format styles to behave differently from those that don't.   In particular, a problem I have with MySQL-python and *maybe* recent versions of psycopg2 (would have to check again) is that the behavior changes whether or not I pass parameters to cursor.execute(). The same statement that includes a "%" sign as part of the string must be passed without escaping when no list/dictionary is passed as the second argument, but when a list/dictionary is passed, the parsing changes and now the % sign has to be escaped normally.   This is an undocumented behavior that's directly a side effect of the DBAPI saying, "oh there's par
 ameters, let's call "stmt % params", vs. not.

On this specific point you are right, and just yesterday I had to
apologise for the inconsistency with a colleague of mine. This is
something I would probably fix in an eventual "psycopg3" that would
break compatibility with the past, but note that it would only affect
functions that use the % operator and have no parameter: a minimal
number (can't remember on top of my head if the % is used for other
syntactical elements in postgres: not that I recall).

OTOH if you want consistent behaviour with the %s and %%s just pass an
empty tuple to queries taking no argument. You are a framework, you
can do that (I would do that in psycopg by specifying the empty tuple
as default argument for execute's params, or or something semantically
equivalent).

-- Daniele
_______________________________________________
DB-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/db-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.