Simple Variables
A simple scalar-valued variable (integer, floating-point, or character string) is referred to by the syntax:
:simplename
Note:
1. If you use the variable to send data to Ingres, it can be any scalar-valued variable, constant, or enumerated literal.
2. If you use the variable to receive data from Ingres, it can only be a scalar-valued variable.
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":
exec sql begin declare section;
var
buffer : packed array[1..80] of char;
seconds : integer;
exec sql end declare section;
begin
...
exec frs message :buffer;
exec frs sleep :seconds;
end;
A special case of a scalar type is the enumerated type. As mentioned in the section describing declarations, Embedded SQL treats all enumerated literals and any variables declared with an enumerated type as integers. When used in an Embedded SQL statement, only the ordinal position of the value in relation to the original enumerated list is relevant. When assigning into an enumerated variable, Embedded SQL 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:
exec sql begin declare section;
type
Table_field_states =
(undefined, newrow, unchanged, changed, deleted);
var
tbstate: table_field_states;
ename: varying[20] of char;
exec sql end declare section;
...
tbstate := undefined;
exec frs getrow empform employee
(:ename = name, :tbstate = _state);
case tbstate of
undefined:
...
deleted:
...
end;
Another example retrieves the value TRUE (a predefined constant of type boolean) into a variable when a database qualification is successful:
exec sql begin declare section;
var
found: boolean;
exec sql end declare section;
...
found := false;
exec sql select :true
into :found
from emp
where age > 62;
if not found then
begin
...
end;
Note that a colon precedes the Pascal constant "TRUE." The colon is required before all Pascal named objects--constants and enumerated literals, as well as variables--used in Embedded SQL statements.