Db::open |
#include <db_cxx.h>int Db::open(DbTxn *txnid, const char *file, const char *database, DBTYPE type, u_int32_t flags, int mode);
int Db::get_dbname(const char **filenamep, const char **dbnamep);
int Db::get_open_flags(u_int32_t *flagsp);
int Db::get_transactional()
The Db::open method opens the database represented by the file and database parameters for both reading and writing.
The currently supported Berkeley DB file formats (or access methods) are Btree, Hash, Queue, and Recno. The Btree format is a representation of a sorted, balanced tree structure. The Hash format is an extensible, dynamic hashing scheme. The Queue format supports fast access to fixed-length records accessed sequentially or by logical record number. The Recno format supports fixed- or variable-length records, accessed sequentially or by logical record number, and optionally backed by a flat text file.
Storage and retrieval for the Berkeley DB access methods are based on key/data pairs; see Dbt for more information.
Calling Db::open is a relatively expensive operation, and maintaining a set of open databases will normally be preferable to repeatedly opening and closing the database for each new query.
The Db::open 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. If Db::open fails, the Db::close method should be called to discard the Db handle.
In-memory databases never intended to be preserved on disk may be created by setting both the file and database parameters to NULL. Note that in-memory databases can only ever be shared by sharing the single database handle that created them, in circumstances where doing so is safe.
In-memory databases never intended to be preserved on disk may be created by setting both the file and database parameters to NULL. Note that in-memory databases can only ever be shared by sharing the single database handle that created them, in circumstances where doing so is safe.
On Windows, the file argument will be interpreted as a UTF-8 string, which is equivalent to ASCII for Latin characters.
The DB_TRUNCATE flag cannot be lock or transaction-protected, and it is an error to specify it in a locking or transaction-protected environment.
On UNIX systems or in IEEE/ANSI Std 1003.1 (POSIX) environments, files created by the database open are created with mode mode (as described in chmod(2)) and modified by the process' umask value at the time of creation (see umask(2)). Created files are owned by the process owner; the group ownership of created files is based on the system and directory defaults, and is not further specified by Berkeley DB. System shared memory segments created by the database open are created with mode mode, unmodified by the process' umask value. If mode is 0, the database open will use a default mode of readable and writable by both owner and group.
If the database was opened within a database environment, the environment variable DB_HOME may be used as the path of the database environment home.
Db::open is affected by any database directory specified using the DbEnv::set_data_dir method, or by setting the "set_data_dir" string in the environment's DB_CONFIG file.
The Db::open method may fail and throw DbException, encapsulating one of the following non-zero errors, or return one of the following non-zero errors:
If a transactional database environment operation was selected to resolve a deadlock, the Db::open method will fail and either return DB_LOCK_DEADLOCK or throw a DbDeadlockException exception.
If a Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable to grant a lock in the allowed time, the Db::open method will fail and either return DB_LOCK_NOTGRANTED or throw a DbLockNotGrantedException exception.
The Db::get_database method returns the current filename and database name.
The Db::get_database method may be called at any time during the life of the application.
The Db::get_database 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.
The Db::get_open_flags method returns the current open method flags.
The Db::get_open_flags method may not be called before the Db::open method has been called.
The Db::get_open_flags 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.
The Db::get_transactional method returns non-zero if the Db handle has been opened in a transactional mode.
The Db::get_transactional method may be called at any time during the life of the application.
Copyright (c) 1996-2004 Sleepycat Software, Inc. - All rights reserved.