Variable assignment - assign values to variables

 

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).

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.


SEE ALSO
SQL, EXPORT


Copyright © Thunderstone Software     Last updated: Sep 25 2019
Copyright © 2019 Thunderstone Software LLC. All rights reserved.