5. Embedded SQL for Ada : Ada Variables and Data Types : Embedded SQL/Ada Declarations : DCLGEN Utility
 
Share this page                  
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. Use the following command to invoke DCLGEN from the operating system level:
dclgen language dbname tablename filename recordname
language
Defines the Embedded SQL host language, in this case, ada.
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 Ada record variable that the command creates. The command generates a record type definition named recordname, followed by "_rec". It 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 you have generated 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 an Ada 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(14,2) not null,
            dept    smallint);
and the DCLGEN system-level command is:
dclgen ada 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 Ada record type definition "emprec_rec." The last statement is a declaration, using the "emprec_rec" type, for the record variable "emprec." The exact contents of the employee.dcl file are:
-- 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(14,2) not null,
    dept       smallint);
type emprec_rec is
    record
    eno:       short_integer;
    ename:     string(1..20);
    age:       short_short_integer;
    job:       short_integer;
    sal:       long_float;
    dept:      short_integer;
    end record;
emprec: emprec_rec;
You should include this file, 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;
You can then use the emprec record in a select, fetch, or insert statement.
The field names of the structure that DCLGEN generates are identical to the column names in the specified table. Therefore, if the column names in the table contain any characters that are illegal for host language variable names you must modify the name of the field before attempting to use the variable in an application.
DCLGEN and Large Objects
When a table contains a large object column, DCLGEN will issue a warning message and map the column to a zero length character string variable. You must modify the length of the generated variable before attempting to use the variable in an application.
For example, assume that the "job_description" table was created in the personnel database as:
create table job_description (job smallint,
     description long varchar);
and the DCLGEN system level command is:
dclgen ada personnel job_descriptionjobs.dcl jobs_rec
The contents of the jobs.dcl file would be:
-- Description of table job_description from
-- database personnel
exec sql declare job_description table
                (job         smallint,
                long_column long varchar);

type jobs_rec_rec is
record
         job:         short_integer;
         description: string(1..0);

end record
jobs_rec: jobs_rec_rec;