Handling an unknown column list

You can use an sqlda structure to handle the INSERT...VALUES statement

About this task

For an introduction on how to handle columns in a VALUES clause of an INSERT, see Handling an unknown column list.

To use an sqlda structure to handle input parameters in an INSERT:

Procedure

  1. Declare a variable to hold the address of an sqlda structure.
    For more information, see Define an sqlda structure.
  2. Prepare the INSERT statement (with the PREPARE statement) and give it a statement identifier.
    For more information, see Assemble and prepare the SQL statement.
  3. Use the DESCRIBE...INTO statement to perform two tasks:
    1. Allocate an sqlda structure.
      The address of the allocated structure is stored in the sqlda pointer that you declare. For more information, see Allocate memory for the sqlda structure.
    2. Determine the number and data types of columns in the table with the DESCRIBE...INTO statement.
      The DESCRIBE statement fills an sqlvar_struct structure for each item of the column list. For more information, see Initialize the sqlda structure.
  4. Examine the sqltype and sqllen fields of sqlda for each column to determine the amount of memory that is required to allocate for the data.
    For more information, see Allocate memory for column data.
  5. Save the number of columns stored in the sqld field in a host variable.
  6. Set the columns to their values with C-language statements that set the appropriate sqldata fields in the sqlvar_struct structures of sqlda.
    A column value must be compatible with the data type of its associated column. If you insert a null value, make sure to set the appropriate sqlind field to the address of an indicator variable that contains -1.
  7. Execute the INSERT statement to insert the values into the database.
  8. Release the memory that is allocated to the sqldata fields and the sqlda structure.
    For more information, see ids_esqlc_0656.html#ids_esqlc_0656.