DB->cursor()
Prev | Chapter 3. The DBcursor Handle | Next

## DB->cursor()

    #include <db.h>

    int
    DB->cursor(DB *db, DB_TXN *txnid, DBC **cursorp, u_int32_t flags);

The `DB->cursor()` method returns a created database cursor.

Cursors may span threads, but only serially, that is, the application must serialize access to the cursor handle.

The `DB->cursor()` method returns a non-zero error value on failure and 0 on success.

### Parameters

#### cursorp

The cursorp parameter references memory into which a pointer to the allocated cursor is copied.

#### flags

The flags parameter must be set to 0 or by bitwise inclusively OR'ing together one or more of the following values:

- `DB_BULK`

  Configure a cursor to optimize for bulk operations. Each successive operation on a cursor configured with this flag attempts to continue on the same database page as the previous operation, falling back to a search if a different page is required. This avoids searching if there is a high degree of locality between cursor operations. This flag is currently only effective with the btree access method: for other access methods it is ignored.

- `DB_READ_COMMITTED`

  Configure a transactional cursor to have degree 2 isolation. This ensures the stability of the current data item read by this cursor but permits data read by this cursor to be modified or deleted prior to the commit of the transaction for this cursor.

- `DB_READ_UNCOMMITTED`

  Configure a transactional cursor to have degree 1 isolation. Read operations performed by the cursor may return modified but not yet committed data. Silently ignored if the DB_READ_UNCOMMITTED flag was not specified when the underlying database was opened.

- `DB_WRITECURSOR`

  Specify that the cursor will be used to update the database. The underlying database environment must have been opened using the DB_INIT_CDB flag.

- `DB_TXN_SNAPSHOT`

  Configure a transactional cursor to operate with read-only snapshot isolation. For databases with the DB_MULTIVERSION flag set, data values will be read as they are when the cursor is opened, without taking read locks.

  This flag implicitly begins a transaction that is committed when the cursor is closed.

  This flag is silently ignored if DB_MULTIVERSION is not set on the underlying database or if a transaction is supplied in the txnid parameter.

#### txnid

To transaction-protect cursor operations, cursors must be opened and closed within the context of a transaction. The txnid parameter specifies the transaction context in which the cursor may be used.

Cursor operations are not automatically transaction-protected, even if the DB_AUTO_COMMIT flag is specified to the DB_ENV->set_flags() or DB->open() methods. If cursor operations are to be transaction-protected, the txnid parameter must be a transaction handle returned from DB_ENV->txn_begin(); otherwise, NULL.

### Errors

The `DB->cursor()` method may fail and return one of the following non-zero errors:

#### DB_REP_HANDLE_DEAD

When a client synchronizes with the master, it is possible for committed transactions to be rolled back. This invalidates all the database and cursor handles opened in the replication environment. Once this occurs, an attempt to use such a handle will return `DB_REP_HANDLE_DEAD`. The application will need to discard the handle and open a new one in order to continue processing.

#### DB_REP_LOCKOUT

The operation was blocked by client/master synchronization.

#### EINVAL

An invalid flag value or parameter was specified.

### Class

DB

### See Also

Database Cursors and Related Methods

Prev | Up | Next
Chapter 3. The DBcursor Handle | Home | DBcursor->close()