2. Embedded SQL for C : Dynamic Programming for C : How to Declare an SQLDA Variable : Static Declaration of an SQLDA
 
Share this page                  
Static Declaration of an SQLDA
As previously mentioned, you can statically declare an SQLDA as well as dynamically allocate one. The C file that is included when issuing the include sqlda statement specifies some C macros that help a program tailor the size of the statically declared SQLDA. In fact, the IISQLDA type definition is derived from that macro.
If a program requires a statically declared SQLDA with the same number of variables as the IISQLDA type, then it can use code like the following:
exec sql include sqlda;
 
IISQLDA _sqlda;
 IISQLDA *sqlda = &_sqlda;
 
sqlda->sqln = IISQ_MAX_COLS; /* Set the size */
...
 
exec sql describe s1 into :sqlda;
Even though a pointer to an SQLDA is required when describing or executing a statement, it is also acceptable to use the syntax:
exec sql describe s1 into :&_sqlda;
You must confirm that the SQLDA object being used is a pointer to a valid SQLDA.
If a program requires a statically declared SQLDA with a different number of variables (not IISQ_MAX_COLS), it can use the macro IISQLDA_TYPE. This macro is described in more detail in the eqsqlda.h include file that is generated by include sqlda. (If you are not familiar with C macros then skip the following discussion). The syntax of IISQLDA_TYPE is:
IISQLDA_TYPE(tag_name, sqlda_name, number_of_sqlvars);
IISQLDA_TYPE is a macro that declares object sqlda_name (a type definition or a variable) of an SQLDA-like structure with tag tag_name, and with num_of_sqlvars SQLDA variables. For example, the following declaration declares a local SQLDA, called sqlda10 with 10 variables. The variable sqlda10 is not a pointer.
IISQLDA_TYPE(da10_, sqlda10, 10);
The following example declares a static SQLDA with 32 variables, and a pointer to the SQLDA.
Example: Static declaration of an SQLDA
static IISQLDA_TYPE(da32_, sqlda32, 32);
 struct da32_ *da32_ptr = &sqlda32;