informix
Informix DataBlade API Programmer's Manual
Executing SQL Statements

Inserting Data Into the Database

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:

  1. Assemble the statement string.
  2. Send the INSERT statement with either mi_exec() or mi_exec_prepared_statement().
  3. Process the results of the completed statement.

Assembling an Insert String

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.

Sending the Insert Statement

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:

Processing Insert Results

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.

Serial Data Type DataBlade API Function
SERIAL mi_last_serial()
SERIAL8 mi_last_serial8()


Informix DataBlade API Programmer's Manual, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved