CFLib.org – Common Function Library Project

queryToStructOfStructsAutoRow(theQuery)

Last updated September 23, 2004

author

Peter J. Farrell

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Description:
Converts a query to a structure of structures with the primary index of the main structure auto incremented. Thanks to Shawn Seley's QueryToStructOfStructures for the basis of my code.

Return Values:
Returns a struct.

Example:

<cfquery name="test" datasource="test">
select * from test
</cfquery>

<cfset s = queryToStructOfStructsAutoRow(test)>

Parameters:

Name Description Required
theQuery The query to transform. Yes

Full UDF Source:

/**
 * Converts a query to a structure of structures with the primary index of the main structure auto incremented.
 * 
 * @param theQuery 	 The query to transform. (Required)
 * @return Returns a struct. 
 * @author Peter J. Farrell (pjf@maestropublishing.com) 
 * @version 1, September 23, 2004 
 */
function queryToStructOfStructsAutoRow(theQuery){
	var theStructure = StructNew();
	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];
		} 
		theStructure[row] = Duplicate(thisRow);
	} 
	return theStructure;
}
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