QueryExecute()
Passes SQL statements to a data source.
This is the equivalent to <cfquery> as a function, it uses the same underlying code.
QueryExecute( sql=string, params=any, options=struct, name=string );
Returns: any
Argument | Description |
---|---|
sql
string,
required
|
SQL to execute |
params
any,
optional
|
An array or structure containing parameter values. When passing an array, use When passing a struct, use The array or structure can be a structure with keys that match the names of the <cfqueryparam> names:
Alias: param |
options
struct,
optional
|
A struct containing the query options All the <cfquery> tag attributes are supported, except the Alias: option, queryOptions |
name
string,
optional
|
name of the query produced, visible in dumps or debugging output. Alias: queryName |
Examples
SELECT
_test = queryNew(
"_id, _need, _forWorld",
"integer, varchar, varchar",
[[01,'plant', 'agri'],[02, 'save','water']]
);
queryResult = queryExecute(
sql = 'SELECT * FROM _test WHERE _need = :need',
params = {
need: {
value: "plant",
type: "varchar"
}
},
options = {
dbtype = 'query'
}
);
dump(queryResult);
INSERT
and returning the generated key in result
queryExecute(
sql = 'insert into user (name) values (:name)',
params = {
name: {
value: "lucee",
type: "varchar"
}
},
options = {
dbtype = 'query',
result: "insertResult"
}
);
dump( insertResult.generatedKey );
See also
- Cache
- Queries
- Query Listeners
- Query of Queries sometimes it rocks, sometimes it sucks
- Query Handling In Lucee
- Lucee Sql Types
- <cfquery>
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)