5. Embedded SQL for Ada : Ada Variables and Data Types : Embedded SQL/Ada Declarations : Simple Variable Declarations
 
Share this page                  
Simple Variable Declarations
An Embedded SQL/Ada variable declaration has the following syntax:
identifier {, identifier} :
                                          [constant]
                                          [array (dimensions) of]
                                          type_name
                                          [type_constraint]
                                          [:= initial_value];
Syntax Notes:
The identifier must be a legal Ada identifier beginning with an alphabetic character.
If you specify the constant clause, the declaration must include an explicit initialization.
If you specify the constant clause, the declared variables cannot be targets of Ingres assignments.
The Embedded SQL preprocessor does not parse the dimensions of an array specification. Consequently, the preprocessor accepts unconstrained array bounds and multi-dimensional array bounds. However, an illegal dimension (such as a non-numeric expression) is also accepted but causes Ada compiler errors.
For example, both of the following declarations are accepted, even though only the first is legal Ada:
square:        array (1..10, 1..10) of Integer;
bad_array:     array ("dimensions") of Float;
A variable or type name must begin with an alphabetic character, which can be followed by alphanumeric characters or underscores.
The type_name must be either an Embedded SQL/Ada type (refer to the list of acceptable types earlier in this chapter) or a type name already declared to Embedded SQL.
The legal type_constraints are described in the next section.
The preprocessor does not parse initial_value. Consequently, the preprocessor accepts any initial value, even if it can later cause an Ada compiler error. For example, both of the following initializations are accepted, even though only the first is legal Ada:
rowcount: Integer := 1;
msgbuf:   String(1..100) := 2; -- Incompatible value
You must not use a single quote in an initial value to specify an Ada attribute. Embedded SQL treats it as the beginning of a string literal and generates an error. For example, the following declaration generates an error:
id: Integer := Integer'First
The following is a sample variable declaration:
rows, records:    Integer range 0..500 := 0;
was_error:        Boolean;
min_sal:          constant Float := 15000.00;
msgbuf:           String(1..100) := (1..100 => ' ');
operators:        constant array(1..6) of String(1..2) :=
      ("= ", "!=", "<=", ">=");