简体   繁体   中英

Python's sqlite3 module: get query with escaped parameters

The sqlite3 module allows one to use parameter substitution for queries like so:

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. sqlite3 has an interface to fetch the expanded query, but the latest version of Python has no interfaces for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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