5. Embedded SQL for Ada : Ada Variables and Data Types : Embedded SQL/Ada Declarations : Character and String Data Types
 
Share this page                  
Character and String Data Types
Both the character and string data types are compatible with Ingres string objects. By default, the string data type is an array of characters.
The character data type does have some restrictions. Because it must be compatible with Ingres string objects, you can use only a one-dimensional array of characters. Therefore, you cannot use a single character or a multi-dimensional array of characters as a Ingres string. Note that you can use a multi-dimensional array of strings. For example, the following four declarations are legal:
subtype Alphabet is Character range 'a'..'z';
type word_5 is array(1..5) of Character;
                                -- 1-dimensional array
word_6: String(1..6);           -- Default string type
word_arr: array(1..5) of String(1..6);
                                -- Array of strings
However, the declarations below are illegal because they violate the Embedded SQL restrictions for the character type. Although the declarations may not generate Embedded SQL errors, the Ada compiler does not accept the references when used with Embedded SQL statements.
letter: Character;        -- 1 character
word_arr: array(1..5) of word_5;
                          -- 2-dimensional array of char
Both could be declared instead with the less restrictive string type:
letter: String(1..1);
word_arr: array(1..5) of String(1..5);
                         -- Array of strings
Character strings containing embedded single quotes are legal in SQL, for example:
mary's
User variables may contain embedded single quotes and need no special handling unless the variable represents the entire search condition of a where clause:
where :variable
In this case you must escape the single quote by reconstructing the :variable string so that any embedded single quotes are modified to double single quotes, as in:
mary''s
Otherwise, a runtime error will occur.
For more information on escaping single quotes, see String Literals in this chapter.