6. Embedded SQL for BASIC : BASIC Variables and Data Types : Variable 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 declaration section.
Use the following command to invoke DCLGEN from the operating system level:
dclgen language dbname tablename filename recordname
where
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 BASIC record variable that the command generates. The command generates a record definition named recordname followed by an underscore character (_) and a declaration for a record variable of recordname.
This command creates the declaration file filename, containing a record corresponding to the database table. The file also includes a record statement for the record variable, as well as a declare table statement that serves as a comment and identifies the database table and columns from which the record was generated.
Once the file has been generated, 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 BASIC 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 basic 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 definition of the BASIC record "emprec_". The last statement is a declare statement for the record "emprec". The 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 not null,      &
            dept    smallint)

    record emprec_
            word     eno
            string   ename = 20
            byte     age
            word     job
            double   sal
            word     dept
    end record
    declare emprec_ emprec
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
You can then use the emprec record in a select, fetch, or insert statement.
DCLGEN and Large Objects
You can use DCLGEN to generate an appropriate declare table statement with BASIC 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 BASIC compilers that support structures:
exec sql declare long_obj_table table     &
    (long_column long varchar)

record blobs_rec_
    string long column = 0
end record blobs_rec_
declare blobs_rec_ blobs_rec