Adobe COLDFUSION 9 Manual page 447

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Accessing and Using Data
Using the CAST function
In some cases, the data type of a column is not compatible with the processing you want to do. For example, query
columns returned by the
cfhttp
use the Query of Queries CAST function to convert a column value into an expression of the correct data type.
The syntax for the CAST function is as follows:
CAST ( expression AS castType )
Where castType is one of the following:
• BINARY
• BIGINIT
• BIT
• DATE
• DECIMAL
• DOUBLE
• INTEGER
• TIME
• TIMESTAMP
• VARCHAR
For example:
<cfhttp
url="http://quote.yahoo.com/download/quotes.csv?Symbols=csco,jnpr&format=sc1l1&ext=.csv"
method="GET"
name="qStockItems"
columns="Symbol,Change,LastTradedPrice"
textqualifier=""""
delimiter=","
firstrowasheaders="no">
<cfoutput>
<cfdump var="#qStockItems#">
<cfdump var="#qStockItems.getColumnNames()#">
</cfoutput>
<cfoutput>
<cfloop index="i" from="1" to="#arrayLen(qStockItems.getColumnNames())#">
#qStockItems.getMetaData().getColumnTypeName(javaCast("int",i))#<br/>
</cfloop>
</cfoutput>
<cftry>
<cfquery name="hello" dbtype="query">
SELECT SUM(CAST(qStockItems.LastTradedPrice as INTEGER))
AS SUMNOW from qStockItems
</cfquery>
<cfcatch>Error in Query of Queries</cfcatch>
</cftry>
<cfoutput>
<cfdump var="#hello#">
</cfoutput>
tag are all of type CF_SQL_VARCHAR, even if the contents are numeric. In this case,
Last updated 8/5/2010
442

Advertisement

Table of Contents
loading

Table of Contents