[DB-SIG] mogrify/query for adodbapi

William Dode wilk at flibuste.net
Sun Feb 13 19:19:08 CET 2011


On 13-02-2011, Vernon Cole wrote:
> --===============0804799855==
> Content-Type: multipart/alternative; boundary=0016e644df66158a5b049c2cec40
>
> --0016e644df66158a5b049c2cec40
> Content-Type: text/plain; charset=ISO-8859-1
> Content-Transfer-Encoding: quoted-printable
>
> This sounds like a handy feature.  Recent releases of adodbapi allow the
> programmer to specify the paramstyle she wishes to use. If she uses 'qmark'
> (the default) her query is used unchanged. If she uses 'named' or 'format',
> then her query is converted to 'qmark' before being used.
>   The cursor stores an ADODB.Command structure as its .cmd attribute. The
> (converted) query text is stored in the .cmd.CommandText attribute. There i=
> s
> no storage of the original query, although it might be an optimization to
> keep it around to avoid re-parsing.
>
> Q) Should a reference to cursor.query return the original query text, or th=
> e
> reformatted version?

Same as mogrify

>>> cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (42, 'bar'))
>>> cur.query
"INSERT INTO test (num, data) VALUES (42, E'bar')"


>
> Q) What is "mogrify"? Is that a reformatted version?

mogrify(operation[, parameters])¶

    Return a query string after arguments binding. The string returned is exactly the one that would be sent to the database running the execute() method or similar.

    >>> cur.mogrify("INSERT INTO test (num, data) VALUES (%s, %s)", (42, 'bar'))
    "INSERT INTO test (num, data) VALUES (42, E'bar')"

I use to log it and some times use it to copy and paste.


-- 
William Dodé http://flibuste.net
Informaticien Indépendant



More information about the DB-SIG mailing list