Railo 4.2 Reference
Choose a tag:

Tag <CFQUERY>

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

Body

This tag must have a body.

Example

	<cfquery
[blockfactor="number"]
[cachedafter="datetime"]
[cachedwithin="object"]
[cachename="string"]
[connectstring="string"]
[datasource="any"]
[dbname="string"]
[dbserver="string"]
[dbtype="string"]
[debug="boolean"]
[lazy="boolean"]
[maxrows="number"]
[name="string"]
[ormoptions="struct"]
[params="object"]
[password="string"]
[provider="string"]
[providerdsn="string"]
[psq="boolean"]
[result="string"]
[returntype="string"]
[timeout="number"]
[timezone="string"]
[unique="boolean"]
[username="string"]>
</cfquery>
This tag is also supported within cfscript
	<cfscript>
query
[blockfactor="number"]
[cachedafter="datetime"]
[cachedwithin="object"]
[cachename="string"]
[connectstring="string"]
[datasource="any"]
[dbname="string"]
[dbserver="string"]
[dbtype="string"]
[debug="boolean"]
[lazy="boolean"]
[maxrows="number"]
[name="string"]
[ormoptions="struct"]
[params="object"]
[password="string"]
[provider="string"]
[providerdsn="string"]
[psq="boolean"]
[result="string"]
[returntype="string"]
[timeout="number"]
[timezone="string"]
[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 This is the age of which the query data can be 
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. 
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 a 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. 
lazy boolean No if "lazy" is set to true (default "false") Railo 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, railo throws a 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" 
timeout number No The maximum number of milliseconds for the query to execute before returning an error
indicating that the query has timed-out. This attribute is not supported by most ODBC drivers.
timeout is supported by the SQL Server 6.x or above driver. The minimum and maximum allowable values
vary, depending on the driver. 
timezone string 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.