Type Constraints
Type constraints can optionally follow the type name in an Ada object declaration. In general, they do not provide Embedded SQL with runtime type information, so they are not fully processed. The following two constraints describe the syntax and restrictions of Embedded SQL type constraints.
The Range Constraint
The syntax of the range constraint is:
range lower_bound .. upper_bound
In a variable declaration, its syntax is:
identifier: type_name range lower_bound .. upper_bound;
Syntax Notes:
• Even if Ada does not allow a range constraint, Embedded SQL does accept it. For example, both of the following range constraints are accepted, although the second is illegal in Ada because the string type is not a discrete scalar type:
digit: Integer range 0..9;
chars: String range 'a'..'z';
• The two bounds, lower_bound and upper_bound, must be integer literals, floating-point literals, character literals, or identifiers. Other expressions are not accepted.
• The bounds are not checked for compatibility with the type_name or with each other. For example, the preprocessor accepts the following three range constraints, even though only the first is legal Ada:
byte: Integer range -128..127;
word: Integer range 1.0..30000.0;
--Incompatible with type name
long: Integer range 1..'z';
--Incompatible with each other
The Discriminant and Index Constraints
The discriminant and index constraints have the following syntax:
(discriminant_or_index_constraint)
In a variable declaration the syntax is:
identifier: type_name (discriminant_or_index_constraint);
Syntax Notes:
• Even if Ada does not allow a constraint, Embedded SQL does accept it. For example, Embedded accepts both of the following constraints, even though the second is illegal in Ada because the integer type does not have a discriminant:
who: String(1..20); -- Legal index constraint
nat: Integer(0); -- Illegal context for discriminant
• The contents of the constraint contained in the parentheses are not processed. Consequently, Embedded SQL accepts any constraint, even if Ada does not allow it. For example, Embedded SQL accepts the following declaration but generates a later Ada compiler error because of the illegal index constraint:
password: String(secret word);
Note that the above type constraints are not discussed in detail after this section, and their rules and restrictions are considered part of the Embedded SQL/Ada declaration syntax.