CFLib.org – Common Function Library Project

QueryGetSQL(queryname)

Last updated October 15, 2002
Download UDF

author

Ben Forta                                         Ben Forta

Version: 1 | Requires: ColdFusion MX | 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

Jose Diaz-Salcedo Jose Diaz-Salcedo added
cfRssFeed
2 day(s) ago

Raymond Compton Raymond Compton added
structBlend
23 day(s) ago

Duncan Duncan added
IsZIPUK
23 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
29 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson