7. Embedded SQL for Pascal : Pascal Variables and Data Types : Embedded SQL/Pascal Declarations : The DCLGEN Utility
 
Share this page                  
The DCLGEN Utility
DCLGEN (Declaration Generator) is a record-generating utility that maps the columns of a database table into a record that can be included in a variable declaration. You invoke DCLGEN from the operating system level with the following command:
dclgen language dbname tablename filename recordname
where
language
Defines the Embedded SQL host language, in this case, "pascal."
dbname
Defines the name of the database containing the table.
tablename
Defines the name of the database table.
filename
Defines the output file into which the record declaration is placed.
recordname
Defines the name of the Pascal record variable that the command creates. The command generates a record type definition named recordname, followed by "_rec." The command also generates a variable declaration for recordname.
This command creates the declaration file filename. The file contains a record type definition corresponding to the database table and a variable declaration of that record type. The file also includes a declare table statement that serves as a comment and identifies the database table and columns from which the record was generated.
After generating the file, you can use an Embedded SQL include statement to incorporate it into the variable declaration section. The following example demonstrates how to use DCLGEN in a Pascal program.
Assume the Employee table was created in the Personnel database as:
exec sql create table employee
            (eno       smallint not null,
             ename     char(20) not null,
             age       integer1,
             job       smallint,
             sal       decimal   not null,
             dept      smallint);
and the DCLGEN system-level command is:
dclgen pascal personnel employee employee.dcl emprec
The employee.dcl file created by this command contains a comment and three statements. The first statement is the declare table description of "employee," which serves as a comment. The second statement is a declaration of the Pascal record type definition "emprec_rec." The last statement is a declaration, using the "emprec_rec" type, for the record variable "emprec." The contents of the employee.dcl file are shown below.
{Description of table employee from database personnel}
exec sql declare employee TABLE
            (eno         smallint not null,
             ename       char(20) not null,
             age         integer1,
             job         smallint,
             sal         decimal  not null,
             dept        smallint);

type emprec_rec = record
            eno:         [word] -32768 .. 32767;
            ename:       packed array[1..20] of Char;
            age:         [byte] -128 .. 127;
            job:         [word] -32768 .. 32767;
            sal:         Double;
            dept:        [word] -32768 .. 32767;
end;
var emprec: emprec_rec;
This file should be included, by means of the Embedded SQL include statement, in an Embedded SQL declaration section:
exec sql begin declare section;
        exec sql include 'employee.dcl';
exec sql end declare section;
The emprec record can then be used in a select, fetch, or insert statement.
DCLGEN and Large Objects
You can use DCLGEN to generate an appropriate declare table statement with Pascal variables for tables that contain long varchar columns. For columns that have a limited length, the variables generated will be identical to the variables generated for the Ingres varchar datatype. For columns with unlimited length, such as:
create table long_obj_table(blob_col long varchar);
DCLGEN will issue an error message and generate a character string variable with zero length. You can modify the length of the generated variable before attempting to use the variable in an application.
For example the following table definition:
create tablelongobj_table
        (long_column     long varchar));
results in the following DCLGEN generated output for Pascal compilers that support structures:
exec sql declare long_obj_table table  
        (long_column         long varchar)

type blobs_rec_rec = record
         long_column : varying[0] of char;
end;
var blobs_rec : blobs_rec_rec;