FLUSH statement

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

Syntax


1  FLUSH
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

Usage

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 

Example

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 BEGIN WORK; 
EXEC SQL OPEN new_custs; 

while(SQLCODE == 0) 
{ 
	next_cust(); 
	if(the_company == NULL) 
		break; 

	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 */ 
} 
else 
	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.