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

查看:155
本文介绍了如何使用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 ?

推荐答案

答案是:否. 我在项目的本地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:

l ... @ deller.id.au关于问题163的评论#1: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文档 迁移"游标的方法 记者指: http://initd.org/psycopg/docs/cursor.html#cursor.气死

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驱动程序中执行 发送到服务器(例如Microsoft SQL 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天全站免登陆