cfmlrailo

Using StructKeyExists on a cfquery result


I have a list of column names and loop over them to see if a name exists as a key in struct using 'StructKeyExists' - works as expected.

But when I try the same on a single row cfquery result it also works - I expected it to crash.

Why does it work on a cfquery results?

I'd expect to have issues if the cfquery result had more than 1 row, but in this case biz rules don't allow it.


Solution

  • It is checking the structure key not the individual rows in the query. So if you query has a column named "id" or "columnName" and you use structkeyexists to check for the key, e.g. "id" or "columnName" you are asking CFML if that query has a column named that. How many rows the query has returned is in no way related.