QueryNew

Return new query based on the provided column list, column types, and/or row data.

Available column types are:

  • bigint

  • binary

  • bit

  • date

  • decimal

  • double

  • integer

  • null

  • object

  • other

  • time

  • timestamp

  • varchar

If columnTypeList is empty, all columns will be of type "object".

Method Signature

QueryNew(columnList=[any], columnTypeList=[string], rowData=[any])

Arguments

Argument
Type
Required
Description
Default

columnList

any

true

The column list to be used in the query, Ex: "name, age, dob". It can also be an array of structs that will be used as the row data.

columnTypeList

string

false

Comma-delimited list specifying column data types. If empty, all columns will be of type "object". Ex: "varchar, integer, date"

rowData

any

false

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). Ex: [{name: "John", age: 30}, {name: "Jane", age: 25}]

Examples

Builds a simple query using queryNew

Using Script with the queryAddRow querySetCell functions to populate the query.

Run Example

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 BL Tags with the queryAddRow querySetCell functions to populate the query.

<bx:set news = queryNew( "id,title", "integer,varchar" ) >
<bx:set queryAddRow( news ) >
<bx:set querySetCell( news, "id", "1" ) >
<bx:set querySetCell( news, "title", "Dewey defeats Truman" ) >
<bx:set queryAddRow( news ) >
<bx:set querySetCell( news, "id", "2" ) >
<bx:set querySetCell( news, "title", "Men walk on Moon" ) >
<bx:set writeDump( news ) >

Creating and Populating a query using an array rowData in queryNew

CF10+ Passes an array of structs to create a new query.

Run Example

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

CF10+ If you only need one row you can pass a single struct instead of an array into the rowData argument.

Run Example

news = queryNew( "id,title", "integer,varchar", { 
	"id" : 1,
	"title" : "Dewey defeats Truman"
} );
writeDump( news );

Creating and populating a query with an array of structs

CF2018u5+ Directly assigns columns and values with an array of structs.

Run Example

news = queryNew( [ 
	{
		"id" : 1,
		"title" : "Dewey defeats Truman"
	},
	{
		"id" : 2,
		"title" : "Man walks on Moon"
	}
] );
writeDump( news );

Additional Examples

Run Example

testQuery = queryNew( "name , age", "varchar , numeric", { 
	NAME : [
		"Susi",
		"Urs"
	],
	AGE : [
		20,
		24
	]
} );
dump( testQuery );
qry = queryNew( "name , age", "varchar , numeric", [
	[
		"Susi",
		20
	],
	[
		"Urs",
		24
	]
] );
dump( qry );
qry = queryNew( "name , age", "varchar , numeric", [
	{
		NAME : "Susi",
		AGE : 20
	},
	{
		NAME : "Urs",
		AGE : 24
	}
] );
dump( qry );

Last updated

Was this helpful?