FLUSH statement

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


1 cursor_id
1 cursor_id_var
Element Description Restrictions Syntax
cursor_id Name of a cursor Must have been declared Identifier
cursor_id_var Host variable that holds the value of cursor_id Must be a character data type Language specific


Use this statement, which is an extension to the ANSI/ISO standard for SQL, with .

The PUT statement adds a row to a buffer, whose content is written to the database when the buffer 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 that operates on a cursor called icurs:
FLUSH icurs 


The following example assumes that a function named next_cust returns either information about a new customer or null data to signal the end of input:
EXEC SQL OPEN new_custs; 

while(SQLCODE == 0) 
	if(the_company == NULL) 

	EXEC SQL PUT new_custs; 

if(SQLCODE == 0) 	/* if no problem with PUT */ 
	EXEC SQL FLUSH new_custs; 
	/* write any rows left */ 
	if(SQLCODE == 0) 	/* if no problem with FLUSH */ 
		EXEC SQL COMMIT WORK; 	/* commit changes */ 
	EXEC SQL ROLLBACK WORK; /* else undo changes */
The code in this example calls next_cust repeatedly. When it returns non-null data, the PUT statement sends the returned data to the row buffer. When the buffer fills, the rows it contains are automatically sent to the database server. The loop normally ends when next_cust has no more data to return.