+I+Berkeley DB: DBcursor->c_get[P

DBcursor->c_get





#include <db.h>

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





Description



MThe DBcursor->c_get function retrieves key/data pairs from the database. TheaddressIand length of the key are returned in the object referenced by keyF(except for the case of the DB_SET flag where the key object isunchanged), and theaddressLand length of the data are returned in the object referenced by data.

HModifications to the database during a sequential scan will be reflectedGin the scan, i.e. records inserted behind a cursor will not be returned=while records inserted in front of a cursor will be returned.

MIn Recno databases, missing entries (i.e., entries that were never explicitlyHcreated or that were created and then deleted), will be skipped during asequential scan.

IIf multiple threads or processes insert items into the same database file1without using locking, the results are undefined.For more detail,@see cursor stability.

FThe flags parameter must be set to one of the following values:

Z

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,9the 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 neverHexplicitly created by the application or were created and later deleted.

BIf the database is empty, DBcursor->c_get will return DB_NOTFOUND.X

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,8the last data item in the set of duplicates is returned.

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

BIf the database is empty, DBcursor->c_get will return DB_NOTFOUND.Y

DB_NEXT
If the cursor is not yet initialized, DB_NEXT is identical to DB_FIRST.

EOtherwise, move the cursor to the next key/data pair of the database,and that pair is returned.MIn 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 the9DB_NEXT flag will skip any keys that exist but were neverHexplicitly created by the application or were created and later deleted.

LIf the cursor is already on the last record in the database, DBcursor->c_getwill return DB_NOTFOUND.]

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

9If the cursor is not yet initialized, the DBcursor->c_getfunction will return EINVAL.X

DB_PREV
If the cursor is not yet initialized, DB_PREV is identical to DB_LAST.

IOtherwise, move the cursor to the previous key/data pair of the database,and that pair is returned.MIn 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 the9DB_PREV flag will skip any keys that exist but were neverHexplicitly created by the application or were created and later deleted.

MIf the cursor is already on the first record in the database, DBcursor->c_getwill return DB_NOTFOUND.Q

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

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

9If the cursor is not yet initialized, the DBcursor->c_getfunction will return EINVAL.P

DB_SET
Move the cursor to the specified key/data pair of the database,3and return the datum associated with the given key.

HIn the presence of duplicate key values, DBcursor->c_get will return the"first data item for the given key.

IIf the database is a Recno database and the requested key exists, but wasAnever explicitly created by the application or was later deleted,(DBcursor->c_get will return DB_KEYEMPTY.

GIf 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 theGkey is returned as well as the data item, and, in the case of the btreeJaccess 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 theJkey and the data arguments must be matched by the key and data item in the database.W

DB_SET_RECNO
Move the cursor to the specific numbered record of the database,(and return the associated key/data pair.1The data field of the specified keypmust be a pointer to a memory location from which a db_recno_t!may be read, as described in DBT.JThis memory location will be read to determine the record to be retrieved.

DFor DB_SET_RECNO to be specified, the underlying database must be ofvtype btree and it must have been created with the DB_RECNUM flag.K

DB_GET_RECNO
Return the record number associated with the cursor.AThe record number will be returned in data as described inDBT.$The key parameter is ignored.

DFor DB_GET_RECNO to be specified, the underlying database must be ofvtype btree and it must have been created with the DB_RECNUM flag.



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

T

DB_RMW
Acquire write locks instead of read locks when doing the retrieval.BSetting this flag may decrease the likelihood of deadlock during aFread-modify-write cycle by immediately acquiring the write lock duringFthe read part of the cycle so that another thread of control acquiringGa read lock for the same item, in its own read-modify-write cycle, willnot result in deadlock.


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

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



Errors

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

The DBcursor->c_get)function may fail and return errnoKfor 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),6lock_get,3lock_put,l6lock_vec,1log_put,m malloc(3), memcmp(3), memcpy(3), memmove(3),m9memp_fget,r9memp_fput,b9memp_fset,g memset(3), realloc(3), strerror(3), vfprintf(3),and> vsnprintf(3).<

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

(

EAGAIN
A lock was unavailable.
t

h

B

EINVAL
An invalid flag value or parameter was specified.

3The specified cursor was not currently initialized. 

t•The DB_THREAD flag was specified to db_open and neitheraIthe DB_DBT_MALLOC orn_DB_DBT_USERMEM flags were set in the DBT.b



r

See Also

e8db_appexit,8db_appinit,8db_version,2DB->close,4DB->cursor,.DB->del,,DB->fd,.DB->get,/db_open,h.DB->put,0DB->stat,0DB->sync,;DBcursor->c_close,i7DBcursor->c_del,DBcursor->c_geteandt7DBcursor->c_put. 
csoÿÿ>c_get using the:DB_FIRST flag will skip any keys that exist but were neverHexplicitly created by the application or were created and later deleted.

BIf the database is empty, DBcursor->c_get will return DB_NOTFOUND.X

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,8the last data item in the set of duplicates is returned.

>If the database is a R