A varying-list SELECT
statement is one in which the number and types of columns that are
to be returned are not known at precompilation time.
In
this case, the application does not know in advance the exact host
variables that need to be declared to hold a row of the result table.
Procedure
To process a variable-list SELECT statement, code your
application to do the following steps:
- Declare an SQLDA.
An SQLDA structure must
be used to process varying-list SELECT statements.
- PREPARE the statement using the INTO clause.
The
application then determines whether the SQLDA structure declared has
enough SQLVAR elements. If it does not, the application allocates
another SQLDA structure with the required number of SQLVAR elements,
and issues an additional DESCRIBE statement using the new SQLDA.
- Allocate the SQLVAR elements.
Allocate storage
for the host variables and indicators needed for each SQLVAR. This
step involves placing the allocated addresses for the data and indicator
variables in each SQLVAR element.
- Process the SELECT statement.
A cursor
is associated with the prepared statement, opened, and rows are fetched
using the properly allocated SQLDA structure.