Assign values to input parameters

For a parameterized SQL statement, your DataBlade® API module must perform the following steps:
  1. Specify input parameters in the text of the SQL statement.
  2. Send the SQL statement to the database server for parsing.
  3. Provide input-parameter values when the SQL statement executes.

The mi_prepare() statement performs these first two steps for a parameterized statement.

The mi_exec_prepared_statement() and mi_open_prepared_statement() functions assign values to input parameters when they send a parameterized SQL to the database server for execution. To provide a value for an input parameter, you pass information in several parallel arrays:
  • Parameter-value array
  • Parameter-value type array
  • Parameter-value length array
  • Parameter-value null array
These input-parameter value arrays are similar to the input-parameter arrays in the statement descriptor (see Input-parameter arrays in the statement descriptor ). They have an element for each input parameter in the prepared statement. However, they are unlike the input-parameter arrays in the statement descriptor in the following ways:
  • An input-parameter value array describes the actual value for an input parameter.

    An input-parameter array describes the column with which the input parameter is associated.

  • You must allocate and manage an input-parameter value array.

    The DataBlade API does not provide accessor functions for input-parameter value arrays. For each input parameter, your DataBlade API module must declare, allocate, and assign a value to the array.

All of the input-parameter-value arrays have zero-based indexes. The following figure shows how the information at index position 1 of these arrays holds the input-parameter-value information for the second input parameter of a prepared statement.
Figure 1: Arrays for initialization of input parameters

begin figure description - This figure is described in the surrounding text. - end figure description

You specify the number of input-parameter values in the input-parameter value arrays with the nparams argument of mi_exec_prepared_statement() or mi_open_prepared_statement().