QueryRowToStruct(query[, row])
Last updated December 11, 2001
Version: 1 | Requires: CF5 | Library: DataManipulationLib
Description:
Convenience function for turning a given row of query into a structure. By default, it uses the first row.
Return Values:
Returns a structure.
Example:
<cfscript>
q = querynew("id,name");
queryAddRow(q);
querySetCell(q,"id",1);
querySetCell(q,"name","Nathan Dintenfass");
queryAddRow(q);
querySetCell(q,"id",2);
querySetCell(q,"name","Ben Archibald");
queryAddRow(q);
querySetCell(q,"id",3);
querySetCell(q,"name","Raymond Camden");
</cfscript>
<cfdump var="#queryRowToStruct(q)#">
<cfdump var="#queryRowToStruct(q,2)#">
Parameters:
Name | Description | Required |
---|---|---|
query | The query to work with. | Yes |
row | Row number to check. Defaults to row 1. | No |
Full UDF Source:
/**
* Makes a row of a query into a structure.
*
* @param query The query to work with.
* @param row Row number to check. Defaults to row 1.
* @return Returns a structure.
* @author Nathan Dintenfass (nathan@changemedia.com)
* @version 1, December 11, 2001
*/
function queryRowToStruct(query){
//by default, do this to the first row of the query
var row = 1;
//a var for looping
var ii = 1;
//the cols to loop over
var cols = listToArray(query.columnList);
//the struct to return
var stReturn = structnew();
//if there is a second argument, use that for the row number
if(arrayLen(arguments) GT 1)
row = arguments[2];
//loop over the cols and build the struct from the query row
for(ii = 1; ii lte arraylen(cols); ii = ii + 1){
stReturn[cols[ii]] = query[cols[ii]][row];
}
//return the struct
return stReturn;
}
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