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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson