You can use an sqlda structure to handle the INSERT...VALUES
statement
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:
- 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:
- 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.
- 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.
- 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.