William Dode wrote:
> 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.

Since database adapater usually try to avoid merging the parameters
into the query string before sending them off to the server and
instead send the query and parameters separately (which is more
efficient and also allows caching of access plans on the server
side based on the query string), wouldn't it be better to log
both the query string and a Python repr() of the parameters
instead ?

That's how we have do such logging in our code and it works nicely.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 14 2011)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
_______________________________________________
DB-SIG maillist  -  DB-SIG@python.org
http://mail.python.org/mailman/listinfo/db-sig

Reply via email to