[thelist] ColdFusion: logging cfqueries

Jon Hall jonhall at ozline.net
Mon Aug 26 16:46:01 CDT 2002


Ben Forta posted some code a few months to cf-talk a few months ago.

...
Execution time is easy, just use CFQUERY.ExecutionTime. Getting the SQL
statement is harder, but, if you are using CFMX and have debugging
turned on, here is a function that will do it:


<!--- Get a query's SQL statement --->
<CFFUNCTION NAME="QueryGetSQL" RETURNTYPE="string">

        <!--- Query name is required --->
        <CFARGUMENT NAME="queryname" TYPE="string" REQUIRED="yes">

        <!--- Initialize result string --->
        <CFSET result="">

        <!--- Requires debug mode --->
        <CFIF IsDebugMode()>

                <!--- Use debugging service --->
                <CFOBJECT ACTION="CREATE"
                          TYPE="JAVA"
                            CLASS="coldfusion.server.ServiceFactory"
                            NAME="factory">
                <CFSET cfdebugger=factory.getDebuggingService()>

                <!--- Load the debugging service's event table --->
                <CFSET events = cfdebugger.getDebugger().getData()>

                <!--- Get SQL statement (body) for specified query --->
                <CFQUERY DBTYPE="query" NAME="getquery" DEBUG="false">
                SELECT body
                FROM events
                WHERE type='SqlQuery' AND name='#queryname#'
                </CFQUERY>

                <!--- Save result --->
                <CFSET result=getquery.body>

        </CFIF>

        <!--- Return string --->
        <CFRETURN result>

</CFFUNCTION>

--
jon
mailto:jonhall at ozline.net

Monday, August 26, 2002, 4:44:39 PM, you wrote:

RC> As far as I know - no.

RC> Well - this is kind of a hack - in CFMX you can specify your own
RC> debugging templates. Looking at our code, instead of outputting the
RC> values, you could log them.

RC> =======================================================================
RC> Raymond Camden, ColdFusion Jedi Master for Hire

RC> Email    : jedimaster at macromedia.com
RC> Yahoo IM : cfjedimaster

RC> "My ally is the Force, and a powerful ally it is." - Yoda

>> -----Original Message-----
>> From: thelist-admin at lists.evolt.org
>> [mailto:thelist-admin at lists.evolt.org] On Behalf Of Rex
>> Vincent J. Aglibot
>> Sent: Monday, August 26, 2002 3:26 PM
>> To: thelist at lists.evolt.org
>> Subject: [thelist] ColdFusion: logging cfqueries
>>
>>
>> Is there a way to log the datasource name and SQL statement
>> for each query
>> executed?
>>
>> I know that you can set the debugging options to display the
>> record count,
>> processing time and theSQL statement for each query executed,
>> but I don't
>> want to display it, I want to log it somewhere instead.




More information about the thelist mailing list