如何使用 pyodbc 和 MS-Access 在 Python cursor.execute 中查看真正的 SQL 查询 [英] How to see the real SQL query in Python cursor.execute using pyodbc and MS-Access

查看:28
本文介绍了如何使用 pyodbc 和 MS-Access 在 Python cursor.execute 中查看真正的 SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Python 中使用以下代码(使用 pyodbc 作为 MS-Access 基础).

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))

没关系,但出于维护目的,我需要知道发送到数据库的完整准确的 SQL 字符串.
是否可能以及如何实现?

It's Ok but, for maintenance purposes, I need to know the complete and exact SQL string send to the database.
Is it possible and how ?

推荐答案

答案是:NO.我在项目的主页 Google 代码(以及 Google 群组)上发布了我的问题,答案是:

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

评论 #1 on issue 163 by l...@deller.id.au: cursor.mogrify 返回查询字符串http://code.google.com/p/pyodbc/issues/detail?id=163

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

这里有一个链接供参考他们的 pyscopg 文档mogrify"游标方法记者指的是:http://initd.org/psycopg/docs/cursor.html#cursor.mogrify

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 不执行任何此类操作SQL 的翻译:它通过参数化 SQL 直接到ODBC 驱动程序.唯一的涉及的处理是翻译从 Python 对象到 C 的参数ODBC API 支持的类型.

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.

对 SQL 的一些转换可能是在它之前的 ODBC 驱动程序中执行发送到服务器(例如 MicrosoftSQL Native Client 这样做)但这些转换是隐藏的pyodbc.

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.

因此我认为不是提供 mogrify 功能是可行的在pyodbc中.

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

这篇关于如何使用 pyodbc 和 MS-Access 在 Python cursor.execute 中查看真正的 SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆