Creating the Input XSQLDA (Embedded SQL Guide)
Go Up to Method 2: Non-query Statements with Parameters (Embedded SQL Guide)
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
XSQLDAneeded to process parameters. For example, the following declaration creates anXSQLDAcalledin_sqlda:XSQLDA *in_sqlda;
- Optionally declare a variable for accessing the
XSQLVARstructure of theXSQLDA:XSQLVAR *var;
Declaring a pointer to theXSQLVARstructure is not necessary, but can simplify referencing the structure in subsequent statements. - Allocate memory for the
XSQLDAusing theXSQLDA_LENGTHmacro. The following statement allocates storage forin_sqlda:in_sqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(10));
In this statement space for 10XSQLVARstructures is allocated, allowing the XSQLDA to accommodate up to 10 parameters. - Set the
versionfield of theXSQLDAtoSQLDA_CURRENT_VERSION, and set thesqlnfield to indicate the number ofXSQLVARstructures allocated:in_sqlda_version = SQLDA_CURRENT_VERSION; in_sqlda->sqln = 10;