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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson