7. Embedded QUEL for Pascal : Pascal Variables and Data Types : Variable Usage : Simple Variables
 
Share this page                  
Simple Variables
A simple scalar-valued variable (integer, floating-point or character string) is referred to by the syntax:
simplename
Syntax Notes:
1. If the variable is used to send data to Ingres, it can be any scalar-valued variable, constant or enumerated literal.
2. If the variable is used to receive data from Ingres, it cannot be a constant or an enumerated literal.
3. Packed or varying arrays of characters (for example, character
strings) are referenced as simple variables.
The following program fragment demonstrates a typical message-handling routine that uses two scalar-valued variables, "buffer" and "seconds":
##  var
##      buffer : packed array[1..80] of Char;
##      seconds : Integer;
        ...

##      message buffer
##      sleep seconds
A special case of a scalar type is the enumerated type. As mentioned in the section describing declarations, EQUEL treats all enumerated literals and any variables declared with an enumerated type as integers. When used in an EQUEL statement, only the ordinal position of the value in relation to the original enumerated list is relevant. When assigning into an enumerated variable, EQUEL will pass the object by address and assume that the value being assigned into the variable will not raise a runtime error. For example, the following enumerated type declares the states of a table field row, and the variable of that type will always receive one of those values:
##  type
##      Table_Field_States =
##          (UNDEFINED, NEWROW, UNCHANGED, CHANGED, DELETED);
##  var
##      tbstate: Table_Field_States;
##      ename: varying[20] of Char;
        ...

        tbstate := undefined;
##      getrow empform employee (ename = name, 
##              tbstate = _state)

        case tbstate of
                undefined:
                ...

                deleted:
                ...
        end;
Another example retrieves the value TRUE (an enumerated literal of type boolean) into a variable when a database qualification is successful:
##  var
##          found: Boolean;
##          qual: varying[100] of Char;
            ...

            found := FALSE;
##          retrieve (found = TRUE) WHERE qual

        if not found then 
        begin
        ...

        end;