Analyzing the Sqlvar Elements
After describing a statement, the program must analyze the contents of the sqlvar array. Each element of the sqlvar array describes one result column of the SELECT statement. Together, all the sqlvar elements describe one complete row of the result table.
The DESCRIBE statement sets the data type, length, and name of the result column (sqltype, sqllen and sqlname), and the program must use that information to supply the address of the result variable and result indicator variable (sqldata and sqlind).
For example, assuming the table, object, was created as follows:
exec sq create table object
(o_id integer not null,
o_desc character(100) not null,
o_price float not null,
o_sold date);
and the following dynamic query was described as follows:
exec sql prepare s1 from 'select * from object';
exec sql describe s1 into sqlda;
The SQLDA descriptor results would be:
The DESCRIBE statement sets the value of sqllen to the length of the result column. For character data types, sqllen is set to the maximum length of the character string. For numeric data types, sqllen is set to the size of the numeric field as declared when created. For the date data type, sqllen is set to 0, but the program should use a 25‑byte character string to retrieve or set date data. Note that, for nullable columns, a negative value is returned.
After the statement is described, your program must analyze the values of sqltype and sqllen in each sqlvar element. If sqltype and sqllen do not correspond exactly with the types of variables used by the program to process the SELECT statement, then sqltype and sqllen must be modified to be consistent with the program variables. After describing a SELECT statement, there will be one sqlvar element for each expression in the select target list.
After processing the values of sqltype and sqllen, allocate storage for the variables that will contain the values in the result columns of the SELECT statement, by pointing sqldata at a host language variable that will contain the result data. If the value of sqltype is negative, which indicates a nullable result column data type, allocate an indicator variable for the particular result column and set sqlind to point to the indicator variable. If sqltype is positive, indicating that the result column data type is not nullable, an indicator variable is not required. In this case, set sqlind to zero.
To omit the null indicator for a nullable result column (sqltype is negative), set sqltype to its positive value and sqlind to zero. If sqltype is positive and an indicator variable is allocated, set sqltype to its negative value, and set sqlind to point to the indicator variable.
In the previous example, after the program analyzes the results as described, the date type is changed to character and sqlind and sqldata are set to appropriate values. The values in the resulting sqlvar elements are:
Last modified date: 08/14/2024