Python's sqlite3 module: get query with escaped parameters

53 Views Asked by At

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.

0

There are 0 best solutions below