Bobspadger / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

cursor.mogrify return query string #163

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
For debug or log purposes it is usefull to have the exact query for debugging.
When you use :
cursor.execute("select a from tbl where b=? and c=?", (x, y))
you can't know what is the true SQL query sent to the database because the 
library do some things like quoting strings and escaping quotes

Some libraries have a mogrify method on the cursor that returns the string that 
would be sent to the database for an execute.

It would be another (better) way to have a cursor.sql property which contain 
the exact query after the cursor.execute.

Original issue reported on code.google.com by Phil.Pr...@gmail.com on 11 Mar 2011 at 9:00

GoogleCodeExporter commented 9 years ago
For reference here is a link to the pyscopg documentation of their "mogrify" 
cursor method that the reporter is referring to:
http://initd.org/psycopg/docs/cursor.html#cursor.mogrify

pyodbc does not perform any such translations of the SQL: it passes 
parameterized SQL straight through to the ODBC driver verbatim.  The only 
processing involved is translating parameters from Python objects to C types 
supported by the ODBC API.

Some transformation on the SQL may be performed in the ODBC driver before it is 
sent to the server (eg Microsoft SQL Native Client does this) but these 
transformations are hidden from pyodbc.

Consequently I think it is not feasible to provide a mogrify function in pyodbc.

Original comment by lukedell...@gmail.com on 16 Mar 2011 at 5:19

GoogleCodeExporter commented 9 years ago
Great comment by Luke.  Exactly so.

Closing.  Thanks Luke.

Original comment by mkleehammer on 27 Dec 2011 at 12:59