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_multiple()
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 must be called to discard the Db handle.
ParametersIn-memory databases never intended to be preserved on disk may be created by setting the file parameter to NULL. If the database parameter is also NULL, the database is strictly temporary and cannot be opened by any other thread of control, thus the database can only be accessed by sharing the single database handle that created it, in circumstances where doing so is safe. If the database parameter is not set to NULL, the database can be opened by other threads of control and will be replicated to client sites in any replication group.
In-memory databases never intended to be preserved on disk may be created by setting the file parameter to NULL.
When using a Unicode build on Windows (the default), the file argument will be interpreted as a UTF-8 string, which is equivalent to ASCII for Latin characters.
flagsThe 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_dbname method returns the current filename and database name.
ParametersThe Db::get_dbname method may be called at any time during the life of the application.
The Db::get_dbname 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_multiple method returns non-zero if the Db handle references a physical file supporting multiple databases.
In this case, the Db handle is a handle on a database whose key values are the names of the databases stored in the physical file and whose data values are opaque objects. No keys or data values may be modified or stored using the database handle.
The Db::get_multiple method may not be called before the Db::open method is called.
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 is 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.
ParametersThe 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,2008 Oracle. All rights reserved.