简体   繁体   English

Python 的 sqlite3 模块:使用转义参数获取查询

[英]Python's sqlite3 module: get query with escaped parameters

The sqlite3 module allows one to use parameter substitution for queries like so: sqlite3模块允许对查询使用参数替换,如下所示:

import sqlite3
con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("create table lang (name, first_appeared)")
cur.execute("insert into lang values (?, ?)", ("C", 1972))

I'd like to be able to get the "post-substitution" query string.我希望能够获得“替换后”查询字符串。 In the example above that would be:在上面的示例中,这将是:

"insert into lang values ('C', '1972')"

Can it be done?可以做到吗? There doesn't seem to be a documented means of doing this, but I'd settle for undocumented.似乎没有记录在案的方法可以做到这一点,但我愿意接受无证记录。

Unfortunately, it's not possible now with Python.不幸的是,现在 Python 不可能。 sqlite3 has an interface to fetch the expanded query, but the latest version of Python has no interfaces for that. sqlite3有一个接口来获取扩展查询,但最新版本的 Python 没有接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM