Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements > CLOSE >

Using End of Transaction to Close a Cursor

The COMMIT WORK and ROLLBACK WORK statements close all cursors except those that are declared with a hold. It is better to close all cursors explicitly, however. For select or function cursors, this action simply makes the intent of the program clear. It also helps to avoid a logic error if the WITH HOLD clause is later added to the declaration of a cursor.

For an insert cursor, it is important to use the CLOSE statement explicitly so that you can test the error code. Following the COMMIT WORK statement, SQLCODE reflects the result of the COMMIT statement, not the result of closing cursors. If you use a COMMIT WORK statement without first using a CLOSE statement, and if an error occurs while the last buffered rows are being written to the database, the transaction is still committed.

For how to use insert cursors and the WITH HOLD clause, see DECLARE .

In an ANSI-compliant database, a cursor cannot be closed implicitly. You must issue a CLOSE statement.

Related Information

Related statements: DECLARE , FETCH , FLUSH , FREE , OPEN , PUT , and SET AUTOFREE

For an introductory discussion of cursors, see the IBM Informix Guide to SQL: Tutorial.

For a more advanced discussion of cursors, see the IBM Informix ESQL/C Programmer's Manual.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]