DB2 10.5 for Linux, UNIX, and Windows

Preparing a dynamically executed SQL statement using the minimum SQLDA structure

Use the information provided here as an example of how to allocate the minimum SQLDA structure for a statement.

About this task

You can only allocate a smaller SQLDA structure with programming languages, such as C and C++, that support the dynamic allocation of memory.

Suppose an application declares an SQLDA structure named minsqlda that contains no SQLVAR entries. The SQLN field of the SQLDA describes the number of SQLVAR entries that are allocated. In this case, SQLN must be set to 0. Next, to prepare a statement from the character string dstring and to enter its description into minsqlda, issue the following SQL statement (assuming C syntax, and assuming that minsqlda is declared as a pointer to an SQLDA structure):
   EXEC SQL 
     PREPARE STMT INTO :*minsqlda FROM :dstring;

Suppose that the statement contained in dstring is a SELECT statement that returns 20 columns in each row. After the PREPARE statement (or a DESCRIBE statement), the SQLD field of the SQLDA contains the number of columns of the result table for the prepared SELECT statement.

The SQLVAR entries in the SQLDA are set in the following cases:

The SQLVAR entries in the SQLDA are not set (requiring allocation of additional space and another DESCRIBE) in the following cases:

The SQLWARN option of the BIND command cannot control whether the DESCRIBE (or PREPARE...INTO) will return the following warnings:

It is recommended that your application code always consider that these SQLCODE values could be returned. The warning SQLCODE +238 (SQLSTATE 01005) is always returned when there are LOB columns in the select list and there are insufficient SQLVAR entries in the SQLDA. This is the only way the application can know that the number of SQLVAR entries must be doubled because of a LOB column in the result set.