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:

  1. Declare a variable to hold the XSQLDA needed to process parameters. For example, the following declaration creates an XSQLDA called in_sqlda:
    XSQLDA *in_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 in_sqlda:
    in_sqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(10));
    
    In this statement space for ten XSQLVAR structures is allocated, allowing the XSQLDA to accommodate up to ten parameters.
  4. Set the version field of the XSQLDA to SQLDA_CURRENT_VERSION, and set the sqln field to indicate the number of XSQLVAR structures allocated:
    in_sqlda->version = SQLDA_CURRENT_VERSION;
    in_sqlda->sqln = 10;
    

Advance To: