Function: Query To Array Of Structures
I needed a simple function to convert a query to an array of structures, www.cflib.org provided one but I found that a bit 'out of date', so I wrote a new one to implement in my standard function component.
<cffunction name="querytoarray" returntype="array" output="No">
<cfargument name="q" required="Yes" type="query">
<cfset var aTmp = arraynew(1)>
<cfif q.recordcount>
<cfloop query="q">
<cfset stTmp = structNew()>
<cfloop list="#lcase(q.columnlist)#" index="col">
<cfset stTmp[col] = q[col][currentRow]>
</cfloop>
<cfset arrayAppend(aTmp,stTmp)>
</cfloop>
<cfelse>
<cfset stTmp = structNew()>
<cfloop list="#lcase(q.columnlist)#" index="col">
<cfset stTmp[col] = "">
</cfloop>
<cfset arrayAppend(aTmp,stTmp)>
</cfif>
<cfreturn aTmp>
</cffunction>
<cfset aRecordset= querytoarray(qRecordset)>
<cfdump var="#aRecordset#">
The reason I need this conversion is because I want to be able to change the 'default' values of a specific query cell... and because you can't change a recordset... wait a minute.. I just tested this on my MX7.01 server and you CAN overwrite a query recordset like this.
<cfset qRecordset.column[1] = "different value">
<cfdump var="qRecordset">
Hmmmm interesting.. do any of you know if this also works on MX6.x??
21485 viewed | 7 opinion(s) | del.icio.us | Digg it | Tjarko @ 12/08/05 12:01 cet



