Previous Topic

Next Topic

Cursor Updates

Unless the cursor is explicitly opened in readonly mode or if table level lock granularity is in effect or if the transaction isolation level is read uncommitted, an update mode lock is obtained at the row or page level granularity, as appropriate. The granularity of locking used depends on many factors, including the effects of several set options, the estimated selectivity of the select criteria, various lock configuration parameters, and the page size used by the table. For a complete explanation, see "Understanding the Locking System" in the Database Administrator Guide.

If an update is performed, this lock is converted to an exclusive lock. If the cursor moves off the page or row without performing an update, the lock is converted to share mode if the isolation level is repeatable read or serializable, or the lock is released if the isolation level is read committed.

If the isolation level is read uncommitted, updates are implicitly forbidden, and no logical locks are taken on the table.

If isolation level is not read, uncommitted and table level lock granularity is used and the cursor was not opened in readonly, a single exclusive lock at the table level is taken.

If updates are not to be performed with the cursor, cursor performance can be improved by specifying for readonly when the cursor is opened.

For details, see Open. (If the select statement of the cursor contains one or more aggregate functions, the cursor is read-only.)

For details about updating or deleting table rows using a cursor, see Update and Delete.

A cursor cannot be declared for update if its select statement refers to more than one table.

For example, the following cursor declaration causes a compile-time error:

/* illegal join on different tables for update */
exec sql declare c1 cursor for
       select employee.id, accounts.sal
       from employee, accounts
       where employee.salno = accounts.accno
       for update of sal;

This declaration is illegal because two tables were used in the select statement.

For example, if empdept is a read-only view, the following example generates a runtime error when the open statement is executed. No preprocessor error is generated, because the preprocessor does not know that empdept is a view.

/* empdept is a read-only view */
exec sql declare c2 cursor for
       select name, deptinfo
       from empdept
       for update of deptinfo;

exec sql open c2;

For example, the following cursor declaration causes an error when attempting to update the column named constant:

/* "constant" cannot be declared for update */
exec sql declare c3 cursor for
       select constant = 123, ename
       from employee
       for update of constant;

If an updateable column has been assigned a result column name using the syntax:

result_name = column_name

or:

column_name as result_name

The column referred to in the for update list must see the table column name, and not the result column name.

Previous Topic

Next Topic

Cursor Modes

There are two update modes for cursors: deferred and direct.

Note: The default cursor mode is specified at the time the DBMS Server is started. For compliance with the ANSI/ISO SQL-92 standard, the default cursor mode must be direct mode.


© 2007 Ingres Corporation. All rights reserved.