5. Embedded SQL for Ada : Ada Variables and Data Types : Variable Usage : Access Variables
 
Share this page                  
Access Variables
An access variable must qualify another object using the dot operator, and using the same syntax as a record component:
:access.reference
Syntax Notes:
By the time you reference an access variable, you must fully define the type to which it is pointing. This is true even for access types that were declared to point at incomplete types.
The final object denoted by the above reference must be a scalar value (integer, floating-point or character string). There can be any combination of arrays, records or access variables, but the last object referenced must be a scalar value.
If an access variable is pointing at a scalar-valued type, then the qualification must include the Ada .all clause to refer to the scalar value. If you use the .all clause, it must be the last component in the qualification. For example:
exec sql begin declare section;
    type Access_Integer is access Integer;
    ai: Access_Integer;
exec sql end declare section;
    ...

ai := new Integer'(2);
exec frs sleep :ai.all;
In the following example, an access type to an employee record is used to load a linked list of values into the Employee database table.
exec sql begin declare section;
        type Employee_Rec;
        type Emp_Link is access Employee_Rec;
        type Employee_Rec is
                record
                    ename: String(1..20);
                    eage:  Short_integer;
                    eidno: Integer;
                    enext: Emp_Link;
                end record;
        elist: Emp_Link;
exec sql end declare section;
    ...

while (elist <= null) loop
    exec sql insert into employee (name, age, idno)
        values (:elist.ename, :elist.eage, :elist.eidno);
    elist := elist.enext;
end loop;