Search code examples
pythonsqlitepysqlite

Can I get the raw SQL generated by a prepared statement in Python’s sqlite3 module?


If so, how can I do this?


Solution

  • when you create a prepared statement, the "template" SQL code is sent to the DBMS already, which compiles it into an expression tree. When you pass the values, the corresponding library (python sqlite3 module in your case) doesn't merge the values into the statement. The DBMS does.

    If you still want to produce a normal SQL string, you can use string replace functions to replace the placeholders by the values (after escaping them).

    What do you need this for?