getQueryMetadata(Query)
Last updated May 30, 2010
Version: 0 | Requires: CF6 | Library: DataManipulationLib
Description:
CF7 introduced the ability to run getMetadata() on a query, which returns an array of structures containing datatype information. This UDF replicates this functionality for CFMX6.1
If run on CFMX7+, it uses CF's built-in function.
Return Values:
Returns an array
Example:
<cfquery datasource="mydsn" name="myquery">
select * from mytable
</cfquery>
<cfdump var="#getQueryMetadata(myquery)#">
Parameters:
Name | Description | Required |
---|---|---|
Query | ColdFusion query object to return metadata for | Yes |
Full UDF Source:
<!---
Replicates the CF7 getMetadata(query) functionality for MX6.1+
@param Query ColdFusion query object to return metadata for (Required)
@return Returns an array
@author Marc Esher (marc.esher@gmail.com)
@version 0, May 30, 2010
--->
<cffunction name="getQueryMetadata" access="public" returntype="array" hint="Replicates the CF7 getMetadata(query) functionality for MX6.1+">
<cfargument name="query" type="query" required="true"/>
<cfset var metadata = ArrayNew(1)>
<cfset var columns = ArrayNew(1)>
<cfset var col = 1>
<cfset var map = StructNew()>
<cfif listFirst(server.ColdFusion.ProductVersion) GT 6>
<cfreturn getMetadata(arguments.query)>
</cfif>
<cfset columns = arguments.query.getMetaData().getColumnLabels() />
<cfloop from="1" to="#ArrayLen(columns)#" index="col">
<cfset map = StructNew()>
<cfset map.name = columns[col]>
<cfset map.IsCaseSensitive = arguments.query.getMetaData().isCaseSensitive( javacast("int",col))>
<cfset map.TypeName = arguments.query.getMetadata().getColumnTypeName(javacast("int",col))>
<cfset ArrayAppend(metadata,map)>
</cfloop>
<cfreturn metadata>
</cffunction>
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