queryAddRow

Adds a specified number of empty rows to a query.

queryAddRow(query [, number/row(s)]) → returns Numeric

queryAddRow Argument Reference

query Query
Required

number/row(s) Numeric / Array / Struct

As of CF 10+ you can pass a Structure whose keys map to the query column names to insert a row of data; or an Array of those Structures to insert multiple rows at once.

Examples sample code invoking the queryAddRow function


Builds a simple query using queryNew and queryAddRow

CF 10+ 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 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

The example above could be simplified even more this way:

<cfscript>
news = queryNew("id,title", "integer,varchar");
queryAddRow(news, [{"id"=1,"title"="Dewey defeats Truman"},{"id"=2,"title"= "Men walk on Moon"}]);
writeDump(news);
</cfscript>

Fork me on GitHub