Parameter-value array

The parameter-value array, values, is the fifth argument of the mi_exec_prepared_statement() and mi_open_prepared_statement() functions. Each element of the parameter-value array is a pointer to an MI_DATUM structure that holds the value for each input parameter.

The format of this value depends on:
  • Whether the control mode for the input-parameter data is text or binary representation:

    The params_are_binary argument of mi_exec_prepared_statement() or mi_open_prepared_statement() indicates this control mode. For more information about the format of data for different control modes, see Control modes for data.

  • In binary representation, whether the MI_DATUM value is passed by reference or by value:
    • For C UDRs, the data type of the value determines the passing mechanism.
    • For client LIBMI applications, pass all values (regardless of data type) by reference.
For the prepared INSERT statement in Preparing a statement that contains input parameters, the following code fragment assigns values to the input parameters for the customer_num and company columns. These values are in text representation because the params_are_binary argument of mi_exec_prepared_statement() is MI_FALSE.
/* Initialize input parameter for customer_num column */
values[0] = "0"; /* value of '0' for SERIAL customer_num */
lengths[0] = 0; /* SERIAL is built-in type: no length */
types[0] = "serial";
nulls[0] = MI_FALSE;

/* Initialize input parameter for company column */
stcopy("Trievers Inc.", strng);
values[1] = strng;
lengths[1] = stleng(strng); /* CHAR types need length! */
types[1] = "char(20)";
nulls[1] = MI_FALSE;

/* Send INSERT statement to database server for execution along 
 * with the input-parameter-value arrays
 */
mi_exec_prepared_statement(insrt_stdesc, 0, MI_FALSE, 2
   values, lengths, nulls, types, 0, NULL);
Server only:
The following code fragment initializes the input parameters to the same values but it assigns these values in binary representation instead of text representation:
/* Initialize input parameter for customer_num column */
values[0] = 0; /* value of 0 for SERIAL customer_num */
lengths[0] = 0; /* SERIAL is built-in type: no length */
types[0] = "serial";
nulls[0] = MI_FALSE;

/* Initialize input parameter for company column */
values[1] = mi_string_to_lvarchar("Trievers Inc.");
lengths[1] = 0; /* CHAR types need length! */
types[1] = "char(20)";
nulls[1] = MI_FALSE;

/* Send INSERT statement to database server for execution along
 * with the input-parameter-value arrays
 */
mi_exec_prepared_statement(insrt_stdesc, 0, MI_TRUE, 2
   values, lengths, nulls, types, 0, NULL);
In the preceding code fragment, the first element of the values array is assigned an integer value. Because this code executes in a C UDR, the integer value in the MI_DATUM structure of this array must be passed by value.
Client only:

In a client LIBMI application, all values in MI_DATUM structure must be passed by reference. Therefore, to assign values to input parameters within a client LIBMI application, you must assign all values in the values array as pointers to the actual values.

The preceding code fragment assumes that it executes within a C UDR because it passes the value for the first input parameter (an INTEGER column by value). In a client LIBMI application, you cannot use the pass-by-value mechanism. Therefore, the assignment to the first input parameter must pass a pointer to the integer value, as follows:
col1 = 0;
values[0] = &col1;