Creating the Input XSQLDA
From InterBase
Go Up to Method 2: Non-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 execute time. 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_sqlda
:In this statement space for tenin_sqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(10));
XSQLVAR
structures is allocated, allowing theXSQLDA
to accommodate up to ten parameters. - Set the
version
field of theXSQLDA
toSQLDA_CURRENT_VERSION
, and set thesqln
field to indicate the number ofXSQLVAR
structures allocated:in_sqlda->version = SQLDA_CURRENT_VERSION; in_sqlda->sqln = 10;