# DbEnv::log_get

`

###

    #include <db_cxx.h>

    int
    DbEnv::log_get(DbLsn *lsn, Dbt *data, u_int32_t flags);

# Description

The DbEnv::log_get method implements a cursor inside of the log, retrieving records from the log according to the lsn and flags arguments.

The data field of the data structure is set to the record retrieved and the size field indicates the number of bytes in the record. See Dbt for a description of other fields in the data structure. When multiple threads are using the returned log handle concurrently, one of the DB_DBT_MALLOC, DB_DBT_REALLOC or DB_DBT_USERMEM flags must be specified for any Dbt used for data retrieval.

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

DB_CHECKPOINT
  The last record written with the DB_CHECKPOINT flag specified to the DbEnv::log_put method is returned in the data argument. The lsn argument is overwritten with the DbLsn of the record returned. If no record has been previously written with the DB_CHECKPOINT flag specified, the first record in the log is returned.

  If the log is empty, the DbEnv::log_get method will return DB_NOTFOUND.

DB_FIRST
  The first record from any of the log files found in the log directory is returned in the data argument. The lsn argument is overwritten with the DbLsn of the record returned.

  If the log is empty, the DbEnv::log_get method will return DB_NOTFOUND.

DB_LAST
  The last record in the log is returned in the data argument. The lsn argument is overwritten with the DbLsn of the record returned.

  If the log is empty, the DbEnv::log_get method will return DB_NOTFOUND.

DB_NEXT
  The current log position is advanced to the next record in the log and that record is returned in the data argument. The lsn argument is overwritten with the DbLsn of the record returned.

  If the pointer has not been initialized via DB_FIRST, DB_LAST, DB_SET, DB_NEXT, or DB_PREV, DbEnv::log_get will return the first record in the log. If the last log record has already been returned or the log is empty, the DbEnv::log_get method will return DB_NOTFOUND.

  If the log was opened with the DB_THREAD flag set, calls to DbEnv::log_get with the DB_NEXT flag set will return EINVAL.

DB_PREV
  The current log position is moved to the previous record in the log and that record is returned in the data argument. The lsn argument is overwritten with the DbLsn of the record returned.

  If the pointer has not been initialized via DB_FIRST, DB_LAST, DB_SET, DB_NEXT, or DB_PREV, DbEnv::log_get will return the last record in the log. If the first log record has already been returned or the log is empty, the DbEnv::log_get method will return DB_NOTFOUND.

  If the log was opened with the DB_THREAD flag set, calls to DbEnv::log_get with the DB_PREV flag set will return EINVAL.

DB_CURRENT
  Return the log record currently referenced by the log.

  If the log pointer has not been initialized via DB_FIRST, DB_LAST, DB_SET, DB_NEXT, or DB_PREV, or if the log was opened with the DB_THREAD flag set, DbEnv::log_get will return EINVAL.

DB_SET
  Retrieve the record specified by the lsn argument. If the specified DbLsn is invalid (e.g., does not appear in the log) DbEnv::log_get will return EINVAL.

Otherwise, the DbEnv::log_get method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success.

# Errors

The DbEnv::log_get method may fail and throw an exception or return a non-zero error for the following conditions:

EINVAL
  An invalid flag value or parameter was specified.

  The DB_FIRST flag was specified and no log files were found.

The DbEnv::log_get method may fail and throw an exception or return a non-zero error for errors specified for other Berkeley DB and C library or system methods. If a catastrophic error has occurred, the DbEnv::log_get method may fail and either return DB_RUNRECOVERY or throw an exception encapsulating DB_RUNRECOVERY, in which case all subsequent Berkeley DB calls will fail in the same way.

### Class

DbEnv

# See Also

DbEnv::set_lg_bsize, DbEnv::set_lg_max, DbEnv::log_archive, DbEnv::log_compare, DbEnv::log_file, DbEnv::log_flush, DbEnv::log_get, DbEnv::log_put, DbEnv::log_register, DbEnv::log_stat and DbEnv::log_unregister.`

Copyright Sleepycat Software