Created
October 8, 2013 11:23
-
-
Save Macagare/6883249 to your computer and use it in GitHub Desktop.
cfscript implementation convert query to structs array. created in railo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts a coldfusion query into a coldfusion struct | |
* | |
* @param required query source query to convert | |
* @return struct converted query as a array with structs | |
*/ | |
array function toStruct( required query source) output="true" { | |
var arrResult = arraynew(1); | |
var cols = ListtoArray(arguments.source.columnlist); | |
var row = 1; | |
var thisRow = ""; | |
var col = 1; | |
for(row = 1; row LTE arguments.source.recordcount; row = row + 1){ | |
thisRow = structnew(); | |
for(col = 1; col LTE arraylen(cols); col = col + 1){ | |
thisRow[cols[col]] = arguments.source[cols[col]][row]; | |
} | |
arrayAppend( arrResult, duplicate( thisRow ) ); | |
} | |
return(arrResult); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment