Preparing the Output XSQLDA to Query Statements with Parameters
From InterBase
Go Up to Method 4: Query Statements With Parameters
Most queries return one or more rows of data, referred to as a select-list. Because the number and kind of items returned are unknown when a statement string is executed, an output XSQLDA
must be created to store select-list items that are returned at runtime. To prepare the XSQLDA
, follow these steps:
- Declare a variable to hold the
XSQLDA
needed to process parameters. For example, the following declaration creates anXSQLDA
calledout_sqlda
:XSQLDA *out_sqlda;
- Optionally declare a variable for accessing the
XSQLVAR
structure of theXSQLDA
:Declaring a pointer to theXSQLVAR *var;
XSQLVAR
structure is not necessary, but can simplify referencing the structure in subsequent statements. - Allocate memory for the
XSQLDA
using theXSQLDA_LENGTH
macro. The following statement allocates storage forout_sqlda
:Space for tenout_sqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(10));
XSQLVAR
structures is allocated in this statement, enabling theXSQLDA
to accommodate up to ten select-list items. - Set the
version
field of theXSQLDA
toSQLDA_CURRENT_VERSION
, and set thesqln
field of theXSQLDA
to indicate the number ofXSQLVAR
structures allocated:out_sqlda->version = SQLDA_CURRENT_VERSION; out_sqlda->sqln = 10;