CFLib.org – Common Function Library Project

queryColumns(dbquery)

Last updated March 17, 2006

author

John Bartlett

Version: 1 | Requires: CF6 | Library: DataManipulationLib

Description:
Returns the columns in a query in the same order and case returned by the database. Note that you can get the same information in CFMX7 using the result attribute for cfquery.

Return Values:
Returns a list.

Example:

<cfquery name="foo" datasource="cflib">
select id, Description, name
from tbludfs
</cfquery>

<cfoutput>
#querycolumns(foo)#
</cfoutput>

Parameters:

Name Description Required
dbquery Query to examine. Yes

Full UDF Source:

/**
 * Returns query column list.
 * 
 * @param dbquery      Query to examine. (Required)
 * @return Returns a list. 
 * @author John Bartlett (jbartlett@strangejourney.net) 
 * @version 1, March 17, 2006 
 */
function queryColumns(dbquery) {
    var queryFields = "";
    var metadata = dbquery.getMetadata();
    var i = 0;
    var col = "";
    
    for (i = 1; i lte metadata.getColumnCount(); i = i+1) {
        col = metadata.getColumnLabel(javaCast("int", i));
        queryFields = listAppend(queryFields,col);
    }

    return queryFields;
}

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