QueryToArrayOfStructures(query)
Last updated September 27, 2001
Version: 1 | Requires: ColdFusion 5 | Library: DataManipulationLib
Description:
Converts a query object into an array of structures.
Return Values:
This function returns a structure.
Example:
<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:
<cfscript>
/**
* 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);
}
</cfscript>
Search CFLib.org
Latest Additions
Dave Anderson added
iniToStruct
20 day(s) ago
Dave Anderson added
deDupeArray
20 day(s) ago
Richard added
dice
22 day(s) ago
Isaac Dealey added
getRelative
a while ago
Top Rated
backupDatabase
Rated 5.0, 22 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)
highlightAndCrop
Rated 5.0, 4 time(s)