User Guide

348 Chapter 2: ColdFusion Tags
Usage
Use this tag to execute a SQL statement against a ColdFusion data source. Although you can use
the
cfquery tag to execute any SQL Data Definition Language (DDL) or Data Manipulation
Language (DML) statement, you typically use it to execute a SQL SELECT statement.
Note: To call a stored procedure, use the cfstoredproc tag.
This tag creates a query object, providing this information in query variables:
The
cfquery tag also returns the following result variables in a structure. You can access these
variables with a prefix of the name you specified in the
result attribute. For example, if you
assign the name
myResult to the result attribute, you would retrieve the name of the SQL
statement that was executed by accessing
#myResult.sql#. The result attribute provides a way
for functions or CFCs that are called from multiple pages, possibly at the same time, to avoid
overwriting results of one call with another.
cachedWithin Optional Timespan, using the CreateTimeSpan function. If original
query date falls within the time span, cached query data is
used.
CreateTimeSpan defines a period from the present,
back. Takes effect only if query caching is enabled in the
Administrator.
To use cached data, the current query must use the same
SQL statement, data source, query name, user name, and
password.
debug Optional;
value and
equals sign
may be
omitted
Yes, or if omitted: if debugging is enabled, but the
Administrator Database Activity option is not enabled,
displays SQL submitted to datasource and number of
records returned by query.
No: if the Administrator Database Activity option is
enabled, suppresses display.
result Optional Specifies a name for the structure in which
cfquery returns
the result variables. For more information, see the Usage
section .
Variable name Description
query_name.currentRow
Current row of query that cfoutput is processing.
query_name.columnList
Comma-delimited list of the query columns.
query_name.RecordCount
Number of records (rows) returned from the query.
Variable name Description
result_name.sql
The SQL statement that was executed.
result_name.recordcount
Current row of query that cfoutput is processing.
result_name.cached
True
if the query was cached; False otherwise.
result_name.sqlparameters
An ordered Array of cfqueryparam values.
Attribute Req/Opt Default Description