Was this helpful?
How to Declare an SQLDA Record Variable
Once the SQLDA type definition has been included (or hard-coded), the program can declare an SQLDA record variable. This variable must be declared outside of a declare section, as the preprocessor does not understand the special meaning of the components of the SQLDA. When the variable is used, the preprocessor will accept any object name, and assume that the variable refers to a legally declared SQLDA record.
If a program requires a statically declared SQLDA with the same number of sqlvar variables as the IISQLDA type, then it can accomplish this as in the following example:
exec sql include sqlda;
var
    sqlda: IIsqlda;         { Outside of a DECLARE SECTION }
...

sqlda.sqln := IISQ_MAX_COLS; { Set the size }
...

exec sql describe s1 into :sqlda;
Recall that you must confirm that the SQLDA object being used is a valid SQLDA record variable.
If a program requires a statically declared SQLDA with a different number of variables (not IISQ_MAX_COLS), it can declare its own type. For example:
const
    NUM_COLS = 20;

type
    My_Sqlda = record
        my_sqid:     packed array[1..8] of Char;
        my_sqbc:     Integer;
        my_vars:     [word] 0..500;
        res_vars:    [word] 0..500;
        col_vars:    array[1..NUM_COLS] of IIsqlvar;
    end;

var
    my_sq: My_Sqlda;

...

my_sq.my_vars := NUM_COLS; { Set the size }
...

exec sql describe s1 into :my_sq;
In the above declaration the names of the record components are not the same as those of the IISQLDA record, but their layout is identical.
If the variable in the above example was declared as a pointer to an SQLDA record type, then it can be dynamically allocated and used as in the following example:
{ Assume My_Sqlda is declared as above }

var
    ptr_sq: ^My_Sqlda;

...

new(ptr_sq);

ptr_sq^.my_vars := NUM_COLS; { Set the size }
...

exec sql describe s1 into :ptr_sq^;
Last modified date: 08/28/2024