Cursor commands

Cursor commands, which are available only with Open Client CT-Library System 10 or later, allow an application to retrieve and change data in a flexible way. For example, you can use cursor commands to process multiple result sets that are simultaneously available to the application, instead of one at a time using the language command.

Cursor commands require you to specify a SQL select statement that goes through SQL transformation, as follows:

  1. The client application declares and opens the cursor command through the CT-Library routine ct_cursor.

  2. When the cursor opens, a set of rows on the target is qualified. At that point, the select, update, or delete statement can initiate the following SQL statements to operate on specific rows in the set:

    • fetch

    • update

    • delete

NoteThe DB2 access service does not accept language event-based cursor commands. You must use ct_cursor commands.

DB-Library also supports a form of cursors but somewhat differently, as shown in Table 6-2.

Table 6-2: Comparison of DB-Library and CT-Library cursors

Characteristic

DB-Library-based cursor

CT-Library-based cursor

Relationship to Sybase SQL cursor

Called an “emulated” or “client-side” cursor, does not correspond to a SQL cursor.

Called a “native” or “server-side” cursor, corresponds to an actual SQL cursor.

Cursor row position

Defined by the client.

Defined by the server.

Fetch capability

Can fetch backward.

Can fetch forward only.

Memory requirements

More is required if querying large row sizes, unless a smaller number of rows in the buffer is specified.

No additional memory is required, regardless of the row sizes.

Access to Open Server application

Not available, unless required DB-Library stored procedures are installed.

Any System 10 or later Open Server application is coded to support cursors.

The DB2 access service supports CT-Library-based cursors by mapping the corresponding Open Server commands to DB2 capabilities. Because DB2 cursors do not provide all the capabilities of Open Server cursors, some limitations apply and are included in the following section.

For more information about DB2 capabilities related to commit and rollback statements, see the IBM DB2 SQL Reference manual.