DB->exists()
Prev | Chapter 2. The DB Handle | Next

## DB->exists()

    #include <db.h>

    int
    DB->exists(DB *db, DB_TXN *txnid, DBT *key, u_int32_t flags);

The `DB->exists()` method returns whether the specified key appears in the database.

The `DB->exists()` method will return DB_NOTFOUND if the specified key is not in the database. The `DB->exists()` method will return DB_KEYEMPTY if the database is a Queue or Recno database and the specified key exists, but was never explicitly created by the application or was later deleted.

### Parameters

#### flags

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

- `DB_READ_COMMITTED`

  Configure a transactional read operation to have degree 2 isolation (the read is not repeatable).

- `DB_READ_UNCOMMITTED`

  Configure a transactional read operation to have degree 1 isolation, reading modified but not yet committed data. Silently ignored if the DB_READ_UNCOMMITTED flag was not specified when the underlying database was opened.

- `DB_RMW`

  Acquire write locks instead of read locks when doing the read, if locking is configured. Setting this flag can eliminate deadlock during a read-modify-write cycle by acquiring the write lock during the read part of the cycle so that another thread of control acquiring a read lock for the same item, in its own read-modify-write cycle, will not result in deadlock.

  Because the `DB->exists()` method will not hold locks across Berkeley DB calls in non-transactional operations, the DB_RMW flag to the `DB->exists()` call is meaningful only in the presence of transactions.

#### key

The key DBT operated on.

#### txnid

If the operation is part of an application-specified transaction, the txnid parameter is a transaction handle returned from DB_ENV->txn_begin(); if the operation is part of a Berkeley DB Concurrent Data Store group, the txnid parameter is a handle returned from DB_ENV->cdsgroup_begin(); otherwise NULL. If no transaction handle is specified, but the operation occurs in a transactional database, the operation will be implicitly transaction protected.

### Class

DB

### See Also

Database and Related Methods

Prev | Up | Next
DB->err() | Home | DB->fd()