Handling an unknown select list
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.
For more information, see Define an sqlda structure.
- Prepare the SELECT statement (with the PREPARE statement)
to give it a statement identifier.The SELECT statement cannot include an INTO TEMP clause. For more information, see Assemble and prepare the SQL statement.
- Use the DESCRIBE...INTO statement to perform two tasks:
- 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.For more information, see Allocate memory for column 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.For more information, see Assign and obtain values from an sqlda structure.
- Release memory allocated to the sqldata fields and
the sqlda structure.For more information, see Free memory allocated to an 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.