cfscript loop through query - querySetCell v direct assignment
I was rather surprised to find out that in cfscript, using querySetCell inside a query loop does not set the column value immediately available for use.
The column value is only present AFTER the loop is complete.
for (row in query) {
value = row["LAST"] & ", " & row["FIRST"]; //value="Doe, John"
querySetCell(query,"NAME",value,query.currentRow);
//value of row.NAME is not set
if (value == row["NAME"]) {
writeoutput("Match"); //never
} else {
writeoutput("No Match"); //always
}
}
writedump(query); //value of row.NAME is set
However, if you use direct assignment, the column value is immediately available for use.
for (row in query) {
value = row["LAST"] & ", " & row["FIRST"]; //value="Doe, John"
row["NAME"] = value;
//value of row.NAME is set
if (value == row["NAME"]) {
writeoutput("Match"); //always
} else {
writeoutput("No Match"); //never
}
}
writedump(query); //value of row.NAME is set
I find this rather disturbing. Is it a bug? Depends on how you look at it, I suppose.
Certainly, the documentation should clarify the difference.
