Db::exists()

#include <db_cxx.h>
 
int
Db::exists(DbTxn *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 DbEnv::txn_begin(); if the operation is part of a Berkeley DB Concurrent Data Store group, the txnid parameter is a handle returned from DbEnv::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