1.4.6 Debugging

If debug is set to True in the cursor() method of the connection object then debugging information can be accessed from the debug attribute of the cursor. The Debug object returned has two attributes: sql is a list of all the SQL strings sent to the database, types is a list of the contents of the types cache after each SQL call.

You can use it like this:

# Table Person
+----------+-----------+---------+-------------+
| LastName | FirstName | Address | DateOfBirth |
+----------+-----------+---------+-------------+
| Smith    | John      | Bedford | 1980-01-01  |
+----------+-----------+---------+-------------+
| Doe      | John      | Oxford  | 1981-12-25  |
+----------+-----------+---------+-------------+

>>> cursor.debug.sql
[]
>>> cursor.debug.types
[]
>>> cursor.select('LastName', 'Person')
(DatabaseTuple(TupleDescriptor((['LastName'],)),('Smith','Doe')),)
>>> cursor.debug.sql
['SELECT LastName FROM Person']
>>> cursor.debug.types
[{'PERSON': {'LASTNAME': 2, 'FIRSTNAME': 2, 'ADDRESS': 3, 'DATEOFBIRTH': 6}}]

See About this document... for information on suggesting changes.