CFLib.org – Common Function Library Project

getRowFromQuery(qry, row)

Last updated June 21, 2014

author

Tony Felice

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Description:
Given a numeric row id, this function will return the single row as a query object.

Return Values:
Returns a query.

Example:

<cfset myQuery = QueryNew("Name, Time, Advanced", "VarChar, Time, Bit")>
<cfset newRow = QueryAddRow(MyQuery, 2)>
<cfset QuerySetCell(myQuery, "Name", "The Wonderful World of CMFL", 1)>
<cfset QuerySetCell(myQuery, "Time", "9:15 AM", 1)>
<cfset QuerySetCell(myQuery, "Advanced", False, 1)>
<cfset QuerySetCell(myQuery, "Name", "CFCs for Enterprise Applications", 2)>
<cfset QuerySetCell(myQuery, "Time", "12:15 PM", 2)>
<cfset QuerySetCell(myQuery, "Advanced", True, 2)>

The second row of the query is: <cfdump var="#getRowFromQuery(myQuery,2)#">

Parameters:

Name Description Required
qry Query to inspect. Yes
row Numeric row to retrieve. Yes

Full UDF Source:

/**
 * Return a single row from a query.
 * v1.0 by Tony Felice
 * v1.1 by Adam Cameron (changing name so as to not conflict with current CFML)
 * 
 * @param qry 	 Query to inspect. (Required)
 * @param row 	 Numeric row to retrieve. (Required)
 * @return Returns a query. 
 * @author Tony Felice (tfelice@reddoor.biz) 
 * @version 1.10, June 21, 2014 
 */
function getRowFromQuery(qry,row){
	var result = queryNew('');
	var cols = listToArray(arguments.qry.columnList);
	var i = '';

	for(i=1; i lte arrayLen(cols); i=i+1){
		queryAddColumn(result, cols[i], listToArray(arguments.qry[cols[i]][arguments.row]));
	}

	return result;
}
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