Db::set_append_recno()

#include <db_cxx.h>
 
int
Db::set_append_recno(int (*db_append_recno_fcn)(DB *dbp, Dbt *data, db_recno_t recno));

When using the DB_APPEND option of the Db::put() method, it may be useful to modify the stored data based on the generated key. If a callback function is specified using the Db::set_append_recno() method, it will be called after the record number has been selected, but before the data has been stored.

The Db::set_append_recno() method configures operations performed using the specified Db handle, not all operations performed on the underlying database.

The Db::set_append_recno() method may not be called after the Db::open() method is called.

The Db::set_append_recno() 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.

Note

Berkeley DB is not re-entrant. Callback functions should not attempt to make library calls (for example, to release locks or close open handles). Re-entering Berkeley DB is not guaranteed to work correctly, and the results are undefined.

Parameters

db_append_recno_fcn

The db_append_recno_fcn parameter is a function to call after the record number has been selected but before the data has been stored into the database. The function takes three parameters:

  • dbp

    The dbp parameter is the enclosing database handle.

  • data

    The data parameter is the data Dbt to be stored.

  • recno

    The recno parameter is the generated record number.

The called function may modify the data Dbt. If the function needs to allocate memory for the data field, the flags field of the returned Dbt should be set to DB_DBT_APPMALLOC, which indicates that Berkeley DB should free the memory when it is done with it.

The callback function must return 0 on success and errno or a value outside of the Berkeley DB error name space on failure.

Errors

The Db::set_append_recno() method may fail and throw a DbException exception, encapsulating one of the following non-zero errors, or return one of the following non-zero errors:

EINVAL

If the method was called after Db::open() was called; or if an invalid flag value or parameter was specified.

Class

Db

See Also

Database and Related Methods