Berkeley DB: DBcursor->c_get
Полезная информация Как перевести стрелки на часах casio g shock ga

DBcursor->c_get


#include <db.h>

int DBcursor->c_get(DBC *cursor, DBT *key, DBT *data, u_int32_t flags);

Description

The DBcursor->c_get function retrieves key/data pairs from the database. The address and length of the key are returned in the object referenced by key (except for the case of the DB_SET flag where the key object is unchanged), and the address and length of the data are returned in the object referenced by data.

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 created 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 cursor stability.

The flags parameter must be set to 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 values, the first data item in the set of duplicates is returned.

If the database is a Recno database, DBcursor->c_get using the DB_FIRST flag will skip any keys that exist but were never explicitly created by the application or were created and later deleted.

If the database is empty, DBcursor->c_get 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 a Recno database, DBcursor->c_get using the DB_LAST flag will skip any keys that exist but were never explicitly created by the application or were created and later deleted.

If the database is empty, DBcursor->c_get 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 database is a Recno database, DBcursor->c_get using the DB_NEXT flag will skip any keys that exist but were never explicitly created by the application or were created and later deleted.

If the cursor is already on the last record in the database, DBcursor->c_get will return DB_NOTFOUND.

DB_NEXT_DUP
If the next key/data pair of the database is a duplicate record for the current key/data pair, move the cursor to the next key/data pair of the database, and that pair is returned. Otherwise, DBcursor->c_get will return DB_NOTFOUND.

If the cursor is not yet initialized, the DBcursor->c_get function will return EINVAL.

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 values, the value of the key may not change.

If the database is a Recno database, DBcursor->c_get using the DB_PREV flag will skip any keys that exist but were never explicitly created by the application or were created and later deleted.

If the cursor is already on the first record in the database, DBcursor->c_get will return DB_NOTFOUND.

DB_CURRENT
Return the key/data pair currently referenced by the cursor.

If the cursor key/data pair was deleted, DBcursor->c_get will return DB_KEYEMPTY.

If the cursor is not yet initialized, the DBcursor->c_get function 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, DBcursor->c_get 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, DBcursor->c_get will return DB_KEYEMPTY.

If no matching keys are found, DBcursor->c_get 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 specified key (as determined by the comparison function), permitting partial key matches and range searches.

DB_GET_BOTH
The DB_GET_BOTH flag is identical to the DB_SET flag, except that both the key and the data arguments must be matched by the key and data item in the database.

DB_SET_RECNO
Move the cursor to the specific numbered record of the database, and return the associated key/data pair. The data field of the specified key must be a pointer to a memory location from which a db_recno_t may be read, as described in DBT. 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.

DB_GET_RECNO
Return the record number associated with the cursor. The record number will be returned in data as described in DBT. The key 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.

In addition, the following value may be set by logically OR'ing it into the flags parameter:

DB_RMW
Acquire write locks instead of read locks when doing the retrieval. Setting this flag may decrease the likelihood of deadlock during a read-modify-write cycle by immediately 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.

Otherwise, the DBcursor->c_get function returns the value of errno on failure, and 0 on success.

If DBcursor->c_get fails for any reason, the state of the cursor will be unchanged.

Errors

If a fatal error occurs in Berkeley DB, the DBcursor->c_get function may fail and return DB_RUNRECOVERY, at which point all subsequent database calls will also return DB_RUNRECOVERY.

The DBcursor->c_get function may fail and return errno for any of the errors specified for the following Berkeley DB and C library functions: __account_page(3), abort(3), dbenv->db_paniccall(3), dbp->dup_compare(3), fflush(3), fprintf(3), free(3), func(3), hcp->dbc->dbp->h_hash(3), lock_get, lock_put, lock_vec, log_put, malloc(3), memcmp(3), memcpy(3), memmove(3), memp_fget, memp_fput, memp_fset, memset(3), realloc(3), strerror(3), vfprintf(3), and vsnprintf(3).

In addition, the DBcursor->c_get function may fail and return errno for the following conditions:

EAGAIN
A lock was unavailable.

EINVAL
An invalid flag value or parameter was specified.

The specified cursor was not currently initialized.

The DB_THREAD flag was specified to db_open and neither the DB_DBT_MALLOC or DB_DBT_USERMEM flags were set in the DBT.

See Also

db_appexit, db_appinit, db_version, DB->close, DB->cursor, DB->del, DB->fd, DB->get, db_open, DB->put, DB->stat, DB->sync, DBcursor->c_close, DBcursor->c_del, DBcursor->c_get and DBcursor->c_put.