queryAddRow

Adds a specified number of empty rows to a query.

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

Member Function Syntax

someQuery.addRow([number/row(s)])

Argument Reference

query query
Required

number/row(s) numeric

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

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

CF 10+ Pass in row data directly to queryAddRow argument.

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

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

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

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

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub