|
To insert a row of data into a database, you must execute the INSERT statement. Take the following steps to send an INSERT statement to the database server for execution:
Assemble a statement string for the INSERT statement you want to execute. If you know the values you want to insert into the columns, you can create a basic SQL statement; that is, one that you can execute with mi_exec(). If you do not know the column values, use input parameters in the statement string in place of the column values in the VALUES clause. You must prepare any parameterized INSERT statement with a call to mi_prepare(). Figure 8-6 on page 8-18 shows a statement string for an INSERT that contains input parameters.
The choice of DataBlade API statement-execution function for an INSERT statement depends on whether the statement string was prepared with mi_prepare(), as follows:
After the database server executes an INSERT statement, the mi_get_result() function returns a MI_DML statement status. You can obtain the following information about the statement:
The SERIAL and SERIAL8 data types allow you to have an integer column for which the database server automatically increments the value with each insert. You can obtain the newly inserted serial value for the most recent INSERT statement with the following DataBlade API functions.