Db

#include <db_cxx.h>

class Db { 
public: 
        Db(DbEnv *dbenv, u_int32_t flags); 
        ~Db();

         DB *Db::get_DB(); 
         const DB *Db::get_const_DB() const; 
         static Db *Db::get_Db(DB *db); 
         static const Db *Db::get_const_Db(const DB *db); 
         ... 
}; 

The Db handle is the handle for a Berkeley DB database, which may or may not be part of a database environment.

Db handles are free-threaded if the DB_THREAD flag is specified to the Db::open() method when the database is opened or if the database environment in which the database is opened is free-threaded. The handle should not be closed while any other handle that refers to the database is in use; for example, database handles must not be closed while cursor handles into the database remain open, or transactions that include operations on the database have not yet been committed or aborted. Once the Db::close(), Db::remove(), Db::rename(), or Db::verify() methods are called, the handle may not be accessed again, regardless of the method's return.

The constructor creates a Db object that is the handle for a Berkeley DB database. The constructor allocates memory internally; calling the Db::close(), Db::remove(), or Db::rename() methods will free that memory.

Note that destroying the Db object is synonomous with calling Db::close(0).

Each Db object has an associated DB struct, which is used by the underlying implementation of Berkeley DB and its C-language API. The Db::get_DB() method returns a pointer to this struct. Given a const Db object, Db::get_const_DB() returns a const pointer to the same struct.

Given a DB struct, the Db::get_Db() method returns the corresponding Db object, if there is one. If the DB object was not associated with a Db (that is, it was not returned from a call to the Db::get_DB() method), then the result of Db::get_Db() is undefined. Given a const DB struct, Db::get_const_Db() returns the associated const Dbobject, if there is one.

These methods may be useful for Berkeley DB applications including both C and C++ language software. It should not be necessary to use these calls in a purely C++ application.

Parameters

dbenv

If no dbenv value is specified, the database is standalone; that is, it is not part of any Berkeley DB environment.

If a dbenv value is specified, the database is created within the specified Berkeley DB environment. The database access methods automatically make calls to the other subsystems in Berkeley DB, based on the enclosing environment. For example, if the environment has been configured to use locking, the access methods will automatically acquire the correct locks when reading and writing pages of the database.

flags

The flags parameter is currently unused, and must be set to 0.

  • DB_CXX_NO_EXCEPTION

    The Berkeley DB C++ API supports two different error behaviors. By default, whenever an error occurs, an exception is thrown that encapsulates the error information. This generally allows for cleaner logic for transaction processing because a try block can surround a single transaction. However, if this flag is specified, exceptions are not thrown; instead, each individual function returns an error code.

    If a dbenv value is specified, this flag is ignored, and the error behavior of the specified environment is used instead.

Class

Db

See Also

Database and Related Methods