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:

  1. Declare a variable to hold the XSQLDA needed to process parameters. For example, the following declaration creates an XSQLDA called ­out_sqlda:
    XSQLDA *out_sqlda;
  2. Optionally declare a variable for accessing the XSQLVAR structure of the XSQLDA:
    XSQLVAR *var;
    Declaring a pointer to the XSQLVAR structure is not necessary, but can simplify referencing the structure in subsequent statements.
  3. Allocate memory for the XSQLDA using the XSQLDA_LENGTH macro. The following statement allocates storage for out_sqlda:
    out_sqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(10));
    Space for ten XSQLVAR structures is allocated in this statement, enabling the XSQLDA to accommodate up to ten select-list items.
  4. Set the version field of the XSQLDA to SQLDA_CURRENT_VERSION, and set the sqln field of the XSQLDA to indicate the number of XSQLVAR structures allocated:
    out_sqlda->version = SQLDA_CURRENT_VERSION;
    out_sqlda->sqln = 10;

Advance To: