Examples Of Type Conversion In Expression Evaluation - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

If you use SQL to insert data into a database or in a WHERE clause to select data from a
database, and the database driver does not support ODBC-formatted dates, use the
DateFormat
function to convert the date-time value to a valid format for the driver. This rule also applies to
queries of queries.
For example, the following SQL statement uses the
function in a query of queries to
DateFormat
select rows that have MyDate values in the future:
<cfquery name="MyQofQQ" dbtype="query">
SELECT *
FROM DateQuery
WHERE MyDate >= '#DateFormat(Now())#'
</cfquery>
The following query of queries fails with the error message "Error: {ts is not a valid date," because
the ColdFusion
function returns an ODBC timestamp:
Now
<cfquery name="MyQofQQ" dbtype="query">
SELECT *
FROM DateQuery
WHERE MyDate >= '#now()#'
</cfquery>
Using JavaCast with overloaded Java methods
You can overload Java methods so a class can have several identically named methods that differ
only in parameter data types. At runtime, the Java virtual machine attempts to resolve the specific
method to use, based on the types of the parameters passed in the call. Because ColdFusion does
not use explicit types, you cannot predict which version of the method the virtual machine will
use.
The ColdFusion
function helps you ensure that the right method executes by
JavaCast
specifying the Java type of a variable, as in the following example:
<cfset
emp.SetJobGrade(JavaCast("int", JobGrade))>
The
function takes two parameters: a string representing the Java data type and the
JavaCast
variable whose type you are setting. You can specify the following Java data types: bool, int, long,
float, double, and String.
For more information on the
function, see CFML Reference.
JavaCast
Using quotation marks
To ensure that ColdFusion properly interprets string data, surround strings in single- or double-
quotation marks. For example, ColdFusion evaluates "10/2/2001" as a string that can be
converted into a date-time object. However, it evaluates 10/2/2001 as a mathematical expression,
5/2001, which evaluates to 0.00249875062469.

Examples of type conversion in expression evaluation

The following examples demonstrate ColdFusion expression evaluation.
Example 1
2 * True + "YES" - ('y' & "es")
Result value as string: "2"
Explanation: (2*True) is equal to 2; ("YES"- "yes") is equal to 0; 2 + 0 equals 2.
Data type conversion
71

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents