我在 Python 中使用以下代码(使用 pyodbc 作为 MS-Access 基础)。
cursor.execute("select a from tbl where b=? and c=?", (x, y))
没关系,但是出于维护目的,我需要知道发送到数据库的完整且准确的 SQL 字符串。
这可能吗?如何实现?
因驾驶员而异。下面是两个例子:
import MySQLdb
mc = MySQLdb.connect()
r = mc.cursor()
r.execute('select %s, %s', ("foo", 2))
r._executed
"select 'foo', 2"
import psycopg2
pc = psycopg2.connect()
r = pc.cursor()
r.execute('select %s, %s', ('foo', 2))
r.query
"select E'foo', 2"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)