Berkeley DB: DBcursor->c_put
Description: Berkeley DB: An embedded database programmatic toolkit.
Keywords: embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++

# 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.

  In the case of the Queue access method, it is always an error to specify DB_AFTER.

  If the current cursor record has already been deleted and the underlying access method is Hash, DBcursor->c_put will return DB_NOTFOUND. If the underlying access method is Btree or Recno, the operation will succeed.

  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.

  In the case of the Queue access method, it is always an error to specify DB_BEFORE.

  If the current cursor record has already been deleted and the underlying access method is Hash, DBcursor->c_put will return DB_NOTFOUND. If the underlying access method is Btree or Recno, the operation will succeed.

  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 current cursor record has already been deleted and the underlying access method is Hash, DBcursor->c_put will return DB_NOTFOUND. If the underlying access method is Btree, Queue or Recno, the operation will succeed.

  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 Queue or Recno access methods.

DB_KEYLAST
  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 last of the data items for that key.

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

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_KEYEXIST is returned. The DB_NODUPDATA flag may only be specified if the underlying database has been configured to support sorted duplicates.

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

Otherwise, the DBcursor->c_put function returns a non-zero error value 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

The DBcursor->c_put function may fail and return a non-zero error for the following conditions:

DB_LOCK_DEADLOCK
  The operation was selected to resolve a deadlock.

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

EINVAL
  An invalid flag value or parameter was specified.

  The DB_BEFORE or 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.

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

The DBcursor->c_put function may fail and return a non-zero error for errors specified for other Berkeley DB and C library or system functions. If a catastrophic error has occurred, the DBcursor->c_put function may fail and return DB_RUNRECOVERY, in which case all subsequent Berkeley DB calls will fail in the same way.

# See Also

DBcursor->c_close, DBcursor->c_count, DBcursor->c_del, DBcursor->c_dup, DBcursor->c_get and DBcursor->c_put.`

Copyright Sleepycat Software