Allocate memory for the sqlda structure
After you define a host variable as a pointer to an sqlda structure,
you must ensure that memory is allocated for all parts of this structure,
as follows:
- To allocate memory for the sqlda structure itself, use
the DESCRIBE...INTO statement. The following DESCRIBE statement obtains information about the prepared statement st_id, allocates memory for an sqlda structure, and puts the address of the sqlda structure in the pointer da_ptr:
EXEC SQL describe st_id into da_ptr;
- To allocate memory for the sqlvar_struct structures, take
the following actions:
- If the prepared statement is a SELECT (with no INTO TEMP clause), INSERT, or EXECUTE FUNCTION statement, the DESCRIBE...INTO statement can allocate space for sqlvar_struct structures.
- If some other SQL statement was prepared and you need to send or receive columns in the database server, your program must allocate space for the sqlvar_struct structures.
- To allocate memory for the data of the sqldata fields, make sure that you align the data types with proper word boundaries.
If you use the sqlda structure to define input parameters, you cannot use a DESCRIBE statement. Therefore, your program must explicitly allocate memory for both the sqlda structure and the sqlvar_struct structures.