CFLib.org – Common Function Library Project

QueryToArrayOfStructures(query)

Last updated September 27, 2001

author

Nathan Dintenfass

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Description:
Converts a query object into an array of structures.

Return Values:
This function returns a structure.

Example:

<CFSET Query = QueryNew("id,name,age")>
<CFLOOP INDEX="X" FROM=1 TO=3>
<CFSET QueryAddRow(Query,1)>
<CFSET QuerySetCell(Query,"ID",X,X)>
<CFSET QuerySetCell(Query,"Name","Name #X#",X)>
<CFSET QuerySetCell(Query,"Age",X+15,X)>
</CFLOOP>
<CFSET arrStruct = QueryToArrayOfStructures(Query)>
<CFDUMP VAR="#arrStruct#">

Parameters:

Name Description Required
query The query to be transformed Yes

Full UDF Source:

/**
 * Converts a query object into an array of structures.
 * 
 * @param query 	 The query to be transformed 
 * @return This function returns a structure. 
 * @author Nathan Dintenfass (nathan@changemedia.com) 
 * @version 1, September 27, 2001 
 */
function QueryToArrayOfStructures(theQuery){
	var theArray = arraynew(1);
	var cols = ListtoArray(theQuery.columnlist);
	var row = 1;
	var thisRow = "";
	var col = 1;
	for(row = 1; row LTE theQuery.recordcount; row = row + 1){
		thisRow = structnew();
		for(col = 1; col LTE arraylen(cols); col = col + 1){
			thisRow[cols[col]] = theQuery[cols[col]][row];
		}
		arrayAppend(theArray,duplicate(thisRow));
	}
	return(theArray);
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson