Debugging
Debugging a Single Query
toSQL
Name
Type
Required
Default
Description
showBindings
boolean | string
false
false
If true
, the bindings for the query will be substituted back in where the question marks (?
) appear as cfqueryparam
structs. If inline
, the binding value will be substituted back creating a query that can be copy and pasted to run in a SQL client.
Returns the SQL that would be executed for the current query.
The bindings for the query are represented by question marks (?
) just as when using queryExecute
. qb can replace each question mark with the corresponding cfqueryparam
-compatible struct by passing showBindings = true
to the method.
If you want to show the SQL that would be executed for the update
, insert
, updateOrInsert
, or delete
methods, you can pass a toSQL = true
flag to those methods. Please see those individual methods for more information.
To get back a SQL string that can be copied and pasted into a SQL client to run can be retrieved by passing showBindings = "inline"
.
tap
Name
Type
Required
Default
Description
callback
Function
true
A function to execute with a clone of the current query.
Executes a callback with a clone of the current query passed to it. Any changes to the passed query is ignored and the original query returned.
While not strictly a debugging method, tap
makes it easy to see the changes to a query after each call without introducing temporary variables.
dump
Name
Type
Required
Default
Description
showBindings
boolean | string
false
false
If true
, the bindings for the query will be substituted back in where the question marks (?
) appear as cfqueryparam
structs. If inline
, the binding value will be substituted back creating a query that can be copy and pasted to run in a SQL client.
A shortcut for the most common use case of tap
. This forwards on the SQL for the current query to writeDump
. You can pass along any writeDump
argument to dump
and it will be forward on. Additionally, the showBindings
argument will be forwarded on to the toSQL
call.
pretend
A QueryBuilder
instance can be put into pretend mode by calling the pretend
method. In this mode, the QueryBuilder
will turn all query operations into no-ops. A log of the SQL that would have been executed can be retrieved from the query log.
queryLog
Each instance of a QueryBuilder
maintains a log of queries it executed. This can be accessed by calling getQueryLog
. This will return an array of structs like so:
Debugging All Queries
cbDebugger
LogBox Appender
qb is set to log all queries to a debug log out of the box. To enable this behavior, configure LogBox to allow debug logging from qb's grammar classes.
ColdBox Interception Points
Was this helpful?