queryNew

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

Argument Reference for the queryNew function

columnList

Required: Yes
A string or a variable that contains one. Delimited list
of column names, or an empty string.

columnTypeList

Required: No
CF 7+ Comma-delimited list specifying column data types. Values:
  • Integer
  • BigInt
  • Double
  • Decimal
  • VarChar
  • Binary
  • Bit
  • Time
  • Data

rowData

Required: No
CF 10+ Data to populate the query. Can be a struct (with keys matching column names), an array of structs, or an array of arrays (in same order as columnList)

Examples sample code invoking the queryNew function


Builds a simple query using queryNew

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);

Builds a simple query using queryNew

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)>

Creating and Populating a query using an array rowData in queryNew

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);

Creating and Populating a single row query using rowData in queryNew

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);

Fork me on GitHub