DB2 10.5 for Linux, UNIX, and Windows

Allocating an SQLDA structure with sufficient SQLVAR entries for dynamically executed SQL statements

After you determine the number of columns in the result table, you must allocate storage for a second full-size SQLDA. The first SQLDA is used for input parameters and the second full-size SQLDA is used for output parameters.

About this task

Assume that the result table contains 20 columns (none of which are LOB columns). In this situation, you must allocate a second SQLDA structure, fulsqlda with at least 20 SQLVAR elements (or 40 elements if the result table contains any LOBs or distinct types). For the rest of this example, assume that no LOBs or distinct types are in the result table.

When you calculate the storage requirements for SQLDA structures, include the following items:

Procedure

What to do next

The number of SQLVAR entries needed for fulsqlda is specified in the SQLD field of minsqlda. Assume this value is 20. Therefore, the storage allocation required for fulsqlda is:

     16 + (20 * sizeof(struct sqlvar))

This value represents the size of the header plus 20 times the size of each SQLVAR entry, giving a total of 896 bytes.

You can use the SQLDASIZE macro to avoid doing your own calculations and to avoid any version-specific dependencies.