Google

Dbc.put

APIRef

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 value 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 to which the cursor refers. The new element appears immediately after the current cursor position. It is an error to specify Db.DB_AFTER if the underlying Btree or Hash database does not support duplicate data items. The key parameter is ignored.

In the case of the Recno access method, it is an error to specify Db.DB_AFTER if the underlying Recno database was not created with the Db.DB_RENUMBER flag. If the Db.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 to which the key argument refers. The initial value of the key parameter is ignored. See Db.open for more information.

The Db.DB_AFTER flag may not be specified to the Queue access method.

If the current cursor record has already been deleted and the underlying access method is Hash, Dbc.put will return Db.DB_NOTFOUND. If the underlying access method is Btree or Recno, the operation will succeed.

If the cursor is not yet initialized or if 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 to which the cursor refers. The new element appears immediately before the current cursor position. It is an error to specify Db.DB_BEFORE if the underlying Btree or Hash database does not support duplicate data items. The key parameter is ignored.

In the case of the Recno access method, it is an error to specify Db.DB_BEFORE if the underlying Recno database was not created with the Db.DB_RENUMBER flag. If the Db.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 to which the key argument refers. The initial value of the key parameter is ignored. See Db.open for more information.

The Db.DB_BEFORE flag may not be specified to the Queue access method.

If the current cursor record has already been deleted and the underlying access method is Hash, Dbc.put will return Db.DB_NOTFOUND. If the underlying access method is Btree or Recno, the operation will succeed.

If the cursor is not yet initialized or if a duplicate sort function has been specified, Dbc.put will return EINVAL.

Db.DB_CURRENT
Overwrite the data of the key/data pair to which the cursor refers with the specified data item. The key parameter is ignored.

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

If the current cursor record has already been deleted and the underlying access method is Hash, Dbc.put will return Db.DB_NOTFOUND. If the underlying access method is Btree, Queue, or Recno, the operation will succeed.

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 underlying database supports duplicate data items, and 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.DB_KEYFIRST flag may not be specified to the Queue or Recno access methods.

Db.DB_KEYLAST
In the case of the Btree and Hash access methods, insert the specified key/data pair into the database.

If the underlying database supports duplicate data items, and 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.DB_KEYLAST flag may not be specified to the Queue or Recno access methods.

Db.DB_NODUPDATA
In the case of the Btree and Hash access methods, insert the specified key/data pair into the database, unless it already exists in the database. If the key/data pair already appears in the database, Db.DB_KEYEXIST is returned. The Db.DB_NODUPDATA flag may only be specified if the underlying database has been configured to support sorted duplicate data items.

The Db.DB_NODUPDATA flag may not be specified to the Queue or Recno access methods.

Otherwise, the Dbc.put method throws an exception that encapsulates a non-zero error value 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 refer to the newly inserted item.

Errors

The Dbc.put method may fail and throw an exception encapsulating a non-zero error for the following conditions:

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

EINVAL
An invalid flag value or parameter was specified.

The Db.DB_BEFORE or Db.DB_AFTER flags were specified, and the underlying access method is Queue.

An attempt was made to add a record to a fixed-length database that was too large to fit.

An attempt was made to add a record to a secondary index.

EPERM
Write attempted on read-only cursor when the Db.DB_INIT_CDB flag was specified to DbEnv.open.

If the operation was selected to resolve a deadlock, the Dbc.put method will fail and throw a DbDeadlockException exception.

The Dbc.put method may fail and throw an exception for errors specified for other Berkeley DB and C library or system methods. If a catastrophic error has occurred, the Dbc.put method may fail and throw a DbRunRecoveryException, in which case all subsequent Berkeley DB calls will fail in the same way.

Class

Dbc

See Also

Database Cursors and Related Methods

APIRef

Copyright Sleepycat Software