7. Embedded SQL for Pascal : Pascal Variables and Data Types : Embedded SQL/Pascal Declarations : Embedded SQL/Pascal Declarations Example
 
Share this page                  
Embedded SQL/Pascal Declarations Example
The following example demonstrates some simple Embedded SQL/Pascal declarations:
program Concluding_Example( input, output );
exec sql include sqlca; {Include error handling}
exec sql begin declare section;
const
         max_persons = 1000;
type
         shortshortinteger = [byte] -128 .. 127;
         shortinteger = [word] -32768 .. 32767; {same as indicator type}
         string9 = packed array[1..9] of char;
         string12 = packed array[1..12] of char;
         string20 = packed array[1..20] of char;
         string30 = packed array[1..30] of char;
         varstring = varying[40] of char;

record datatypes_rec = {Structure of all types}
         d_byte :         shortshortinteger;
         d_word :         shortinteger;
         d_long :         integer;
         d_single :       real;
         d_double :       double;
         d_string :       string20;
    end;

record Persontype_rec = {variant record}
         age :              shortshortinteger;
         flags :            integer;
         case married :     boolean of
            true :         (spouse_name : string30);
            false :        (dog_name : string12);
    end;
var
    empform, deptform : [external] integer;
                {compiled forms}
    dbname : String9;
    formname, tablename, columnname : String12;
    salary : Real;

    d_rec : Datatypes_Rec;
    person : Persontype_Rec;
    person_store : array[1..MAX_PERSONS] of Persontype_Rec;
    person_null: array[1..10] of Indicator;

    exec sql include 'employee.dcl'; {From DCLGEN}
exec sql end declare section;

begin
        dbname := 'personnel';
        ...

end. {Concluding_Example}