– Common Function Library Project

queryGetRow(query [, row])

Last updated June 21, 2014

Version: 1 | Requires: ColdFusion 9 | Library: CFMLLib

Rated 0 time(s). Average Rating: 0

Simulate QueryGetRow @ for CF8+

Return Values:
Returns a struct containing the data from the selected row


view plain print about
// TestQueryGetRow.cfc
component extends="testbox.system.BaseSpec" {

    function run(){
        include "udfs/queryGetRow.cfm"; // renamed to _queryGetRow() for tests, as I'm running CF11

        describe("Tests for convertBBCodeToHtml()", function(){
            it("handles an empty query", function(){
                    queryGetRow(queryNew(""), 0)
            it("handles zeroth row from a one-row query", function(){
                var q = queryNew("col", "varchar", [["data"]]);
                    queryGetRow(q, 0)
            it("handles first row from a one-row query", function(){
                var q = queryNew("col", "varchar", [["data"]]);
                    queryGetRow(q, 1)
            it("handles row with multiple columns", function(){
                var q = queryNew("col1,col2", "varchar,varchar", [["data1","data2"]]);
                    queryGetRow(q, 1)



Name Description Required
query The query from which to extract the row data Yes
row The row to extract. Defaults to currentRow No

Full UDF Source:

view plain print about
 * This function returns a struct having all the lowercased columns as keys and their corresponding values
 * v0.9 by Henry Ho
 * v1.0 by Adam Cameron (re-write in script)
 * @param query      The query from which to extract the row data (Required)
 * @param row      The row to extract. Defaults to currentRow (Optional)
 * @return Returns a struct containing the data from the selected row 
 * @author Henry Ho ( 
 * @version 1, June 21, 2014 

public struct function queryGetRow(required query query, numeric row){
    if (!structKeyExists(arguments, "row")){
        row = query.currentRow;
    var struct = {};
    for (var col in listToArray(query.columnList)){
        struct[lcase(col)] = query[col][row];

    return struct;
blog comments powered by Disqus


Latest Additions

CF Ninja CF Ninja added
15 day(s) ago

Stephen Withington Stephen Withington added
15 day(s) ago

Adam Cameron Adam Cameron added
a while ago

Ray Ford Ray Ford added
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 48 time(s)

Barney Boisvert indentXml
Rated 5.0, 12 time(s)

Rachel Lehman deAccent
Rated 5.0, 9 time(s)

Darwan Leonardo Sitepu splitNumber
Rated 5.0, 8 time(s)

Created by Raymond Camden / Design by Justin Johnson