5. Embedded SQL for Ada : Ada Variables and Data Types : Embedded SQL/Ada Declarations : Embedded SQL/Ada Declarations Example
 
Share this page                  
Embedded SQL/Ada Declarations Example
The following example demonstrates some simple Embedded SQL/Ada declarations.
package Compiled_Forms is
        exec sql begin declare section;

                    empform, deptform: Integer; -- Compiled forms
        exec sql end declare section;

        pragma import_object( empform );
        pragma import_object( deptform );
    end Compiled_Forms;

with Compiled_Forms; use Compiled_Forms;

exec sql include sqlca; -- Include error handling

package Concluding_Example is
        exec sql begin declare section;

                    max_persons: constant := 1000;
                    dbname:             String(1..9):="personnel";
                    formname, tablename, columnname: String(1..12);
                    salary:             Float;

          type datatypes_rec is -- Structure of all types
                      d_byte: Short_Short_Integer;
                      d_word: Short_integer;
                      d_long: Integer;
                      d_single: Float;
                      d_double: Long_float;
                      d_string: String(1..20);
                end record;
                d_rec: datatypes_rec;

          -- Record with a discriminant
               record persontype_rec (married: in Boolean) is
                      age:   Short_Short_Integer;
                      flags: Integer;
                      case married:
                        when TRUE =
                         spouse_name: String(1..30);
                        when FALSE =
                          dog_name: String(1..12);
                      end case;
                end record;
                person: persontype_rec(TRUE);
                person_store: array(1..max_persons) of
                            persontype_rec(false);

             exec sql include 'employee.dcl'; -- From dclgen
             ind_var: Short_Integer := -1;    -- Indicator
                                            -- variable
    exec sql end declare section;
end concluding_examples;