About this task
For an introduction on how to handle unknown columns in
an unknown select list, see Handling an unknown select list. This section describes
how to use an sqlda structure to handle a SELECT statement.
To
use an sqlda structure to handle unknown select-list columns:
Procedure
- Declare a variable to hold the address of an sqlda structure.
- Prepare the SELECT statement (with the PREPARE statement)
to give it a statement identifier.
- Use the DESCRIBE...INTO statement to perform two tasks:
- Allocate an sqlda structure.
- Determine the number and data types of select-list columns.
- Examine the sqltype and sqllen fields of sqlda for
each select-list column to determine the amount of memory that is
required to allocate for the data.
- Save the number of select-list columns stored in the sqld field
in a host variable.
- Declare and open a cursor and then use the FETCH...USING
DESCRIPTOR statement to fetch column values, one row at a time, into
an allocated sqlda structure.
- Retrieve the row data from the sqlda structure into
host variables with C-language statements that access the sqldata field
for each select-list column.
- Release memory allocated to the sqldata fields and
the sqlda structure.
Results
Important: If the SELECT statement has input parameters
of an unknown number and type in the WHERE clause, your program must
also handle these input parameters with an sqlda structure.
For
more information, see Handling a parameterized SELECT statement.