CFLib.org – Common Function Library Project

queryRowToArray(query, row)

Last updated July 27, 2012

author

Paul Kukiel

Version: 1 | Requires: CF9 | Library: DataManipulationLib

Description:
Convert a row in a query to an array in the same order the columns appear in the query.

Return Values:
Returns an array

Example:

<cfscript>
    q = queryNew("");
    queryAddColumn(q, "id", [1,2,3,4]);
    queryAddColumn(q, "english", ["one","two","three","four"]);
    queryAddColumn(q, "maori", ["tahi","rua","toru","wha"]);

    writeDump(q);    
    writeDump(queryRowToArray(q, 1));
</cfscript>

Parameters:

Name Description Required
query Query to extract from from Yes
row Which row to extract Yes

Full UDF Source:

/**
 * queryRowToArray
 * version 0.1 by Paul Kukiel
 * version 1.0 by Adam Cameron - fixing bug wherein not all columns were returned, plus factoring out unsupported query method usage in favour of native CFML getMetadata() function call to get query columns
 * 
 * @param query      Query to extract from from (Required)
 * @param row      Which row to extract (Required)
 * @return Returns an array 
 * @author Paul Kukiel (kukielp@gmail.com) 
 * @version 1, July 27, 2012 
 */
function queryRowToArray(query, row){
    var i = 1;
    var queryCols = getMetadata(query);
    var arrayReturn = [];

    for(i = 1; i <= arrayLen(querycols); i++){
        arrayReturn[i] = query[querycols[i].name][arguments.row];
    }
    return arrayReturn;
}

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