<cfquery>

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

This tag must have a body.

This tag is also supported within <cfscript>

Attribute Description
connectstring
string, optional

This attribute has been deprecated and is non-functional.

nestinglevel
numeric, optional

the level for the current pagesource

dbtype
string, optional

support the following values: - query: for doing a query on a existing query object - hql: for doing a query on orm

providerdsn
string, optional

This attribute has been deprecated and is non-functional.

dbname
string, optional

This attribute has been deprecated and is non-functional.

password
string, optional

If specified, password overrides the password value specified in the data source setup.

maxrows
number, optional

Specifies the maximum number of rows to return in the record set.

name
string, optional

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.

timeout
any, optional

The maximum number of seconds 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.

debug
boolean, optional

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.

datasource
any, optional

The name of the data source from which this query should retrieve data.

timezone
timezone, optional

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.

ormoptions
struct, optional

Object parameter for the entity.

blockfactor
number, optional

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.

username
string, optional

If specified, username overrides the username value specified in the data source setup.

result
string, optional

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)
tags
any, optional

tags stored with the cache.

provider
string, optional

This attribute has been deprecated and is non-functional.

unique
boolean, optional

Specifies if the object parameter is unique, used only for dbtype=orm or hql

cachedafter
datetime, optional

This is the age of which the query data can be

returntype
string, optional

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: converts the query object into an array of structs
  • struct: converts the query object into a struct using the columnKey attribute as a primary key
columnkey
string, optional

When return type is set to "struct", the value of this column is used as key in the struct for every record.

params
object, optional
dbserver
string, optional

This attribute has been deprecated and is non-functional.

psq
boolean, optional

preserve single quote or not

cachename
string, optional

This attribute has been deprecated and is non-functional.

lazy
boolean, optional

If "lazy" is set to true (default "false") Lucee does not initially load all the data from the datasource.

When "true" the data is only loaded when requested, this means the data is dependant on the datasource connection. If the datasource connection has been lost for some reason and the data has not yet been requested, Lucee throws an error if you try to access the data.

The "lazy" attribute only works if the following attributes are not used: cachewithin, cacheafter and result.

cachedwithin
object, optional

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.

<cfquery
    [connectstring=string]
    [nestinglevel=numeric]
    [dbtype=string]
    [providerdsn=string]
    [dbname=string]
    [password=string]
    [maxrows=number]
    [name=string]
    [timeout=any]
    [debug=boolean]
    [datasource=any]
    [timezone=timezone]
    [ormoptions=struct]
    [blockfactor=number]
    [username=string]
    [result=string]
    [tags=any]
    [provider=string]
    [unique=boolean]
    [cachedafter=datetime]
    [returntype=string]
    [columnkey=string]
    [params=object]
    [dbserver=string]
    [psq=boolean]
    [cachename=string]
    [lazy=boolean]
    [cachedwithin=object]
><!--- body ---></cfquery>

Examples

There are currently no examples for this tag.

See also