classification
Title: sqlite3 mogrify - return query string
Type: enhancement Stage: resolved
Components: Extension Modules Versions: Python 3.2
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Sanjeev, goatbar, r.david.murray
Priority: normal Keywords:

Created on 2010-08-04 11:29 by goatbar, last changed 2013-03-21 03:07 by r.david.murray. This issue is now closed.

Messages (4)
msg112790 - (view) Author: Kurt Schwehr (goatbar) Date: 2010-08-04 11:29
Psycopg2 has a mogrify method on the cursor that returns the string that would be sent to the database for an execute.  Any chance that could be added to pysqlite?  It's definitely helpful for debugging and is a fantastic tool when teaching people databases.
msg112815 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-04 14:43
Can you propose a patch?
msg184813 - (view) Author: Sanjeev Paskaradevan (Sanjeev) Date: 2013-03-21 00:01
An implementation of mogrify for pysqlite will necessarily be different from the Psycopg2 implementation because of the way queries are executed in Psycopg2 vs. pysqlite.

In Pyscopg2 the arguments are bound into the query using mogrify and then executed using PQExec or PQsendQuery.

Whereas the pysqlite implementation uses sqlite3 prepared statements to bind the parameters using the interfaces defined here: http://www.sqlite.org/c3ref/bind_blob.html

As such, the pysqlite implementation never holds a "complete" sql statement with substituted parameters, as well, the sqlite3 C interfaces do not provide a way to retrive the complete statement.

We can implement a 'mogrify' method for pysqlite but by necessity it would not be "exactly" the same as the psycopg2 implementation.  For one thing the string thus generated would not be the statement that is sent to sqlite3.

Should we implement a mogrify anyway?
msg184837 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-03-21 03:07
Given what you have determined, I don't think there would be any benefit to such a method.

Furthermore, I have now remembered that as of Python 3.3 the sqlite3 module/sqlite3 has a set_trace_callback function that allows you to capture the commands that are sent to the database.  It doesn't work the same as mogrify, but it can serve the same purpose, since it shows the sql in expanded form, not in parameterized form.
History
Date User Action Args
2013-03-21 03:07:43r.david.murraysetstatus: open -> closed
resolution: rejected
messages: + msg184837

stage: test needed -> resolved
2013-03-21 00:01:04Sanjeevsetnosy: + Sanjeev
messages: + msg184813
2010-08-04 14:43:45r.david.murraysetversions: + Python 3.2, - Python 3.1, Python 2.7
nosy: + r.david.murray

messages: + msg112815

stage: test needed
2010-08-04 11:29:02goatbarcreate