Using sqlda Structures
You can use a pointer to an sqlda structure to stores output values when you do not know the number of values or their data types that a SELECT or EXECUTE FUNCTION (or EXECUTE PROCEDURE) statement returns.
This structure contains data descriptors that specify the data
type and memory location for one selected value. The keywords USING
DESCRIPTOR introduce the name of the pointer to the sqlda structure.
Tip: If you know the number and data
types of all values in the select list, you can use an INTO clause
in the FETCH statement. For more information, see When the INTO Clause of FETCH is Required.
To specify an sqlda structure as the location of parameters:
- Declare an sqlda pointer variable.
- Use the DESCRIBE statement to fill in the sqlda structure.
- Allocate memory to hold the data values.
- Use the USING DESCRIPTOR clause of FETCH to specify the sqlda structure as the location into which you fetch the returned values.
The following example shows a FETCH USING DESCRIPTOR statement:
struct sqlda *sqlda_ptr; ... EXEC SQL declare selcurs2 cursor for select * from customer where state = 'CA'; EXEC SQL describe selcurs2 into sqlda_ptr; ... EXEC SQL open selcurs2; while (1) { EXEC SQL fetch selcurs2 using descriptor sqlda_ptr; ...
The sqld value specifies the number of output values that are described in occurrences of the sqlvar structures of the sqlda structure. This number must correspond to the number of values returned from the prepared statement.