Expressions

An expression is a combination of operands separated by operators. An expression produces a result and is an value origin.

The following diagrams define the expression syntax:

expression.bmp

Parameter Marker

For ODBC, OLE DB and JDBC, the literal for parameter markers is a single question mark (?)

For Adabas embedded SQL, this is a host variable name , in the format of :host_variable.
 

Expressions Without Operators

If an expression is used without operators, the result is the value represented by the object specified. For example. the result of an expression consisting of a column specification is the value represented in that column specification.

Expressions With Operators

The operators which can be used in expressions can be divided into monadic, diadic and concat operators:

  • Monadic Operators

are prefix operators and have one operand. Monadic operators include the monadic plus (+) and the monadic minus ( - ) operators. The monadic plus operator does not change the value of its operand. The monadic minus operator changes the sign of the value of its operand. Monadic operators can only be used with one numeric data type operand.

  • Diadic Operators

are infix operators and have two operands. Diadic operators include the addition (+), subtraction ( - ), multiplication ( * ) and division ( / ) operators. Diadic operators can only be used with numeric data type operands. The resulting data type of an expression with two operands and a diadic operator depends on the data types of the two operands and on the operator. See Numeric Expressions - Dyadic operations.
 

  • Concat Operator

is an infix operator and has two operands. The concat operator (||) will first implicitly convert non character values to character strings.  Then the two strings are combined.

 

Assignments and Comparisons

All operations in SQL can be broken down to two basic operations: value assignment and value comparison.

Values are assigned during FETCH, UPDATE, INSERT and single-row SELECT statement processing. Value comparison takes place during predicate statement execution. Both assignment and comparison operations have two operands. An assignment operation has a receiving operand and a sending operand. In an assignment, the receiving operand gets the sending operand value. A comparison operation has two comparison operands whose values are compared with each other. Both assignment operands and comparison operation operands must have comparable data types.

In this example, assume Operand 1 has data type x. Operand 2 has a comparable data type only if its data type is:

  • x or

  • a data type which can be converted to x or

  • a data type to which x can be converted, unless operand 1 is the receiving operand of an assignment operation. In this case, the data type is fixed and can not be changed.

Normally, character-string, Binary, and numeric data types are not comparable.

If both operands have different but yet comparable data types and a conversion has to be performed, this is always done from a `lower' data type to a `higher' data type (see Mixed Operands above).

Character-String Assignment

When a data type character-string value is assigned to a value recipient (either a host variable or a column), the value length and the value recipient's defined length are compared:

  • If both lengths are the same, the recipient is assigned the value. After the assignment, the value and the recipient value are identical.

  • If the value  length is smaller than the recipient length, the value is padded with blanks.

  • If the value length is greater than the recipient length, the value is truncated. If the INDICATOR variable was specified, it will show the number of truncated characters.

Numeric Assignment

When a numeric data type value is assigned to a recipient, data type conversion is performed when the value and the recipient data types are not identical.

Binary Assignment

When a binary data type value is assigned to a value recipient (either a host variable or a column), the value length and the value recipient's defined  length are compared:

  • If both lengths are the same, the value is assigned to the recipient. After assignment, the value and the value recipient are identical.

  • If the value length is greater than the recipient length, an error condition is raised.

  • If the value length is smaller than the recipient length, the value's most significant missing digits are appended with zeros.

If the application program is a remote client and Adabas SQL Gateway Embedded SQL resides on a server machine where ASCII/EBCDIC and/or byte swapping conversions would normally be induced during client/server communication, these conversions are suppressed for host variables. The host program must interpret the host variable contents.

For further information refer to the Adabas SQL Gateway Embedded SQL Programmer's Guide, sections: Dynamic SQL and Embedding SQL Statements in Host Languages.

Character-String Comparison

To compare  two character-string data types, CONNX compares the corresponding character in each string. If the two strings do not have the same length, the shorter one of the two is appended with as many blanks as necessary, so both strings have the same length. The padding is done with the appropriate environment-dependent hexadecimal representation for a blank (e.g. x'20' for an ASCII environment and x'40' for an EBCDIC environment) and that padding is either to the right or to the left, depending on the underlying hardware architecture.

  • Two values of data type character-string are equal if and only if both strings are empty (have a length of zero), or every corresponding character is the same. The comparison is done either from left to right or from right to left depending on and according to the underlying hardware architecture.

  • Two values of data type character-string are unequal if at least one corresponding character is found to be unequal. The order of two unequal character-string values is determined by the first unequal character found during the comparison process (either from the left or from the right depending on the underlying hardware architecture). The order is then determined by the EBCDIC or ASCII collating sequence.

Numeric Comparison

The comparison of two values of data type numeric is performed following the normal algebraic rules taking the sign into account.

 

Example:

-5 is less than -3

Numeric comparison is always done between two values of the same data type. If two numeric values do not have the same data type, data type conversion is performed.

Binary Comparison

To compare two binary data type values, CONNX compares the corresponding bit digit in each value. The two values are equal if every corresponding digit is identical.

If the two values are of different lengths, the most significant missing digits of the shorter value are appended with the value `0'.

The comments regarding host variables and binary assignment, as described above, also apply to comparison.