Lucee Tag Reference

<cfquery>

Passes SQL statements to a data source. Not limited to queries.

Body

This tag may have a body.

Example

<cfquery
[blockfactor=number]
[cachedafter=datetime]
[cachedwithin=object]
[cacheid=string]
[cachename=string]
[connectstring=string]
[datasource=any]
[dbname=string]
[dbserver=string]
[dbtype=string]
[debug=boolean]
[indexname=string]
[lazy=boolean]
[maxrows=number]
[name=string]
[ormoptions=struct]
[params=object]
[password=string]
[provider=string]
[providerdsn=string]
[psq=boolean]
[result=string]
[returntype=string]
[sql=string]
[tags=any]
[timeout=any]
[timezone=timezone]
[unique=boolean]
[username=string]>
[</cfquery>]
This tag is also supported within cfscript
<cfscript>
query
[blockfactor=number]
[cachedafter=datetime]
[cachedwithin=object]
[cacheid=string]
[cachename=string]
[connectstring=string]
[datasource=any]
[dbname=string]
[dbserver=string]
[dbtype=string]
[debug=boolean]
[indexname=string]
[lazy=boolean]
[maxrows=number]
[name=string]
[ormoptions=struct]
[params=object]
[password=string]
[provider=string]
[providerdsn=string]
[psq=boolean]
[result=string]
[returntype=string]
[sql=string]
[tags=any]
[timeout=any]
[timezone=timezone]
[unique=boolean]
[username=string] {
[...]
}
</cfscript>

Attributes

The attributes for this tag are fixed. Except for the following attributes no other attributes are allowed.
Name Type Required Description
blockfactor number No Specifies the maximum number of rows to fetch at a time from the server. The range is 1,
default to 100. This parameter applies to ORACLE native database drivers and to ODBC drivers.
Certain ODBC drivers may dynamically reduce the block factor at runtime. 
cachedafter datetime No Sets a date/time from when the tag will start to cache the query. In difference to other CFML Engines this attribute only works in combination with the tag "cachedWithin", so you still have to set with "cachedWithin" how long the query remains in the cache. To match other CFML engines simply set "cachedWithin" to "36500", that will hold it in cache for 100 years! 
cachedwithin any No possible values are:
String "request": If original query was created within the current request, cached query data isused.
a timespan (created with function CreateTimeSpan): If original query date falls within the time span, cached query data isused.

To use cached data, the current query must use the same SQL statement, data source, query name, user name, and password. 
cacheid string No Attribute not supported 
cachename string No This Attribute is deprecated 
connectstring string No This Attribute is deprecated 
datasource any No The name of the data source from which this query should retrieve data. 
dbname string No This Attribute is deprecated 
dbserver string No This Attribute is deprecated 
dbtype string No support the following values:
- query: for doing a query on an existing query object
- hql: for doing a query on orm 
debug boolean No Used for debugging queries. Specifying this attribute causes the SQL statement submitted to the
data source and the number of records returned from the query to be returned. 
indexname string No  
lazy boolean No if "lazy" is set to true (default "false") Lucee does not initially load all the data from the datasource,
in that case the data are only loaded when requested, so this means the data are depending on the datasource connection.
if the datasource connection is gone and the data are not requested yet, lucee throws an error if you try to access the data.
lazy is only working when the following attributes are not used: cachewithin,cacheafter,result 
maxrows number No Specifies the maximum number of rows to return in the record set. 
name string No The name query. Must begin with a letter and may consist of letters, numbers, and the underscore
character, spaces are not allowed. The query name is used later in the page to reference the query's
record set. 
ormoptions struct No Object parameter for the entity. 
params any No  
password string No If specified, password overrides the password value specified in the data source setup. 
provider string No This Attribute is deprecated 
providerdsn string No This Attribute is deprecated 
psq boolean No preserve single quote or not 
result string No Specifies a name for the structure in which cfquery returns
the result variables.
- SQL: The SQL statement that was executed. (string)
- Cached: If the query was cached. (boolean)
- SqlParameters: An ordered Array of cfqueryparam values. (array)
- RecordCount: Total number of records in the query. (numeric)
- ColumnList: Column list, comma separated. (numeric)
- ExecutionTime: Execution time for the SQL request. (numeric) 
returntype string No one of the following values:
- query: default for all dbtype expect "hql", returns a query object
- array_of_entity: works only with dbtype "hql" and is also the default value for dbtype "hql"
- array: returns an array, where each element is a struct with a query record
- struct: returns either a struct of structs where the key is specified by the keyColumn attribute
and each value is a struct with a query record, or a single record if keyColumn is not set, where
each key is a column name and each value has its corresponding value. 
sql string No the SQL query to execute. 
tags any No tags stored with the cache. 
timeout any No The maximum number of seconds for the query to execute before returning an error
indicating that the query has timed-out. Value can be a number (seconds) or a Timespan Object. The minimum and maximum allowable values
vary, depending on the driver. 
timezone timezone No the timezone used to convert a date object to a timestamp (string), this value is needed when your database runs in another timezone and you are not using cfqueryparam to to insert dates. 
unique boolean No Specifies if the object parameter is unique, used only for dbtype=orm or hql 
username string No If specified, username overrides the username value specified in the data source setup.