Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 446

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Accessing and Using Data
Escaping wildcards
You can specify your own escape character by using the conditional ESCAPE clause.
Example
The following example uses the ESCAPE clause to enable a search for a literal percent sign (%), which ColdFusion
normally interprets as a wildcard character:
SELECT emp_discount
FROM Benefits
WHERE emp_discount LIKE '10\%'
ESCAPE '\';
Managing data types for columns
A Query of Queries requires that every column has metadata that defines the data type of the column. All queries that
ColdFusion creates have metadata. However, a query created with
does not contain metadata. You use this optional second parameter to define the data type of each column in the query.
Specify column data types in the QueryNew function
Type a
function, specifying the column names in the first parameter and the data types in the second
QueryNew
parameter, as the following example shows:
<cfset qInstruments = queryNew("name, instrument, years_playing", "CF_SQL_VARCHAR,
CF_SQL_VARCHAR, CF_SQL_INTEGER")>
Note: To see the metadata for a Query of Queries, use the GetMetaData function.
Specify the column data types in the QueryAddColumn function
1
Create a query by specifying the QueryNew function with no parameters.
<!--- Make a query. --->
<cfset myQuery = QueryNew("")>
2
Add and populate a column with the QueryAddColumn function, specifying the data type in the third parameter:
<!--- Create an array. --->
<cfset FastFoodArray = ArrayNew(1)>
<cfset FastFoodArray[1] = "French Fries">
<cfset FastFoodArray[2] = "Hot Dogs">
<cfset FastFoodArray[3] = "Fried Clams">
<cfset FastFoodArray[4] = "Thick Shakes">
<!--- Use the array to add a column to the query. --->
<cfset nColumnNumber = QueryAddColumn(myQuery, "FastFood", "CF_SQL_VARCHAR",
FastFoodArray)>
If you do not specify the data type, ColdFusion examines the first 50 rows of each column to determine the data type
when performing conditional expressions.
In some cases, ColdFusion can guess a data type that is inappropriate for your application. In particular, if you use
columns in a WHERE clause or other conditional expression, the data types must be compatible. If they are not
compatible, use the CAST function to recast one of the columns to a compatible data type. For more information on
casting, see
"Using the CAST
"Understanding Query of Queries
Note: Specifying the data type in the
function" on page 442. For more information on data type compatibility, see
processing" on page 448.
function helps you avoid compatibility issues.
QueryNew
Last updated 1/20/2012
function that omits the second parameter
QueryNew
441

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents