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
XSQLDAneeded to process parameters. For example, the following declaration creates anXSQLDAcalledout_sqlda:XSQLDA *out_sqlda;
- Optionally declare a variable for accessing the
XSQLVARstructure of theXSQLDA:Declaring a pointer to theXSQLVAR *var;
XSQLVARstructure is not necessary, but can simplify referencing the structure in subsequent statements. - Allocate memory for the
XSQLDAusing theXSQLDA_LENGTHmacro. The following statement allocates storage forout_sqlda:Space for tenout_sqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(10));
XSQLVARstructures is allocated in this statement, enabling theXSQLDAto accommodate up to ten select-list items. - Set the
versionfield of theXSQLDAtoSQLDA_CURRENT_VERSION, and set thesqlnfield of theXSQLDAto indicate the number ofXSQLVARstructures allocated:out_sqlda->version = SQLDA_CURRENT_VERSION; out_sqlda->sqln = 10;