Berkeley DB Reference Version 5.3.33

DBcursor->get()

#include <db.h>

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

int
DBcursor->pget(DBC *DBcursor,
    DBT *key, DBT *pkey, DBT *data, u_int32_t flags);  

The DBcursor->get() method retrieves key/data pairs from the database. The address and length of the key are returned in the object to which key refers (except for the case of the DB_SET flag, in which the key object is unchanged), and the address and length of the data are returned in the object to which data refers.

When called on a cursor opened on a database that has been made into a secondary index using the DB->associate() method, the DBcursor->get() and DBcursor->pget() methods return the key from the secondary index and the data item from the primary database. In addition, the DBcursor->pget() method returns the key from the primary database. In databases that are not secondary indices, the DBcursor->pget() method will always fail.

Modifications to the database during a sequential scan will be reflected in the scan; that is, records inserted behind a cursor will not be returned while records inserted in front of a cursor will be returned.

In Queue and Recno databases, missing entries (that is, entries that were never explicitly created or that were created and then deleted) will be skipped during a sequential scan.

Unless otherwise specified, the DBcursor->get() method returns a non-zero error value on failure and 0 on success.

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

Parameters

key

The key DBT operated on.

If DB_DBT_PARTIAL is set for the DBT used for this parameter, and if the flags parameter is set to DB_GET_BOTH, DB_GET_BOTH_RANGE, DB_SET, or DB_SET_RECNO, then this method will fail and return EINVAL.

pkey

The return key from the primary database. If DB_DBT_PARTIAL is set for the DBT used for this parameter, then this method will fail and return EINVAL.

data

The data DBT operated on.

flags

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

In addition, the following flags may be set by bitwise inclusively OR'ing them into the flags parameter:

Errors

The DBcursor->get() method may fail and return one of the following non-zero errors:

DB_BUFFER_SMALL

The requested item could not be returned due to undersized buffer.

DB_LOCK_DEADLOCK

A transactional database environment operation was selected to resolve a deadlock.

DB_LOCK_NOTGRANTED

A Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable to grant a lock in the allowed time.

You attempted to open a database handle that is configured for no waiting exclusive locking, but the exclusive lock could not be immediately obtained. See DB->set_lk_exclusive() for more information.

DB_REP_HANDLE_DEAD

When a client synchronizes with the master, it is possible for committed transactions to be rolled back. This invalidates all the database and cursor handles opened in the replication environment. Once this occurs, an attempt to use such a handle will return DB_REP_HANDLE_DEAD. The application will need to discard the handle and open a new one in order to continue processing.

DB_REP_LEASE_EXPIRED

The operation failed because the site's replication master lease has expired.

DB_REP_LOCKOUT

The operation was blocked by client/master synchronization.

DB_SECONDARY_BAD

A secondary index references a nonexistent primary key.

EINVAL

If the DB_CURRENT, DB_NEXT_DUP or DB_PREV_DUP flags were specified and the cursor has not been initialized; the DBcursor->pget() method was called with a cursor that does not refer to a secondary index; or if an invalid flag value or parameter was specified.

Class

DBcursor

See Also

Database Cursors and Related Methods