QueryRun()

Executes the given SQL query against the given datasource, optionally passing in paramters. Function version of CFQUERY

Usage

QUERY = QueryRun( datasource, sql, params, cachedwithin, id, region )
Argument Summary
datasource name of the datasource, if omitted, then it will be pulled from the Application.cfc ('this.datasource'). If omitted, then pleased used named parameters for this function call
sql SQL string [optional]
params array of structures {value, padding, scale, maxlength, separator, list, defaultlist, nullvalue, cfsqltype} representing the attributes of CFQUERYPARAM; one for each ? within the SQL string [optional]
cachedwithin time span to which this query result will be cached for before it is reexecuted. Use CreateTimeSpan() to get a unit of a day to manage [optional]
id name of the cache you have given this query. If omitted, then the id will be calculated from the SQL statement plus any arguments passed in [optional]
region cache region to use (defaults to 'cfquery') [optional]

Calling

Supports named-parameter calling allowing you to use the function like:

QueryRun(
   datasource=?, 
   sql=?, 
   params=?, 
   cachedwithin=?, 
   id=?, 
   region=?
);

Supports passing parameters as a structure using ArgumentCollection:

QueryRun( ArgumentCollection={
   datasource : ?, 
   sql : ?, 
   params : ?, 
   cachedwithin : ?, 
   id : ?, 
   region : ?
} );

Extra

Using queries with a function is very easy, simply passing in the query to the QueryRun() function.

<cfset a = QueryRun("ds",
                    "select X from tableA where T_ID = 1"
                    )>

If you need to pass in a dynamic variable, then this function has the same ability as CFQUERYPARAM has, by passing in an array of structures with all the attributes that you would pass into CFQUERYPARAM. You specify the position of this using the ? inside the query block.

<cfset a = QueryRun("ds",
                    "select X from tableA where T_ID in (?)", 
                    [
                      {
                        value:"1,2,3,4", 
                        list:true, 
                        defaultlist:"0"
                      }
                    ]
                    )>