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.
- Prepare the INSERT statement (with the PREPARE statement)
and give it a statement identifier.
- Use the DESCRIBE...INTO statement to perform two tasks:
- Allocate an sqlda structure.
- Determine the number and data types of columns in the
table with the DESCRIBE...INTO statement.
- 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.
- 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.