LogoLogo
7.10.0
7.10.0
  • Introduction
  • What's New?
  • Installation & Usage
  • Migration Guide
  • Contributing & Filing Issues
  • Query Builder
    • Getting a New Query
    • Building Queries
      • Selects
      • From
      • Joins
      • Wheres
      • Order By
      • Group By and Having
      • Limit, Offset, and Pagination
      • Unions
      • Common Table Expressions (i.e. CTEs)
      • Raw Expressions
      • When / Conditionals
      • Query Parameters and Bindings
    • Executing Queries
      • Retrieving Results
      • Aggregates
      • Inserts, Updates, and Deletes
    • Options and Utilities
      • Query Options
      • Clone
      • Return Format
      • Column Formatter
      • Parent Query
      • Interception Points
    • Debugging
  • Schema Builder
    • Overview
    • Create
    • Columns
    • Column Modifiers
    • Column Constraints
    • Creating Table Constraints
    • Alter
    • Drop
  • External Links
    • API Docs
    • Source Code
    • Issue Tracker
Powered by GitBook
On this page
  • Debugging a Single Query
  • toSQL
  • tap
  • Debugging All Queries
  • cbDebugger
  • LogBox Appender
  • ColdBox Interception Points

Was this helpful?

Edit on Git
Export as PDF
  1. Query Builder

Debugging

Debugging a Single Query

toSQL

Name

Type

Required

Default

Description

showBindings

boolean

false

​false

If true, the bindings for the query will be substituted back in where the question marks (?) appear.

Returns the SQL that would be executed for the current query.

QueryBuilder
var q = query.from( "users" )
    .where( "active", "=", 1 );

writeOutput( q.toSQL() );
Result
SELECT * FROM "users" WHERE "active" = ?

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.

QueryBuilder
var q = query.from( "users" )
    .where( "active", "=", 1 );

writeOutput( q.toSQL( showBindings = true ) );
Result
SELECT * FROM "users" WHERE "active" = {"value":1,"cfsqltype":"CF_SQL_NUMERIC","null":false}

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.

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.

QueryBuilder
query.from( "users" )
    .tap( function( q ) {
        writeOutput( q.toSQL() & "<br>" );
    } )
    .where( "active", "=", 1 )
    .tap( function( q ) {
        writeOutput( q.toSQL() & "<br>" );
    } );
Result
SELECT * FROM "users"
SELECT * FROM "users" WHERE "active" = ?

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.

config/ColdBox.cfc
logbox = {
    debug = [ "qb.models.Grammars" ]
};

ColdBox Interception Points

PreviousInterception PointsNextOverview

Last updated 5 years ago

Was this helpful?

Starting in 2.0.0 you can view all your qb queries for a request. This is enabled by default if you have qb installed. Make sure your debug output is configured correctly and scroll to the bottom of the page to find the debug output.

qb can be quite chatty when executing many database queries. Make sure that this logging is only enabled for your development environments using .

ColdBox Interception Points can also be used for logging, though you may find it easier to use LogBox. See the documentation for for more information.

cbDebugger
ColdBox's environment controls
qb's Interception Points