QueryAddRow
Return new query
Method Signature
QueryAddRow(query=[query], rowData=[any])
Arguments
Argument
Type
Required
Description
Default
query
query
true
The query to add the row(s) to.
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)
Examples
Builds a simple query using queryNew and queryAddRow
CF10+ Pass in row data directly to queryAddRow argument.
news = queryNew( "id,title", "integer,varchar" );
queryAddRow( news, {
"id" : 1,
"title" : "Dewey defeats Truman"
} );
writeDump( news );
Builds a simple query using queryNew and queryAddRow member syntax
CF10+ Pass in row data directly to queryAddRow argument.
news = queryNew( "id,title", "integer,varchar" );
news.addRow( {
"id" : 1,
"title" : "Dewey defeats Truman"
} );
writeDump( news );
Builds a simple query using queryNew queryAddRow and querySetCell
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 queryAddRow and querySetCell with rows number
The example above could be simplified this way:
news = queryNew( "id,title", "integer,varchar" );
queryAddRow( news, 2 );
querySetCell( news, "id", "1", 1 );
querySetCell( news, "title", "Dewey defeats Truman", 1 );
querySetCell( news, "id", "2", 2 );
querySetCell( news, "title", "Men walk on Moon", 2 );
writeDump( news );
Builds a simple query using queryNew queryAddRow with multiple rows as an array
CF10+ The example above could be simplified even more this way:
news = queryNew( "id,title", "integer,varchar" );
queryAddRow( news, [
{
"id" : 1,
"title" : "Dewey defeats Truman"
},
{
"id" : 2,
"title" : "Men walk on Moon"
}
] );
writeDump( news );
Additional Examples
myQuery = queryNew( "id,name" );
addedRows = queryAddRow( myQuery, 3 ); // will return 3
queryAddRow( myQuery, [
17,
"added via array notation"
] );
anotherRow = queryAddRow( myQuery ); // will return 4
queryAddRow( myQuery, {
ID : 18,
NAME : "added via struct notation"
} );
dump( myQuery );
Related
Last updated
Was this helpful?