CFLib.org – Common Function Library Project

queryColumnTypes(dbquery)

Last updated April 11, 2006

author

John Bartlett

Version: 1 | Requires: CF6 | Library: DataManipulationLib

Description:
Used in conjuction with QueryColumns(), will return a list of data types such as the following: INTEGER,VARCHAR,CHAR,TIMESTAMP. This can be done in CFMX using getMetaData on the query.

Return Values:
Returns a list.

Example:

<cfquery name="foo" datasource="galaga">
select *
from users
</cfquery>

<cfdump var="#queryColumnTypes(foo)#">

Parameters:

Name Description Required
dbquery Query to analyze. Yes

Full UDF Source:

/**
 * Returns a list of query column data types.
 * 
 * @param dbquery 	 Query to analyze. (Required)
 * @return Returns a list. 
 * @author John Bartlett (jbartlett@strangejourney.net) 
 * @version 1, April 11, 2006 
 */
function queryColumnTypes(dbquery) {
	var columnTypes="";
	var metadata=dbquery.getMetadata();
	var i=0;
	var column="";

	for (i=1; i lte metadata.getColumnCount(); i=i+1) {
		column = metadata.getColumnLabel(javaCast("int",i));
		columnTypes = listAppend(columnTypes,dbquery.getColumnTypeName(metadata.getColumnType(dbquery.findColumn(column))));
	}

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