CFLib.org – Common Function Library Project

QueryGetSQL(queryname)

Last updated October 15, 2002

author

Ben Forta

Version: 1 | Requires: CF6 | Library: DatabaseLib

Description:
Returns the SQL statement used to generate the specified query. Uses the coldfusion.server.ServiceFactory object used by the ColdFusion debugging service.

Return Values:
Returns a string.

Example:

<!---
<CFQUERY NAME="GetUDFCount" DATASOURCE="#Request.App.DSN#">
  SELECT Count(*) as UDFCount
  FROM tblUDFs
</CFQUERY>

<P>
<CFOUTPUT>
#QueryGetSQL("GetUDFCount")#
</CFOUTPUT>
Example disabled since debugging is not turned on this server.
--->

Parameters:

Name Description Required
queryname Name of the query you wish to return the SQL statement for. Yes

Full UDF Source:

<!---
 Returns the SQL statement used to generate the specified query.
 
 @param queryname      Name of the query you wish to return the SQL statement for. (Required)
 @return Returns a string. 
 @author Ben Forta (ben@forta.com) 
 @version 1, October 15, 2002 
--->
<CFFUNCTION NAME="QueryGetSQL" RETURNTYPE="string">

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

        <!--- Initialize variables --->
        <CFSET var cfdebugger="">
        <CFSET var events ="">
        
    <!--- Initialize result string --->
    <CFSET var 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>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson