Berkeley DB: Dbc.put
Description: Berkeley DB: An embedded database programmatic toolkit.
Keywords: embedded,database,programmatic,toolkit,b+tree,btr ee,hash,hashing,transaction,transactions,locking,logging,access method,access me thods,java,C,C++

# Dbc.put

`

###

    import com.sleepycat.db.*;

    public void put(Dbt key, Dbt data, int flags)
    	throws DbException;

# Description

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

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

Db.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 Dbc.put function will return EINVAL.

Db.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, Dbc.put will return EINVAL.

Db.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, Dbc.put will return EINVAL.

  If the cursor is not yet initialized, Dbc.put will return EINVAL.

Db.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.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, Dbc.put will return DB_KEYEMPTY.

Otherwise, the Dbc.put method throws an exception that encapsulates an errno on failure.

If Dbc.put fails for any reason, the state of the cursor will be unchanged. If Dbc.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 Dbc.put method may fail and throw a DbRunRecoveryException, at which point all subsequent database calls will also fail in the same way.

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

In addition, the Dbc.put method may fail and throw an exception encapsulating 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.

# Class

Dbc

# See Also

Dbc.close, Dbc.del, Dbc.get and Dbc.put.`