Berkeley DB: DBcursor->c_put
Полезная информация

DBcursor->c_put


#include <db.h>

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

Description

The DBcursor->c_put function stores key/data pairs into the database.

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

DB_AFTER
In the case of the btree and hash access methods, insert the data element as a duplicate element of the key referenced by the cursor. The new element appears immediately after the current cursor position. It is an error to specify DB_AFTER if the underlying btree or hash database was not created with the DB_DUP flag. The key parameter is ignored.

In the case of the recno access method, it is an error to specify DB_AFTER if the underlying recno database was not created with the DB_RENUMBER flag. If the DB_RENUMBER flag was specified, a new key is created, all records after the inserted item are automatically renumbered, and the key of the new record is returned in the structure referenced by the parameter key. The initial value of the key parameter is ignored. See db_open for more information.

If the cursor is not yet initialized or a duplicate sort function has been specified, the DBcursor->c_put function will return EINVAL.

DB_BEFORE
In the case of the btree and hash access methods, insert the data element as a duplicate element of the key referenced by the cursor. The new element appears immediately before the current cursor position. It is an error to specify DB_BEFORE if the underlying btree or hash database was not created with the DB_DUP flag. The key parameter is ignored.

In the case of the recno access method, it is an error to specify DB_BEFORE if the underlying recno database was not created with the DB_RENUMBER flag. If the DB_RENUMBER flag was specified, a new key is created, the current record and all records after it are automatically renumbered, and the key of the new record is returned in the structure referenced by the parameter key. The initial value of the key parameter is ignored. See db_open for more information.

If the cursor is not yet initialized or a duplicate sort function has been specified, DBcursor->c_put will return EINVAL.

DB_CURRENT
Overwrite the data of the key/data pair referenced by the cursor with the specified data item.

The key parameter is ignored.

If a duplicate sort function has been specified and the data item of the current referenced key/data pair does not compare equally to the data parameter, DBcursor->c_put will return EINVAL.

If the cursor is not yet initialized, DBcursor->c_put will return EINVAL.

DB_KEYFIRST
In the case of the btree and hash access methods, insert the specified key/data pair into the database.

If the key already exists in the database, and a duplicate sort function has been specified, the inserted data item is added in its sorted location. If the key already exists in the database, and no duplicate sort function has been specified, the inserted data item is added as the first of the data items for that key.

The DB_KEYFIRST flag may not be specified to the recno access method.

DB_KEYLAST
Insert the specified key/data pair into the database.

If the key already exists in the database, and a duplicate sort function has been specified, the inserted data item is added in its sorted location. If the key already exists in the database, and no duplicate sort function has been specified, the inserted data item is added as the last of the data items for that key.

The DB_KEYLAST flag may not be specified to the recno access method.

If the cursor record has been deleted, DBcursor->c_put will return DB_KEYEMPTY.

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

If DBcursor->c_put fails for any reason, the state of the cursor will be unchanged. If DBcursor->c_put succeeds and an item is inserted into the database, the cursor is always positioned to reference the newly inserted item.

Errors

If a fatal error occurs in Berkeley DB, the DBcursor->c_put function may fail and return DB_RUNRECOVERY, at which point all subsequent database calls will also return DB_RUNRECOVERY.

The DBcursor->c_put function may fail and return errno for 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), lock_get, lock_put, lock_vec, log_put, malloc(3), memcmp(3), memcpy(3), memmove(3), memp_fget, memp_fput, memp_fset, memset(3), realloc(3), strerror(3), vfprintf(3), and vsnprintf(3).

In addition, the DBcursor->c_put function may fail and return errno for the following conditions:

EACCES
An attempt was made to modify a read-only database.

EAGAIN
A lock was unavailable.

EINVAL
An invalid flag value or parameter was specified.

See Also

db_appexit, db_appinit, db_version, DB->close, DB->cursor, DB->del, DB->fd, DB->get, db_open, DB->put, DB->stat, DB->sync, DBcursor->c_close, DBcursor->c_del, DBcursor->c_get and DBcursor->c_put.