Deallocating cursor function with Client-Library

Application programs use and reuse connections that have been allocated for them via the XA Interface. Sybase’s implementation of cursors starting with SQL Server version 10.1 requires cursor structures on both the client (TM/RM program) side and the Adaptive Server side.

When a client explicitly deallocates a cursor, or when the client connection is closed, Adaptive Server deallocates the server cursor structures.

When the first iteration of a program opens or closes a cursor but the connection stays allocated (as it does with XA-Library), the second iteration of the same program fails, as it attempts to open the same cursor name. Adaptive Server informs us that it already has a cursor by this name at the same nesting level.

The application program must explicitly close and deallocate the cursor before it commits or aborts its transaction. This must be done in the transaction program that allocates the cursor. Embedded SQL records information about cursors which allows the XA Interface to perform the deallocation.

With Client-Library, you must handle error paths so that cursors are deallocated before a TM abort code is called. That is, if the open cursor works, deallocate it.

Use ct_cursor( ) with type CS_CURSOR_CLOSE and option CS_DEALLOC.