Preparing the Input XSQLDA
From InterBase
Go Up to Method 4: Query Statements With Parameters
Placeholder parameters are replaced with actual data before a prepared SQL statement string is executed. Because those parameters are unknown when the statement string is created, an input XSQLDA
must be created to supply parameter values 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
calledin_sqlda
:XSQLDA *in_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 forin_slqda
:In this statement, space for tenin_sqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(10));
XSQLVAR
structures is allocated, allowing theXSQLDA
to accommodate up to ten input parameters. Once structures are allocated, assign values to thesqldata
fields. - Set the
version
field of theXSQLDA
toSQLDA_CURRENT_VERSION
, and set thesqln
field of theXSQLDA
to indicate the number ofXSQLVAR
structures allocated:in_sqlda->version = SQLDA_CURRENT_VERSION; in_sqlda->sqln = 10;