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
- Declare a variable to hold the address of an sqlda structure.
For more information, see Define an sqlda structure.
- Prepare the INSERT statement (with the PREPARE statement)
and give it a statement identifier.For more information, see Assemble and prepare the SQL statement.
- Use the DESCRIBE...INTO statement to perform two tasks:
- 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.
- Save the number of columns stored in the sqld field in a host variable.
- 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
. - Execute the INSERT statement to insert the values into the database.
- Release the memory that is allocated to the sqldata fields
and the sqlda structure.For more information, see Free memory allocated to an sqlda structure.