Apr 02
Adding complex data types to coldfusion query rows
Posted by James Netherton | Monday 02 April 2007 8:20 PM | In ColdFusion
I discovered this today after reading a blog entry by Ben Nadel. There's a document on that post that has lots of useful information on how the ColdFusion query of queries feature works. This nugget was particularly interesting, it seems you can add complex data types, arrays, structs and CFC's into the rows of query result sets. Observe....
<cfset crazyQuery = queryNew("complexDataType")/>
<cfset queryAddRow(crazyQuery,3) />
<cfset testObj = createObject("component","test")/>
<cfset crazyQuery["complexDataType"][1] = structNew()/>
<cfset crazyQuery["complexDataType"][2] = listToArray( "I,can,add,an,array,too,:-)" ) />
<cfset crazyQuery["complexDataType"][3] = testObj/>
<cfdump var="#crazyQuery#">
<cfset queryAddRow(crazyQuery,3) />
<cfset testObj = createObject("component","test")/>
<cfset crazyQuery["complexDataType"][1] = structNew()/>
<cfset crazyQuery["complexDataType"][2] = listToArray( "I,can,add,an,array,too,:-)" ) />
<cfset crazyQuery["complexDataType"][3] = testObj/>
<cfdump var="#crazyQuery#">
This produces the output:

I'm not sure how I'd make use of this in a real world app but it's interesting nonetheless.
1 Comment
[Post comment]
1
Posted by kola | Tuesday 03 April 2007 4:50 AM
wow that is useful .... one good use I think is that it allows you the use the query abstraction against non queries - so queries become more like a collection) interesting...