-I:Berkeley DB Reference Guide: Access Methods[P4

Berkeley DB Reference Guide: Access Methods



6

Retrieving records with a cursor



kThe DBcursor->c_get function is the standard function for retrievingErecords from the database, with a cursor. In general, the cursor getGfunction takes a key and returns the associated data from the database.

@There are several flags that you can set to customize retrieval:

m

DB_FIRST
Return the first record from the database.j

DB_LAST
Return the last record from the database.

DB_NEXT
Return the record from the database immediately following the cursor.

DB_NEXT_DUP
Return the record from the database immediately following the cursor, if0it is a duplicate data item for the current key.

DB_PREV
Return the record from the database immediately preceding the cursor.

DB_CURRENT
Return the record from the database currently pointed to by the cursor.

DB_SET
Return the record from the database that matches the supplied key.

DB_SET_RANGE
Return the smallest record in the database greater than or equal to theGsupplied key. This functionality permits partial key matches and range searches.

DB_GET_BOTH
Return the record from the database that matches both the supplied keyIand data items. This is particularly useful when there are large numbersDof duplicate records for a key, as it allows the cursor to easily beIpositioned at the correct place for traversal of some part of a large setof duplicate records.

DB_SET_RECNO
If the underlying database is a Btree, and was configured so that it isCpossible to search it by logical record number, retrieve a specificrecord.

DB_GET_RECNO
If the underlying database is a Btree, and was configured so that it isHpossible to search it by logical record number, return the record numberfor the current cursor record.

DB_RMW
Acquire write locks instead of read locks during retrieval. This can@enhance performance in threaded applications where deadlock is aconcern.


nIn all cases, the cursor is repositioned by a DBcursor->c_get operation=to point to the newly returned key/data pair in the database.

HAH