开发者

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

开发者 https://www.devze.com 2022-12-30 02:01 出处:网络
I开发者_开发问答f so, how can I do this?When executing a prepared statement, no new SQL is generated.

I开发者_开发问答f so, how can I do this?


When executing a prepared statement, no new SQL is generated. The idea of prepared statements is that the SQL query and its data are transmitted separately (that's why you don't have to escape any arguments) - the query is most likely only stored in an optimized form after preparing it.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号