informix
Informix Guide to SQL: Syntax
SQL Statements

FLUSH

Use the FLUSH statement to force rows that a PUT statement buffered to be written to the database.

Use this statement with ESQL/C.

Syntax

Element Purpose Restrictions Syntax
cursor_id Name of a cursor A DECLARE statement must have previously created the cursor. Identifier, p. 4-205
cursor_id_var Host variable that holds the value of cursor_id Host variable must be a character data type. A DECLARE statement must have previously created the cursor. Name must conform to language-specific rules for variable names.

Usage

The PUT statement adds a row to a buffer, and the buffer is written to the database when it is full. Use the FLUSH statement to force the insertion when the buffer is not full.

If the program terminates without closing the cursor, the buffer is left unflushed. Rows placed into the buffer since the last flush are lost. Do not expect the end of the program to close the cursor and flush the buffer automatically.

The following example shows a FLUSH statement:

Error Checking FLUSH Statements

The sqlca structure contains information on the success of each FLUSH statement and the number of rows that are inserted successfully. The result of each FLUSH statement is contained in the fields of the sqlca: sqlca.sqlcode, SQLCODE and sqlca.sqlerrd[2].

When you use data buffering with an insert cursor, you do not discover errors until the buffer is flushed. For example, an input value that is incompatible with the data type of the column for which it is intended is discovered only when the buffer is flushed. When an error is discovered, rows in the buffer that are located after the error are not inserted; they are lost from memory.

The SQLCODE field is set either to an error code or to zero (0) if no error occurs. The third element of the sqlerrd array is set to the number of rows that are successfully inserted into the database:

Counting Total and Pending Rows

To count the number of rows actually inserted into the database as well as the number not yet inserted, perform the following steps:

  1. Prepare two integer variables, for example, total and pending.
  2. When the cursor opens, set both variables to 0.
  3. Each time a PUT statement executes, increment both total and pending.
  4. Whenever a FLUSH statement executes or the cursor is closed, subtract the third field of the SQLERRD array from pending.

Related Information

Related statements: CLOSE, DECLARE, OPEN, and PREPARE

For a task-oriented discussion of FLUSH, see the Informix Guide to SQL: Tutorial.

For information about the sqlca structure, see the Informix ESQL/C Programmer's Manual.


Informix Guide to SQL: Syntax, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved