SYNOPSIS<$var = [value1 ...] >
<[$var = ](SQL expression)>
DESCRIPTION
Variables are explicitly set with an assignment statement. The
variable on the left is set to the list of values on the right. The
right-side values are either literals (plain strings) or other
variables. Each value of a variable on the right is assigned to a
single value of the left-side variable; values are not concatenated
together. If no values are given on the right, the assigned-to (left)
variable is unset (i.e. has no values). Example:
<$code = "Klaatu" "barada" "nikto">
<$said = "Gort" $code "right" "now">
The value of $said
would be the 6 values Gort
,
Klaatu
, barada
, nikto
, right
, now
.
Literals on the right side of (non-SQL-expression) assignments are
either varchar
(string) or long
. If the value has an
optional leading minus sign, no leading zeroes, and is one to eight
digits, it will be a long
; otherwise it is varchar
.
The left-side variable's type will differ from the right if the types
on the right are not identical. In version 7.02.1416623000 20141121
and later, if all values on the right are numeric (floating-point or
integral types), the left-side type will be numeric, and just large
enough to maintain precision and sign of all right-side values (if
possible); otherwise the left side will be varbyte
if the
right-side types are all [var]char
and at least one
[var]byte
is present; otherwise varchar
is used. If any
right-side type is var...
or multi-value, the left-side will be
var...
. Note that the type chosen might not be any of the
right-side types; e.g. int
and dword
typically result in
long
, as the largest dword
value cannot fit in an
int
without overflow. In previous versions, if the right-side
types are not identical, the left side became varchar
.
If the right side is enclosed in parentheses, then it is interpreted
as a SQL SELECT
expression and evaluated. It may then be any
valid Texis select
expression:
<$x = (19 * 6 + 5)>
<$txt = ( "This is test " + $x )>
The value of $x
would be the integer 119
, and the value
of $txt
would be the string "This is test 119
": the
+
operator concatenates when given strings. Quotes and
Vortex operators in SQL expressions are mapped as in IF
(here).
In version 8 and later, the left-side variable may be omitted to just evaluate the right-side SQL expression, with no variable assignment. This can be useful when SQL functions are to be run, but the return value can be ignored, e.g. the middle set of statements here:
<$writer = (xmlWriterNewToString(""))>
<!-- These statements ignore the functions' return value: -->
<(xmlWriterStartDocument($writer, "1.0"))>
<(xmlWriterWriteComment($writer, "Comment"))>
<(xmlWriterWriteElement($writer, "rootNode", "content"))>
<(xmlWriterEndDocument($writer))>
<$ret = (xmlWriterGetContent($writer))>
Document: $ret
See also the syntaxversion
pragma
(here), which can disable this behavior.
If the assigned-to variable is currently in a loop construct,
e.g. inside a LOOP
, SQL
or TIMPORT
that is looping
over the variable, then only the current value of the variable
is changed, to the first value of the right side. The type is cast to the overall type of the
assigned-to variable. If no values are present on the right, then the
assigned value is the empty string ("").
CAVEATS
See type caveats above.
If a SQL expression (in parentheses) is being used, multi-value variables are converted according to the current <sqlcp arrayconvert> setting, and an empty (no values) variable is considered an empty string.