ColdFusion Muse

Get SQL Source Code from Debug on CFMX

Mark Kruger August 31, 2004 11:15 AM Coldfusion & Databases Comments (2)

Here's a great CFMX function using the coldfusion.server.ServiceFactory class to get at the debugging information and extract just the generated SQL for a specific query.

Read More
  • Share:


  • Glenn Dominguez's Gravatar
    Posted By
    Glenn Dominguez | 9/23/06 1:35 AM
    You can turn on debugging if it's not already enabled with:

    The only problem here is that it won't work for the current request. Once the page is refreshed, debugging will be enabled. Also, if you want don't want the cf debug output, there is a method to disable it's display. I think it's cfdebugger.showDebug(0) or showDebugging(0), you can find out by cfdumping your cfdebugger var.
  • Glenn Dominguez's Gravatar
    Posted By
    Glenn Dominguez | 9/23/06 1:44 AM
    Sorry, but I forgot to comment on your last paragraph. You actually CAN get each of multiple queries from a page:

    <CFQUERY DBTYPE="query" NAME="getquery" DEBUG="false">
    SELECT body
    FROM events
    WHERE type='SqlQuery'
    ORRDER BY timestamp asc
    <cfset queries = ArrayNew(1)>
    <cfloop query="getquery">
    <cfset queries[currentrow] = body>

    I use code such as this to capture and store all insert, update and delete queries from my admin app.