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 an array.

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 an array. 
 * @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);
}

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