Creates a new query object. The query can be populated with data using functions queryAddRow, querySetCell, or by passing it in to the rowData argument.
queryNew(columnList [, columnTypeList [, rowData]])
→ returns query
Integer
BigInt
Double
Decimal
VarChar
Binary
Bit
Time
Date
Timestamp
Using Script with the queryAddRow querySetCell functions to populate the query.
news = queryNew("id,title", "integer,varchar");
queryAddRow(news);
querySetCell(news, "id", "1");
querySetCell(news, "title", "Dewey defeats Truman");
queryAddRow(news);
querySetCell(news, "id", "2");
querySetCell(news, "title", "Men walk on Moon");
writeDump(news);
Using CFML Tags with the queryAddRow querySetCell functions to populate the query.
<cfset news = queryNew("id,title", "integer,varchar")>
<cfset queryAddRow(news)>
<cfset querySetCell(news, "id", "1")>
<cfset querySetCell(news, "title", "Dewey defeats Truman")>
<cfset queryAddRow(news)>
<cfset querySetCell(news, "id", "2")>
<cfset querySetCell(news, "title", "Men walk on Moon")>
<cfset writeDump(news)>
CF 10+ Passes an array of structs to create a new query.
news = queryNew("id,title",
"integer,varchar",
[ {"id":1,"title":"Dewey defeats Truman"}, {"id":2,"title":"Man walks on Moon"} ]);
writeDump(news);
CF 10+ If you only need one row you can pass a single struct instead of an array into the rowData argument.
news = queryNew("id,title",
"integer,varchar",
{"id":1,"title":"Dewey defeats Truman"});
writeDump(news);
CF2018u5+ Directly assigns columns and values with an array of structs.
news = queryNew([
{"id":1,"title":"Dewey defeats Truman"},
{"id":2,"title":"Man walks on Moon"}
]);
writeDump(news);
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.