5. Embedded SQL for Ada : Ada 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
Note:   
If you use the variable to send data to Ingres, it can be any scalar-valued variable, constant, or enumerated literal.
If you use the variable to receive data from Ingres, it cannot be a variable declared with the constant clause, a formal parameter that does not specify the out mode, a number declaration, or an enumerated literal.
A string variable (a 1-dimension array of characters) is referenced as a simple variable.
The following program fragment demonstrates a typical message-handling routine that uses two scalar-valued variables, "buffer" and "seconds":
procedure Msg
    exec sql begin declare section;
        (buffer: String; seconds: Integer)
    exec sql end declare section;
is
begin
    exec frs message :buffer;
    exec frs sleep :seconds;
end Msg;
A special case of a scalar type is the enumerated type. Embedded SQL treats all enumerated literals and any variables declared with an enumerated type as integers. When an enumerated literal is used in an Embedded SQL statement, only the ordinal position of the value in relation to the original enumerated list is relevant. When assigning from an enumerated variable or literal, Embedded SQL generates the following:
enumerated_type_name'pos(enumerated_variable_or_literal)
When assigning from or into an enumerated variable, the preprocessor passes the object by address and assumes that the value being assigned from or into the variable does not raise a runtime constraint error. In order to relax the restriction imposed by the preprocessor on enumerated literal assignments (of enumerated types that have included representation clauses to modify their values), you should assign the literal to a variable of the same enumerated type before using it in an embedded statement. For example, the following enumerated type declares the states of a table field row, and the variable of that type always receives one of those values:
exec sql begin declare section;
      type Table_Field_States is
            (undefined, newrow, unchanged, changed, deleted);
      tbstate: Table_Field_States := undefined;
      ename: String(1..20);
exec sql end declare section;
        ...

exec frs getrow empform employee (:ename = name,
        :tbstate = _state);

case tbstate is
            when undefined =>
            ...
end case;
Another example retrieves the value TRUE (an enumerated literal of type boolean) into a variable when a database qualification is successful:
exec sql begin declare section;
        found: Boolean;
        name:  String(1..30);
exec sql end declare section;
        ...

exec sql select :true
        into :found
        from personnel
        where ename = :name;
if (not found) then
        ...
end if;
Note that a colon precedes the Ada enumerated literal "TRUE." The colon is required before all named Ada objects--constants and enumerated literals, as well as variables--used in Embedded SQL statements.