Skip to content

Instantly share code, notes, and snippets.

@nkostic
Created March 26, 2012 12:56
Show Gist options
  • Save nkostic/2204871 to your computer and use it in GitHub Desktop.
Save nkostic/2204871 to your computer and use it in GitHub Desktop.
Convert Array Of Structures To Query
<cffunction name="ArrayOfStructuresToQuery" access="public" returntype="query" output="false">
<cfargument name="StructArray" type="any" required="true" />
<cfscript>
KeyList=StructKeyList(arguments.StructArray[1]);
qbook = QueryNew(KeyList);
for(i=1; i <= ArrayLen(arguments.StructArray); i=i+1){
QueryAddRow(qbook);
for(y=1;y lte ListLen(KeyList);y=y+1){
QuerySetCell(qbook, ListGetAt(KeyList,y), arguments.StructArray[i][ListGetAt(KeyList,y)]);
}
}
return qbook;
</cfscript>
</cffunction>
@harryfear
Copy link

This seems not to work with ColdFusion 11? I migrated to CF11 and it broke the use of this UDF:

"Element is undefined in a CFML structure referenced as part of an expression."

Seems to be thrown when this is happening:

querySetCell(theQuery, colNames[j], theArray[i][colNames[j]], i);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment