163 lines
8.9 KiB
HTML
163 lines
8.9 KiB
HTML
<!--$Id: dbc_put.html 63573 2008-05-23 21:43:21Z trent.nelson $-->
|
|
<!--Copyright (c) 1997,2008 Oracle. All rights reserved.-->
|
|
<!--See the file LICENSE for redistribution information.-->
|
|
<html>
|
|
<head>
|
|
<title>Berkeley DB: Dbc::put</title>
|
|
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
|
|
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
|
|
</head>
|
|
<body bgcolor=white>
|
|
<table width="100%"><tr valign=top>
|
|
<td>
|
|
<b>Dbc::put</b>
|
|
</td>
|
|
<td align=right>
|
|
<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a>
|
|
<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td>
|
|
</tr></table>
|
|
<hr size=1 noshade>
|
|
<tt>
|
|
<b><pre>
|
|
#include <db_cxx.h>
|
|
<p>
|
|
int
|
|
Dbc::put(Dbt *key, Dbt *data, u_int32_t flags);
|
|
</pre></b>
|
|
<hr size=1 noshade>
|
|
<b>Description: Dbc::put</b>
|
|
<p>The Dbc::put method stores key/data pairs into the database.</p>
|
|
<p>Unless otherwise specified, the Dbc::put method
|
|
either returns a non-zero error value
|
|
or throws an exception that encapsulates a non-zero error value on
|
|
failure, and returns 0 on success.
|
|
</p>
|
|
<p>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.</p>
|
|
<b>Parameters</b> <br>
|
|
<b>data</b><ul compact><li>The data <a href="../api_cxx/dbt_class.html">Dbt</a> operated on.</ul>
|
|
<b>flags</b><ul compact><li>The <b>flags</b> parameter must be set to one of the following values:
|
|
<br>
|
|
<b><a name="DB_AFTER">DB_AFTER</a></b><ul compact><li>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_AFTER if the underlying Btree or
|
|
Hash database is not configured for unsorted duplicate data items. The
|
|
<b>key</b> parameter is ignored.
|
|
<p>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 <a href="../api_cxx/db_set_flags.html#DB_RENUMBER">DB_RENUMBER</a> flag. If the <a href="../api_cxx/db_set_flags.html#DB_RENUMBER">DB_RENUMBER</a> 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 <b>key</b> parameter refers. The initial
|
|
value of the <b>key</b> parameter is ignored. See <a href="../api_cxx/db_open.html">Db::open</a>
|
|
for more information.</p>
|
|
<p>The DB_AFTER flag may not be specified to the Queue access method.</p>
|
|
<p>The Dbc::put method will return <a href="../ref/program/errorret.html#DB_NOTFOUND">DB_NOTFOUND</a> if the current cursor record has already been deleted and the
|
|
underlying access method is Hash.
|
|
</p></ul>
|
|
<b><a name="DB_BEFORE">DB_BEFORE</a></b><ul compact><li>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_AFTER if the underlying Btree or
|
|
Hash database is not configured for unsorted duplicate data items. The
|
|
<b>key</b> parameter is ignored.
|
|
<p>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 <a href="../api_cxx/db_set_flags.html#DB_RENUMBER">DB_RENUMBER</a> flag. If the <a href="../api_cxx/db_set_flags.html#DB_RENUMBER">DB_RENUMBER</a> 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 <b>key</b> parameter refers.
|
|
The initial value of the <b>key</b> parameter is ignored. See
|
|
<a href="../api_cxx/db_open.html">Db::open</a> for more information.</p>
|
|
<p>The DB_BEFORE flag may not be specified to the Queue access method.</p>
|
|
<p>The Dbc::put method will return <a href="../ref/program/errorret.html#DB_NOTFOUND">DB_NOTFOUND</a> if the current cursor record has already been deleted and the underlying
|
|
access method is Hash.
|
|
</p></ul>
|
|
<b><a name="DB_CURRENT">DB_CURRENT</a></b><ul compact><li>Overwrite the data of the key/data pair to which the cursor refers with
|
|
the specified data item. The <b>key</b> parameter is ignored.
|
|
<p>The Dbc::put method will return <a href="../ref/program/errorret.html#DB_NOTFOUND">DB_NOTFOUND</a> if the current cursor record has already been deleted.
|
|
</p></ul>
|
|
<b><a name="DB_KEYFIRST">DB_KEYFIRST</a></b><ul compact><li>Insert the specified key/data pair into the database.
|
|
<p>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.</p></ul>
|
|
<b><a name="DB_KEYLAST">DB_KEYLAST</a></b><ul compact><li>Insert the specified key/data pair into the database.
|
|
<p>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.</p></ul>
|
|
<b><a name="DB_NODUPDATA">DB_NODUPDATA</a></b><ul compact><li>In the case of the Btree and Hash access methods, insert the specified
|
|
key/data pair into the database, unless a key/data pair comparing
|
|
equally to it already exists in the database. If a matching key/data
|
|
pair already exists in the database, <a href="../api_cxx/dbc_put.html#DB_KEYEXIST">DB_KEYEXIST</a> is returned.
|
|
The DB_NODUPDATA flag may only be specified if the underlying
|
|
database has been configured to support sorted duplicate data items.
|
|
<p>The DB_NODUPDATA flag may not be specified to the Queue or Recno
|
|
access methods.</p></ul>
|
|
<br></ul>
|
|
<b>key</b><ul compact><li>The key <a href="../api_cxx/dbt_class.html">Dbt</a> operated on.</ul>
|
|
<br>
|
|
<br><b>Errors</b>
|
|
<p>The Dbc::put method
|
|
may fail and throw
|
|
<a href="../api_cxx/except_class.html">DbException</a>,
|
|
encapsulating one of the following non-zero errors, or return one of
|
|
the following non-zero errors:</p>
|
|
<br>
|
|
<b>DB_REP_HANDLE_DEAD</b><ul compact><li>The database handle has been invalidated because a replication election
|
|
unrolled a committed transaction.</ul>
|
|
<br>
|
|
<br>
|
|
<b>DB_REP_LOCKOUT</b><ul compact><li>The operation was blocked by client/master synchronization.</ul>
|
|
<br>
|
|
<br>
|
|
<b>EACCES</b><ul compact><li>An attempt was made to modify a read-only database.</ul>
|
|
<br>
|
|
<br>
|
|
<b>EINVAL</b><ul compact><li>If the DB_AFTER, DB_BEFORE or DB_CURRENT flags
|
|
were specified and the cursor has not been initialized;
|
|
the DB_AFTER or DB_BEFORE flags were specified and a
|
|
duplicate sort function has been specified;
|
|
the DB_CURRENT flag was specified, a duplicate sort function has
|
|
been specified, and the data item of the referenced key/data pair does
|
|
not compare equally to the <b>data</b> parameter;
|
|
the DB_AFTER or DB_BEFORE 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; or if an
|
|
invalid flag value or parameter was specified.</ul>
|
|
<br>
|
|
<br>
|
|
<b>EPERM </b><ul compact><li>Write attempted on read-only cursor when the <a href="../api_cxx/env_open.html#DB_INIT_CDB">DB_INIT_CDB</a> flag was
|
|
specified to <a href="../api_cxx/env_open.html">DbEnv::open</a>.</ul>
|
|
<br>
|
|
<p>If a transactional database environment operation was selected to
|
|
resolve a deadlock, the Dbc::put method will fail and
|
|
either return <a href="../ref/program/errorret.html#DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a> or
|
|
throw a <a href="../api_cxx/deadlock_class.html">DbDeadlockException</a> exception.</p>
|
|
<p>If a Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable
|
|
to grant a lock in the allowed time, the Dbc::put method will fail and
|
|
either return <a href="../ref/program/errorret.html#DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a> or
|
|
throw a <a href="../api_cxx/lockng_class.html">DbLockNotGrantedException</a> exception.</p>
|
|
<hr size=1 noshade>
|
|
<br><b>Class</b>
|
|
<a href="../api_cxx/dbc_class.html">Dbc</a>
|
|
<br><b>See Also</b>
|
|
<a href="../api_cxx/dbc_list.html">Database Cursors and Related Methods</a>
|
|
</tt>
|
|
<table width="100%"><tr><td><br></td><td align=right>
|
|
<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a>
|
|
</td></tr></table>
|
|
<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font>
|
|
</body>
|
|
</html>
|