Library Version 12.1.6.0

Dbc::dup()
Prev | Chapter 3. The Dbc Handle | Next

## Dbc::dup()

    #include <db_cxx.h>

    int
    Dbc::dup(Dbc **cursorp, u_int32_t flags);

The `Dbc::dup()` method creates a new cursor that uses the same transaction and locker ID as the original cursor. This is useful when an application is using locking and requires two or more cursors in the same thread of control.

The `Dbc::dup()` method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success.

### Parameters

#### cursorp

The `Dbc::dup()` method returns the newly created cursor in cursorp.

#### flags

The flags parameter must be set to 0 or the following flag:

- `DB_POSITION`

  The newly created cursor is initialized to refer to the same position in the database as the original cursor (if any) and hold the same locks (if any). If the DB_POSITION flag is not specified, or the original cursor does not hold a database position and locks, the created cursor is uninitialized and will behave like a cursor newly created using the Db::cursor() method.

### Errors

The `Dbc::dup()` method may fail and throw a DbException exception, encapsulating one of the following non-zero errors, or return one of the following non-zero errors:

#### DbRepHandleDeadException or 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 throw a DbRepHandleDeadException (if your application is configured to throw exceptions), or return `DB_REP_HANDLE_DEAD`. The application will need to discard the handle and open a new one in order to continue processing.

#### DbDeadlockException or DB_REP_LOCKOUT

The operation was blocked by client/master synchronization.

DbDeadlockException is thrown if your Berkeley DB API is configured to throw exceptions. Otherwise, `DB_REP_LOCKOUT` is returned.

#### EINVAL

An invalid flag value or parameter was specified.

### Class

Dbc

### See Also

Database Cursors and Related Methods

Prev | Up | Next
Dbc::del() | Home | Dbc::get()