<!--- Init variables --->
<CFPARAM NAME="FORM.datasource" DEFAULT="#datasource_default#">
<CFPARAM NAME="FORM.sql" DEFAULT="">
<CFSET whitespace=" #Chr(10)##Chr(13)#">

<!--- If no SQL, quit --->
<CFIF Trim(FORM.sql) IS "">
	<CFABORT>
</CFIF>

<BODY>

<!--- Check if only SELECT allowed --->
<CFIF select_only>
	<!--- Check first word is SELECT --->
	<CFIF UCase(ListFirst(Trim(FORM.sql), whitespace)) NEQ "SELECT">
		<!--- Abort --->
		<H1>Only SELECT statements are allowed</H1>
		<CFABORT>
	</CFIF>
</CFIF>

<!--- Try/catch block --->
<CFTRY>
	<!--- Execute SQL --->
	<CFQUERY NAME="results" DATASOURCE="#FORM.datasource#" DEBUG="No">
	#PreserveSingleQuotes(FORM.sql)#
	</CFQUERY>
	<!--- Number of results --->
	<CFIF IsDefined("results.RecordCount")>
		<CFOUTPUT><STRONG>#results.RecordCount# #IIf(results.RecordCount IS 1, DE("Row"), DE("Rows"))# Returned</STRONG></CFOUTPUT>
	</CFIF>
	<!--- Dump results --->
	<CFIF IsDefined("results")>
		<CFDUMP VAR="#results#">
	<CFELSE>
		<H1>No results returned</H1>
	</CFIF>
	<!--- Catch errors --->
	<CFCATCH>
		<!--- Something went wrong --->
		<CFOUTPUT><H1>#CFCATCH.Message#</H1><H3>#CFCATCH.Detail#</H3></CFOUTPUT>
		<!--- Provide extra hints, if possible --->
		<CFIF FindNoCase("Too few parameters", CFCATCH.Detail)>
			Hint: This usually means you've mistyped a column name or have missed a comma.
		<CFELSEIF FindNoCase("missing operator", CFCATCH.Detail)>
			Hint: Make sure that you have not missed a comma or mistyped a keyword.
		</CFIF>
	</CFCATCH>
</CFTRY>

</BODY>
