Skip to content

Instantly share code, notes, and snippets.

@mrandrewmills
Created October 8, 2016 17:27
Show Gist options
  • Save mrandrewmills/04c90f6105913c6658b76be0f5d8548c to your computer and use it in GitHub Desktop.
Save mrandrewmills/04c90f6105913c6658b76be0f5d8548c to your computer and use it in GitHub Desktop.
Converts an array of structures returned by getCEData method within CommonSpot's ADF into a ColdFusion query
<cffunction name="CEDataArrayToQuery" returntype="query" description="convert array of structs from getCEData into a CF query">
<cfargument name="CEDataArray" type="array" required="yes">
<cftry>
<!--- begin by getting struct keys from Values first --->
<cfset valueKeys = StructKeyList(arguments.CEDataArray[1].Values)>
<!--- then create our query, using those keys --->
<cfset qData = QueryNew(valueKeys)>
<!--- iterate through array to add/populate query with data --->
<cfloop array="#CEDataArray#" index="curRecord">
<!--- adding a new row to our query --->
<cfset temp = QueryAddRow(qData)>
<!--- then iterate through list of columns to add each field of data --->
<cfloop list="#valueKeys#" index="curColumn">
<cfset temp = QuerySetCell(qData, curColumn, curRecord.Values[curColumn])>
</cfloop>
</cfloop>
<cfreturn qData>
<cfcatch type="any">
<!--- handle and/or log any errors that may occur --->
</cfcatch>
</cftry>
</cffunction>
@mrandrewmills
Copy link
Author

To eliminate any potential confusion, this function will convert only an array of structures (the data stored within the VALUES key, to be precise) returned from the getCEData method. It will not convert a regular array of structures.

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