MySQLdb - parameterised SQL - how to see resulting SQL ?

Dan Sommers me at
Thu May 18 04:10:22 CEST 2006

On 17 May 2006 18:41:55 -0700,
shearichard at wrote:

> Hi - I've got SQL that looks like this ...
> cursor =
> self.MySQLDb_conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
> sqlQuery = "SELECT * FROM T1 WHERE C1 = %s and C2 = %s"
> sql = cursor.execute(sqlQuery,(strURLAlias,strSessionID))
> rows = cursor.fetchall()
> cursor.close

ITYM cursor.close()

> ... i would be interested in seeing what the actual SQL used by the
> .execute looks like after the replacements have been done. Is there a
> way of doing this ?

Taking a quick peek at pysqlite and the API spec, I'd say no, not a
standard way.

OTOH, eventually, mysqldb has to create that SQL in order to pass it to
the database for execution, so it's probably as simple as finding the
right place to put a "print" statement and/or to store the finished SQL
in the cursor object.


Dan Sommers
"I wish people would die in alphabetical order." -- My wife, the genealogist

More information about the Python-list mailing list