|
A variable's type denotes what kind of values it
contains. A variable may have any Texis SQL type, eg. varchar
for a simple text string, int
for integers, or counter
for a counter field. The type of a variable depends on how it was
assigned. Returned variables from <SQL>
statements have the
type of the corresponding table column. An assignment statement
determines the type of the assigned-to variable from that of its
arguments. The type of the return value of user/builtin functions
depends on the function.
Casting
Where needed, a variable's values are cast , ie. copied
and changed to, a different type. For example, passing an integer
variable to a SQL statement that expects a varchar
field, will
automatically cause the integer value to be cast to a string.
A variable's type affects how it is used in expressions, most
notably comparisons. Integer values are compared numerically, so
the integer 123 is greater than the integer 45. Strings (varchar
type) however, are compared alphabetically, so the string
value 123
is less than the string 45
, just as abc
is less than de
.
IF statement casting
It is useful to note that in an <IF>
statement where two
values of different types are compared, it is the left value's
type that controls the comparison. For example:
If $x
is an integer, then it is compared numerically to
123. However, if $x
is a string type, it is compared
alphabetically. To avoid this ambiguity, put the literal value on
the left when possible:
Literal Types
A literal value used in an assignment statement has one of two
types, string or integer. If all the values are normalized (no
leading zeros) integers of 8 digits or less, the variable's type is
integer. In all other cases it is a string. This ensures that
characters are not lost from the original value if it looks like
another type but is cast to a string later. The same rule holds
true for initial values, eg. from CGI, the environment, etc.
|