You can trace all SQL going through both a database connection or
query. Both the Database
and Query
objects have a debug()
method. If you pass
true
to this method, then all SQL executed by the object will
be printed to standard error before it is executed.
The value set on a database object is inherited by its queries. This if
you enable debugging, then all queries subsequently created from that database
object will have their debug flags turned on as well. Likewise, you can set
debug states individually for queries by calling their respective
debug
methods.
# Enable tracing/debugging db.debug true # q1 has debugging on b/c it is set on db q1 = db.query() # Can turn it off: q1.debug false db.debug false # q2 has debugging off q2 = db.query()