

|
|
Variables in CFML; Simple Data TypesCFML supports many different types of data that can be assigned to variables and manipulated by the language. These data types can be grouped together as either "simple" types or "complex" types. The CFML function IsSimpleValue() can be used to determine if a given variable is a simple or complex type.
StringsStrings are text data and are wrapped in quotes (single or double will do, but double quotes are the norm). Examples of strings are "Hello", "14" and 'Goodbye'. Strings may contain any characters. The single and double quotes and the pound sign ("#") however are special characters and cannot be assigned directly to a string. These three special characters may be included in strings but must be escaped (see the section on assigning data to variables for more information). When comparing strings it is recommended that you use the Compare() and CompareNoCase() functions not the mathematical operators to ensure comparison as a string and to control case sensitivity in comparisons. ListsLists are not truly a separate data type, but rather specially formatted strings. Lists are values delimited by a character (or multiple characters). Although the comma is the most common (and the default) delimiter CFML allows you to treat any character, even non-printable characters, as a delimiter. So something like "a,b,c,d" could be considered a comma-delimited list of four items, "1-2-3-4" can be seen as a dash-delimited list of four items and "1,2|3*4" could be treated as a list of numbers with multiple delimiters in CFML. This ability of CFML to see any character as a delimiter can be incredibly useful. For example a system path such as "c:\wwwroot\website\content\file.cfm" can be treated as a slash-delimited list, an IP address (i.e. 127.0.0.1) can be treated as a dot-delimited list and any sentence (such "How are you today?") can be treated as a space-delimited list. ColdFusion will collapse multiple delimiters in a list. This means that multiple, empty delimiters will be seen by ColdFusion seen as one. The string "1,,2,,,,3,,4" will be seen as a comma-delimited list of four items. CFML provides a very rich set of list manipulation functions. See the CFML Reference manual for more information. BooleansBooleans are simple yes/no, true/false, on/off values. In CFML Boolean strings are either "Yes", "True", "No" or "False" or, numerically, zero (False) or one (True). When doing Boolean comparisons in CFML any non-zero integer will also be considered "True" while only zero will be considered "False". The Boolean strings TRUE and FALSE do not need to be quoted in expressions, however "YES" and "NO" must be quoted. Also booleans are, by their nature, expression results. In other words you don't need to say, explicitly "If myVariable is true", rather you can say simply "If myVariable". If you do formulate an expression comparing boolean values remember that "true" and "false" should not be quoted in the comparison to prevent them from being treated as strings. NumbersCFML doesn't require the programmer to differentiate between whole numbers (Integer) and decimal numbers (Floating Point). Integers can be from -2,147,483,648 to 2,147,483,647 and ColdFusion will automatically convert integers outside this range to decimal numbers. ColdFusion's limit of +/-10300 for decimal numbers should handle any task (a high estimate for the number of atoms in the universe, for example, is 1081). Most operations are accurate to the twelfth decimal place.
Numbers in CFML do not have to be quoted, although they will still be treated as numbers in most expressions if quoted. ColdFusion offers many mathematical functions and can manipulate numbers in base 2-36 via the InputBaseN() function. Date/TimeColdFusion does its level best to understand most date formats passed to it. Dates must be between A.D. 100 to 9999 (earlier dates can be used manually as numbers of course, but ColdFusion doesn't consider them "true" date/times). If the date does not specify a four-digit year ColdFusion considers years 00-29 as 21st-century (2000s) and years 30-99 as 20th century (1900s). Times in CFML are accurate to the second. All of the following strings will be interperated by ColdFusion as dates: "Sep 14, 2001", "September 14, 2001", "09/14/2001", "9/14/01", "2001-09-14". There are many other variations and the IsDate() function can be used to determine if ColdFusion considers an arbitrary value a valid date. Times can be in either 12 or 24 hour clocks ("pm" or "p" must be specified for times after noon on the 12 hour clock). Example formats for times are "14:00:00", "2pm", "2:00pm", "2:00p", "02:00:00pm". There are many functions to create dates in CFML (such as CreateDate() and CreateTime()). There is a subtle, but very important difference between a string formatted as a date and a true date/time object as created by these functions. To prevent conversion errors and inconsistencies we recommend using a true date/time object as input to all functions that accept date/times whenever possible. CFML provides an incredibly rich set of functions to manipulate dates and extract meaningful, real-world data from them (for example the IsLeapYear() function can tell you if any given year is a leap year). When comparing dates use the DateDiff() function rather than the mathematical operators to ensure proper results. Universally Unique Identifier (UUID)In CFML a valid UUID is a string formatted as "xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx" with "x" being a hexadecimal number (0-9 and a-f). A UUID is created by the CreateUUID() function. UUIDs are generated by a special algorithm: with an almost complete certainty a UUID generated by one machine cannot be generated by another or again by itself. Because of this they are perfectly suited as unique identifiers across multiple systems. Like lists UUIDs are not a true data type but rather a specially generated and formatted string. Although not generally thought of as a data type some CFML tags (notably CFPARAM, described later) treat UUID as a valid data type. BinaryThe binary data type contains machine-readable representations of binary data files (executables, images, etc). The binary data type is an unusual one in that it is a simple value (in the sense that it is simply a collection of characters) but is not displayable as simple text. Binary data-types are only returned by the CFFILE tag (specifically the "READBINARY" action of the CFFILE tag). Like UUID binary is generally not considered a data type but is used as such by some tags (like CFPARAM). |