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

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