NNAAMMEE Dbc - database sequential access functions SSYYNNOOPPSSIISS ##iinncclluuddee <> iinntt DDbbcc::::cclloossee((vvooiidd));; iinntt DDbbcc::::ddeell((uu__iinntt3322__tt ffllaaggss));; iinntt DDbbcc::::ggeett((DDbbtt **kkeeyy,, DDbbtt **ddaattaa,, uu__iinntt3322__tt ffllaaggss));; iinntt DDbbcc::::ppuutt((DDbbtt **kkeeyy,, DDbbtt **ddaattaa,, uu__iinntt3322__tt ffllaaggss));; DDEESSCCRRIIPPTTIIOONN The DB library is a family of classes that provides a mod- ular programming interface to transactions and record-ori- ented file access. The library includes support for transactions, locking, logging and file page caching, as well as various indexed access methods. Many of the classes (e.g., the file page caching class) are useful independent of the other DB classes, although some classes are explicitly based on other classes (e.g., transactions and logging). For a general description of the DB pack- age, see _d_b___i_n_t_r_o(3). This manual page describes the specific details of the cursor support for the access methods in _D_b_(_3_). The _D_b_c functions are the library interface supporting sequential access to the records stored by the access methods of the Db library. Cursors are created by calling _D_b_:_:_c_u_r_s_o_r method described in _D_b(3), which returns a pointer to a Dbc object. Each cursor maintains positioning information within a set of key/data pairs. In the presence of transactions, cur- sors are only valid within the context of a single trans- action, the one specified during the _D_b_:_:_c_u_r_s_o_r call described in _D_b(3). All cursor operations will be exe- cuted in the context of that transaction. Before aborting or committing a transaction, all cursors used within that transaction must be closed. In the presence of transac- tions, the application must call _D_b_T_x_n_:_:_a_b_o_r_t if any of the cursor operations returns that a deadlock (EAGAIN) or system failure occurred. When locking is enabled, page locks are retained between consecutive cursor calls. For this reason, in the pres- ence of locking, applications should discard cursors as soon as they are done with them. Calling the _D_b_:_:_c_l_o_s_e method (see _D_b(3)) discards any cursors opened in the con- text of a particular Db object returned by the _D_b_:_:_o_p_e_n call. The methods of the Dbc are defined as follows: int Dbc::close(); A method that discards the cursor. No further refer- ences to the Dbc object should be made. The _D_b_c_:_:_c_l_o_s_e method throws a _D_b_E_x_c_e_p_t_i_o_n(3) or returns the value of _e_r_r_n_o on failure and 0 on suc- cess. int Dbc::del(u_int32_t flags); A method that deletes the key/data pair currently referenced by the cursor. The _f_l_a_g_s parameter is currently unused, and must be set to 0. The cursor position is unchanged after a delete and subsequent calls to cursor functions expecting the cursor to reference an existing key will fail. The _D_b_c_:_:_d_e_l method throws a _D_b_E_x_c_e_p_t_i_o_n(3) or returns the value of _e_r_r_n_o on failure, 0 on success, and DB_KEYEMPTY if the element has already been deleted. int Dbc::get(Dbt *key, Dbt *data, u_int32_t flags); A method that retrieves key/data pairs from the database. The address and length of the key are returned in the object referenced by _k_e_y (except for the case of the DB_SET flag where the _k_e_y object is unchanged), and the address and length of the data are returned in the object referenced by _d_a_t_a. Modifications to the database during a sequential scan will be reflected in the scan, i.e. records inserted behind a cursor will not be returned while records inserted in front of a cursor will be returned. In recno databases, missing entries (i.e., entries that were never explicitly created or that were cre- ated and then deleted), will be skipped during a sequential scan. If multiple threads or processes insert items into the same database file without using locking, the results are undefined. For more detail, see the sec- tion below on cursor stability. The parameter _f_l_a_g_s must be set to exactly one of the following values: DB_FIRST The cursor is set to reference the first key/data pair of the database, and that pair is returned. In the presence of duplicate key val- ues, the first data item in the set of dupli- cates is returned. If the database is empty, the _D_b_c_:_:_g_e_t method will return DB_NOTFOUND. DB_LAST The cursor is set to reference the last key/data pair of the database, and that pair is returned. In the presence of duplicate key values, the last data item in the set of duplicates is returned. If the database is empty, the _D_b_c_:_:_g_e_t method will return DB_NOTFOUND. DB_NEXT If the cursor is not yet initialized, DB_NEXT is identical to DB_FIRST. Otherwise, move the cursor to the next key/data pair of the database, and that pair is returned. In the presence of duplicate key values, the value of the key may not change. If the cursor is already on the last record in the database, the _D_b_c_:_:_g_e_t method will return DB_NOTFOUND. DB_PREV If the cursor is not yet initialized, DB_PREV is identical to DB_LAST. Otherwise, move the cursor to the previous key/data pair of the database, and that pair is returned. In the presence of duplicate key val- ues, the value of the key may not change. If the cursor is already on the first record in the database, the _D_b_c_:_:_g_e_t method will return DB_NOTFOUND. DB_CURRENT Return the key/data pair currently referenced by the cursor. If the cursor key/data pair has been deleted, the _D_b_c_:_:_g_e_t method will return DB_KEYEMPTY. If the cursor is not yet initialized, the _D_b_c_:_:_g_e_t method will return EINVAL. DB_SET Move the cursor to the specified key/data pair of the database, and return the datum associated with the given key. In the presence of duplicate key values, _D_b_c_:_:_g_e_t will return the first data item for the given key. If the database is a recno database and the requested key exists, but was never explicitly created by the application or was later deleted, the _D_b_c_:_:_g_e_t method returns DB_KEYEMPTY. If no matching keys are found, the _D_b_c_:_:_g_e_t method will return DB_NOTFOUND. DB_SET_RANGE The DB_SET_RANGE flag is identical to the DB_SET flag, except that the key is returned as well as the data item, and, in the case of the btree access method, the returned key/data pair is the smallest key greater than or equal to the speci- fied key (as determined by the comparison func- tion), permitting partial key matches and range searches. DB_SET_RECNO Move the cursor to the specific numbered record of the database, and return the associated key/data pair. The _d_a_t_a field of the specified _k_e_y must be a pointer to a memory location from which a _d_b___r_e_c_n_o___t may be read, as described in _D_b_t(3). This memory location will be read to determine the record to be retrieved. For DB_SET_RECNO to be specified, the underlying database must be of type btree and it must have been created with the DB_RECNUM flag (see _D_b_:_:_o_p_e_n in _D_b(3)). DB_GET_RECNO Return the record number associated with the cursor. The record number will be returned in the data Dbt as described in _D_b_t(3). The _k_e_y parameter is ignored. For DB_GET_RECNO to be specified, the underlying database must be of type btree and it must have been created with the DB_RECNUM flag (see _D_b_:_:_o_p_e_n in _D_b(3)). Otherwise, the _D_b_c_:_:_g_e_t method throws a _D_b_E_x_c_e_p_- _t_i_o_n(3) or returns the value of _e_r_r_n_o on failure and 0 on success. If _D_b_c_:_:_g_e_t fails for any reason, the state of the cursor will be unchanged. int Dbc::put(Dbt *key, Dbt *data, u_int32_t flags); A method that stores key/data pairs into the database. The _f_l_a_g_s parameter must be set to exactly one of the following values: DB_AFTER In the case of the btree and hash access meth- ods, insert the data element as a duplicate ele- ment of the key referenced by the cursor. The new element appears immediately after the cur- rent cursor position. It is an error to specify DB_AFTER if the underlying btree or hash database was not created with the DB_DUP flag. The _k_e_y parameter is ignored. In the case of the recno access method, it is an error to specify DB_AFTER if the underlying recno database was not created with the DB_RENUMBER flag. If the DB_RENUMBER flag was specified, a new key is created, all records after the inserted item are automatically renum- bered, and the key of the new record is returned in the object referenced by the parameter _k_e_y. The initial value of the _k_e_y parameter is ignored. See _D_b_:_:_o_p_e_n in _D_b(3) for more infor- mation. If the cursor is not yet initialized, the _D_b_c_:_:_p_u_t method will return EINVAL. DB_BEFORE In the case of the btree and hash access meth- ods, insert the data element as a duplicate ele- ment of the key referenced by the cursor. The new element appears immediately before the current cursor position. It is an error to specify DB_BEFORE if the underlying btree or hash database was not created with the DB_DUP flag. The _k_e_y parameter is ignored. In the case of the recno access method, it is an error to specify DB_BEFORE if the underlying recno database was not created with the DB_RENUMBER flag. If the DB_RENUMBER flag was specified, a new key is created, the current record and all records after it are automati- cally renumbered, and the key of the new record is returned in the object referenced by the parameter _k_e_y. The initial value of the _k_e_y parameter is ignored. See _D_b_:_:_o_p_e_n in _D_b(3) for more information. If the cursor is not yet initialized, the _D_b_c_:_:_p_u_t method will return EINVAL. DB_CURRENT Overwrite the data of the key/data pair refer- enced by the cursor with the specified data item. The _k_e_y parameter is ignored. If the cursor is not yet initialized, the _D_b_c_:_:_p_u_t method will return EINVAL. DB_KEYFIRST In the case of the btree and hash access meth- ods, insert the specified key/data pair into the database. If the key already exists in the database, the inserted data item is added as the first of the data items for that key. The DB_KEYFIRST flag may not be specified to the recno access method. DB_KEYLAST Insert the specified key/data pair into the database. If the key already exists in the database, the inserted data item is added as the last of the data items for that key. The DB_KEYLAST flag may not be specified to the recno access method. If the cursor record has been deleted, the _D_b_c_:_:_p_u_t method will return DB_KEYEMPTY. Otherwise, the _D_b_c_:_:_p_u_t method throws a _D_b_E_x_c_e_p_- _t_i_o_n(3) or returns the value of _e_r_r_n_o on failure and 0 on success. If _D_b_c_:_:_p_u_t fails for any reason, the state of the cursor will be unchanged. If _D_b_c_:_:_p_u_t succeeds and an item is inserted into the database, the cursor is always positioned to reference the newly inserted item. CCUURRSSOORR SSTTAABBIILLIITTYY In the absence of locking, no guarantees are made about the stability of cursors in different processes or threads. However, the btree and recno access methods guarantee that cursor operations, interspersed with other cursor or non-cursor operations in the same thread of con- trol (i.e., thread or single-threaded process), will always return keys in order and will return each non- deleted key/data pair exactly once. Because the hash access method uses a dynamic hashing algorithm, it cannot guarantee any form of stability in the presence of inserts and deletes unless locking is performed. If locking was specified when the Db file was opened, but transactions are not in effect, the access methods provide repeatable reads with respect to the cursor. That is, a DB_CURRENT call on the cursor is guaranteed to return the same record as was returned on the last call to the cur- sor. In the presence of transactions, the access method calls between _D_b_T_x_n_M_g_r_:_:_b_e_g_i_n and _D_b_T_x_n_:_:_a_b_o_r_t or _D_b_T_x_n_:_:_c_o_m_m_i_t provide degree 3 consistency. For all access methods, a cursor scan of the database performed within the context of a transaction is guaranteed to return each key/data pair once and only once, except in the following case. If, while performing a cursor scan using the hash access method, the transaction performing the scan inserts a new pair into the database, it is possible that duplicate key/data pairs will be returned. EERRRROORRSS Methods marked as returning _e_r_r_n_o will, by default, throw an exception that encapsulates the error information. The default error behavior can be changed, see _D_b_E_x_c_e_p_t_i_o_n(3). The _D_b_c_:_:_c_l_o_s_e method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for any of the errors specified for the following DB and library functions: DbLock::get(3), DbLock::put(3), DbLockTab::id(3), DbLockTab::vec(3), DbLog::put(3), DbMpoolFile::get(3), DbMpoolFile::put(3), DbMpoolFile::set(3), calloc(3), fcntl(2), fflush(3), mal- loc(3), memcpy(3), memmove(3), memset(3), realloc(3), and strerror(3). In addition, the _D_b_c_:_:_c_l_o_s_e method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for the following condi- tions: [EAGAIN] A lock was unavailable. [EPERM] Database corruption was detected. All subsequent database calls (other than _D_b_:_:_c_l_o_s_e) will return EPERM. The _D_b_c_:_:_d_e_l method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for any of the errors specified for the following DB and library functions: Db::del(3), DbLock::get(3), DbLock::put(3), DbLockTab::id(3), DbLock- Tab::vec(3), DbLog::put(3), DbMpoolFile::get(3), DbM- poolFile::put(3), DbMpoolFile::set(3), calloc(3), fcntl(2), fflush(3), malloc(3), memcpy(3), memmove(3), memset(3), realloc(3), and strerror(3). In addition, the _D_b_c_:_:_d_e_l method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for the following condi- tions: [EAGAIN] A lock was unavailable. [EINVAL] An invalid flag value or parameter was specified. [EPERM] Database corruption was detected. All subsequent database calls (other than _D_b_:_:_c_l_o_s_e) will return EPERM. The _D_b_c_:_:_g_e_t method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for any of the errors specified for the following DB and library functions: Db::get(3), DbLock::get(3), DbLock::put(3), DbLockTab::id(3), DbLock- Tab::vec(3), DbLog::put(3), DbMpoolFile::get(3), DbM- poolFile::put(3), DbMpoolFile::set(3), calloc(3), fcntl(2), fflush(3), malloc(3), memcmp(3), memcpy(3), mem- move(3), memset(3), realloc(3), and strerror(3). In addition, the _D_b_c_:_:_g_e_t method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for the following condi- tions: [EAGAIN] A lock was unavailable. [EINVAL] An invalid flag value or parameter was specified. The DB_THREAD flag was specified to the _D_b_:_:_o_p_e_n method described in _D_b(3) and neither the DB_DBT_MAL- LOC or DB_DBT_USERMEM flags were set in the Dbt. [EPERM] Database corruption was detected. All subsequent database calls (other than _D_b_:_:_c_l_o_s_e) will return EPERM. The _D_b_c_:_:_p_u_t method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for any of the errors specified for the following DB and library functions: DbLock::get(3), DbLock::put(3), DbLockTab::id(3), DbLockTab::vec(3), DbLog::put(3), DbMpoolFile::get(3), DbMpoolFile::put(3), DbMpoolFile::set(3), calloc(3), fcntl(2), fflush(3), mal- loc(3), memcmp(3), memcpy(3), memmove(3), memset(3), real- loc(3), and strerror(3). In addition, the _D_b_c_:_:_p_u_t method may fail and throw a _D_b_E_x_c_e_p_t_i_o_n(3) or return _e_r_r_n_o for the following condi- tions: [EACCES] An attempt was made to modify a read-only database. [EAGAIN] A lock was unavailable. [EINVAL] An invalid flag value or parameter was specified. [EPERM] Database corruption was detected. All subsequent database calls (other than _D_b_:_:_c_l_o_s_e) will return EPERM. SSEEEE AALLSSOO _d_b___a_r_c_h_i_v_e(1), _d_b___c_h_e_c_k_p_o_i_n_t(1), _d_b___d_e_a_d_l_o_c_k(1), _d_b___d_u_m_p(1), _d_b___l_o_a_d(1), _d_b___r_e_c_o_v_e_r(1), _d_b___s_t_a_t(1), _d_b___i_n_t_r_o(3), _d_b___i_n_t_e_r_n_a_l(3), _d_b___t_h_r_e_a_d(3), _D_b(3), _D_b_c(3), _D_b_E_n_v(3), _D_b_E_x_c_e_p_t_i_o_n(3), _D_b_I_n_f_o(3), _D_b_L_o_c_k(3), _D_b_L_o_c_k_T_a_b(3), _D_b_L_o_g(3), _D_b_L_s_n(3), _D_b_M_p_o_o_l(3), _D_b_M_p_o_o_l_F_i_l_e(3), _D_b_t(3), _D_b_T_x_n(3), _D_b_T_x_n_M_g_r(3)