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;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson