*I$Berkeley DB: Dbc::put[P

Dbc::put





#include <db_cxx.h>

int/Dbc::put(Dbt *key, Dbt *data, u_int32_t flags);





Description



<The Dbc::put method stores key/data pairs into the database.

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

D

DB_AFTER
In the case of the btree and hash access methods,Dinsert the data element as a duplicate element of the key referencedby the cursor.FThe new element appears immediately after the current cursor position.KIt 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.

JIn the case of the recno access method, it is an error to specify DB_AFTERKif the underlying recno database was not created with the DB_RENUMBER flag.HIf the DB_RENUMBER flag was specified, a new key is created, all recordsHafter the inserted item are automatically renumbered, and the key of theCnew record is returned in the structure referenced by the parameter key.9The initial value of the key parameter is ignored.KSee Db::open for more information.

JIf the cursor is not yet initialized or a duplicate sort function has been4specified, the Dbc::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.GThe new element appears immediately before the current cursor position.LIt 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.

KIn the case of the recno access method, it is an error to specify DB_BEFOREKif the underlying recno database was not created with the DB_RENUMBER flag.<If the DB_RENUMBER flag was specified, a new key is created,Ithe current record and all records after it are automatically renumbered,Hand the key of the new record is returned in the structure referenced bythe parameter key.9The initial value of the key parameter is ignored.KSee Db::open for more information.

JIf the cursor is not yet initialized or a duplicate sort function has been'specified, Dbc::put will return EINVAL.^

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

$The key parameter is ignored.

HIf a duplicate sort function has been specified and the data item of theLcurrent referenced key/data pair does not compare equally to the data'parameter, Dbc::put will return EINVAL.

%If the cursor is not yet initialized,Dbc::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,Hand 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,Iand no duplicate sort function has been specified, the inserted data item5is added as the first of the data items for that key.

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

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

*If the key already exists in the database,Hand 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,Iand no duplicate sort function has been specified, the inserted data item4is added as the last of the data items for that key.

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



&If the cursor record has been deleted,!Dbc::put will return DB_KEYEMPTY.

Otherwise, the Dbc::put>method either returns errno or throws an exception that:encapsulates an errno on failure, and 0 on success.

9If Dbc::put fails for any reason, the state of the cursorwill be unchanged.5If Dbc::put succeeds and an item is inserted into the@database, the cursor is always positioned to reference the newlyinserted item.



Errors

OIf a fatal error occurs in Berkeley DB, the Dbc::put method may fail and eitherIreturn DB_RUNRECOVERY or throw an exception encapsulating DB_RUNRECOVERY,Gat which point all subsequent database calls will also fail in the sameFway. Methods marked as returning errno will, by default, throwHan exception that encapsulates the error information. The default error\behavior can be changed, see
DbException.

The Dbc::put&method may fail and throw an exceptionKfor 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),>DbLockTab::get,8DbLock::put,>DbLockTab::vec,6DbLog::put, malloc(3), memcmp(3), memcpy(3), memmove(3),BDbMpoolFile::get,BDbMpoolFile::put,BDbMpoolFile::set, memset(3), realloc(3), strerror(3), vfprintf(3),and vsnprintf(3).

In addition, the Dbc::put&method may fail and throw an exceptionor return errnofor the following conditions:

D

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


(

EAGAIN
A lock was unavailable.


B

EINVAL
An invalid flag value or parameter was specified.







Class

.Dbc



See Also

6Dbc::close,2Dbc::del,1Dbc::getand Dbc::put.
ÿÿ