Elements of ColdFusion Expressions

ColdFusion expressions consist of operands and operators. Operands are comprised of constants and variables. Operators are the verbs that act on the operands; functions are a form of operator. This chapter first describes the operands and then describes the operators.

Operands: data types, constants, and variables

The sections on operands provide detailed information on the following:

Data types of constants and variables

In ColdFusion, constants and variables have implied data types. The reason for the term "implied" is that there are no variable declarations that define the scalar data type of a variable, as one finds in statically typed languages such as Pascal. Whenever you use a constant or set the value of a variable, the value you use has a type, such as integer, real, or string. For example, if you use cfset to create a variable AGE and set its value to 62, the implied data type is integer. In addition to these scalar types, ColdFusion also supports lists, structures, and arrays. The following table describes the types of variables and constants you can use in a ColdFusion application page.
Type
Description
Integer
Numbers with no decimal point. The lower limit for a signed integer is -2,147,483,648, and the upper limit for a signed integer is 2,147,483,647.
If you specify an integer outside the limits, ColdFusion converts it to a floating point value to avoid overflow. In doing so, ColdFusion preserves the number's magnitude. However, the conversion to floating point comes at the expense of precision, since ColdFusion has only a fixed number of bits to work with.
Real number
Numbers with a decimal part. Also known as floating point numbers.
The range of ColdFusion numbers is approximately ±10300. Most operations are accurate to 12 digits after the decimal point.
ColdFusion supports scientific notation; this means that you can enter numbers in the form 3 E 16 and perform calculations on them.
String
Text values, which can be enclosed in single (') or double (") quotes. String length is limited only by the amount of available memory on the ColdFusion server.
To use a single quote inside a string that is single quoted, escape, or repeat, the single quote by using two single quotes. For example:

'the ''best'' software' 

Similarly, you can escape a double quote inside a double quote-enclosed string.
To insert a pound sign in a string, the pound sign must be escaped by repeating it. For example:

"enter a pound sign (##) here" 

Boolean value
The result of a logical operation. The value can be TRUE or FALSE. The numerical value of TRUE is 1. The numerical value of FALSE is 0. The string value of TRUE is "YES"; FALSE is "NO".
Date value
Date-and-time values identify a date and time in the range 100AD to 9999AD. If no time part is specified, time is set to 12:00am.
You can also enter a date object in the following formats:

"October 30, 1999"

"Oct 30, 1999"

"Oct. 30, 1999"

"10/30/99"

"1999-30-10" 

Time value
You can enter a date-and-time object in the following formats:

"October 30, 1999 02:34:12"

"October 30, 1999 2:34a"

"October 30, 1999 2:34am"

"October 30, 1999 02:34am"

"October 30, 1999 2am" 

The time part of the object is accurate to the second.
Array
Arrays are tables of objects or data that can be indexed. The ArrayNew function only supports creating up to three-dimensional arrays, there is no limit on array size or maximum dimension.
Elements stored in an array are referenced as follows:

<cfset myarray[1][2] = Now()> 

For more information, see Developing ColdFusion Applications.
Structure
You can use structures to create and maintain key-value pairs, to refer to related string values as a unit rather than individually, or to create associative arrays.
For more information, see Developing ColdFusion Applications.
List
Lists are a kind of string made up of elements separated by delimiters.
The default delimiting character used by list processing functions is a comma. A list can have more than one delimiting character. You specify the allowable delimiters for a list in the delimiters parameter of ColdFusion list processing functions.
White space is not considered a delimiter. However, when using lists where elements may be separated by white space as well as by other delimiters, add the white space characters to the list of delimiters. Delimiters before the first element and after the last element are ignored.
Lists cannot be nested into one another. Also, lists can contain no empty elements. A list can be empty, however. The empty list is equivalent to the empty string "".
Query
ColdFusion queries can be referenced as objects by assigning a query to a variable:

<cfquery name = "myquery"

  datasource = "mydata"

  SELECT * FROM CUSTOMERS

</cfquery>



<cfset myquery2 = myquery> 

In this case the query is not copied. Both names point to the record set data, so that if you make changes to the table referenced in the query, the original query and the query object myquery2 both reflect these changes. If you perform this operation with an array, the array is copied.
Queries and variables cannot have the same name at the same time in the same application page.
COM object
Component Object Model (COM) objects are non-visual components that encapsulate functionality that you can invoke in your application pages. ActiveX, OCX, CORBA, and ADO objects are examples of COM objects.
COM objects generally contain methods, like functions, that you can use to execute operations:

<cfset temp = Mailer.SendMail()> 

COM objects generally contain properties you can read and write using ColdFusion variables:

<cfset Mailer.FromName = Form.fromname> 

Properties can be invoked on either side of an assignment.
For more information, see Developing ColdFusion Applications.

Notes on date-and-time values

This section contains information about how date and time variables are handled by ColdFusion.

How date and time values are stored

ColdFusion represents date-and-time values internally on a time line as a subset of the real numbers. This representation is optimized for efficiency in evaluation and because it is the method used by many popular database systems. In this model, one day is equal to the difference between two successive integers. The time portion of the date-and-time value is stored in the fractional part of the real number.

Thus, you can use arithmetic operations to manipulate date-and-time values. For example, Now() + 1 evaluates to tomorrow at the same time. However, we strongly discourage ColdFusion developers from using this potentially troublesome method of manipulating date-and-time objects. Use the date-and-time manipulation functions instead.

21st century dates

Two-digit years from 00 to 29 are treated as 21st century dates; 30 to 99 are treated as 20th century dates. Thus, the following dates are equivalent:

"October 30, 2015"

"October 30, 15"

Constants

The value of a constant does not change during program execution. Constants are simple scalar values that you can use within expressions and functions. They include integers, real numbers, time and date values, boolean values, string values, and lists.



Banner.Novgorod.Ru