How SQLDA Is Processed in Dynamic FRS
Like Dynamic SQL, Dynamic FRS uses the SQLDA to store the results of a describe statement. However, in Dynamic FRS, the interpretation of the content of the sqld and sqlvar elements differs slightly:
• The sqld indicates the number of form fields or table field columns associated with the describe statement (rather than the number of result columns).
If the value of sqld is zero, then the form had no fields or the table field had no columns of the given mode. If sqld is greater than sqln, then the program must reallocate the SQLDA to provide more storage buffers and reissue the describe statement. When the SQLDA is used to dynamically set or retrieve information from a form or table field, sqld must be equal to the number of form fields or table field columns affected by the statement. When used in a FRS application, the SQLDA components contain the following information.
• Each sqlvar element describes one of the form's fields or one column of the described table field. Each sqlvar element consists of the following:
sqltype
Specifies a 2-byte integer indicating the type of the field or column
sqllen
Specifies a 2-byte integer indicating the length of the field or column
sqldata
Specifies a pointer to the host variable described by the type and length
sqlind
Specifies a pointer to the indicator variable associated with the host variable
sqlname
Specifies the field or column name
All other elements of the SQLDA are identical, whether used in Dynamic FRS or Dynamic SQL statement.
With two exceptions, the procedures for analyzing and processing the information in the SQLDA are the same in Dynamic FRS as in Dynamic SQL. These exceptions follow.
A Dynamic FRS Describe Form Statement Returns a Type Code of 52
This code indicates that the described field is a table field. You must issue a describe table statement to collect the column information about the table field. You can issue this statement either at the end of the processing or immediately. If you issue the describe table immediately, you must use a different SQLDA.
For example, the following program fragment, which generates a report from a form, checks the field's data type and, if a table field type is encountered, allocates another SQLDA and describes the table field into it.
...
exec frs describe form :form_var into :form_desc;
/* Confirm that form descriptor is large enough */
if (form_desc.sqld > form_desc.sqln) then
free form_desc;
allocate a descriptor with sqld or more
sqlvar elements;
exec frs describe form :form_var
into :form_desc;
end if;
/* Generate report for form */
call report_form(form_var, form_desc);
/* Find all table fields (type 52),
** describe them and generate a report */
for index = 1 to form_desc.sqld loop
if (form_desc.sqlvar(index).sqltype = 52) then
table_var = form_desc.sqlvar(index).sqlname;
exec frs describe table :form_var :table_var
into :table_desc;
/* Confirm that table field descriptor
** is large enough */
if (table_desc.sqld > table_desc.sqln) then
free table_desc;
allocate a descriptor with sqld or more
sqlvar elements;
exec frs describe table :form_var :table_var
into :table_desc;
end if;
call report_table(table_var, table_desc);
end if;
end loop;
...
Dynamic FRS Uses the sqlname Field Differently than Dynamic SQL
In Dynamic FRS, you must retain the value in sqlname to execute subsequent statements using the descriptor. The FRS uses these values to associate the fields or columns with the variables pointed at by sqldata. Dynamic SQL associates database columns with the sqldata variables based on the order of the columns in the SQL statement.
Last modified date: 04/03/2024