User Guide

cfquery 349
You can cache query results and execute stored procedures. For information about this and about
displaying
cfquery output, see ColdFusion MX Developer’s Guide.
Because the
timeout attribute only affects the maximum time for each suboperation of a query,
the cumulative time may exceed its value. To set a timeout for a page that might get a very large
result set, set the Administrator > Server Settings > Timeout Requests option to an appropriate
value or use the RequestTimeout attribute of the
cfsetting tag (for example, <cfsetting
requestTimeout="300">).
The Caching page of the ColdFusion MX Administrator specifies the maximum number of
cached queries. Setting this value to 0 disables query caching.
You cannot use ColdFusion reserved words as query names.
You cannot use SQL reserved words as variable or column names in a Query of Queries, unless
they are escaped. The escape character is the bracket []; for example:
SELECT [count] FROM MYTABLE.
For a list of reserved keywords in ColdFusion MX, see “Escaping reserved keywords” in
Chapter 22, “Using Query of Queries” in ColdFusion MX Developer’s Guide.
Example
<!--- This example shows the use of CreateTimeSpan with CFQUERY ------>
<!--- to cache a record set. Define startrow and maxrows to ---->
<!--- facilitate 'next N' style browsing. ---->
<cfparam name="MaxRows" default="10">
<cfparam name="StartRow" default="1">
<!--------------------------------------------------------------------
Query database for information if cached database information has
not been updated in the last six hours; otherwise, use cached data.
--------------------------------------------------------------------->
<cfquery
name="GetParks" datasource="cfdocexamples"
cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#">
SELECT PARKNAME, REGION, STATE
FROM Parks
ORDER BY ParkName, State
</cfquery>
<!--- Build HTML table to display query. ------------------------->
<table cellpadding="1" cellspacing="1">
<tr>
<td bgcolor="f0f0f0">
&nbsp;
</td>
<td bgcolor="f0f0f0">
<b><i>Park Name</i></b>
</td>
<td bgcolor="f0f0f0">
result_name.columnList
Comma-delimited list of the query columns.
result_name.ExecutionTime
Cumulative time required to process the query.
Variable name Description