CFLib.org – Common Function Library Project

QueryGetSQL(queryname)

Last updated October 15, 2002

Version: 1 | Requires: ColdFusion MX | Library: DatabaseLib

 
Rated 1 time(s). Average Rating: 3.0

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:

view plain print about
<!---
<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:

view plain print about
<!---
 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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
10 day(s) ago

Will Belden Will Belden added
longTime
15 day(s) ago

James Sleeman James Sleeman added
quickSort
25 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
28 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson