How to see the real SQL query in Python cursor.execute using pyodbc and MS-Access

前端 未结 9 1435
有刺的猬
有刺的猬 2020-12-04 17:17

I use the following code in Python (with pyodbc for a MS-Access base).

cursor.execute(\"select a from tbl where b=? and c=?\", (x, y))

It\'

9条回答
  •  天涯浪人
    2020-12-04 18:06

    The answer is : NO. I posted my question on the project's home Google Code (and in the Google Group) and the answer is:

    Comment #1 on issue 163 by l...@deller.id.au: cursor.mogrify return query string http://code.google.com/p/pyodbc/issues/detail?id=163

    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.

提交回复
热议问题