1<!--$Id: dbc_put.so,v 10.64 2007/10/24 16:06:07 bostic Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB: Dbc::put</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<table width="100%"><tr valign=top> 12<td> 13<b>Dbc::put</b> 14</td> 15<td align=right> 16<a href="../api_cxx/api_core.html"><img src="../images/api.gif" alt="API"></a> 17<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td> 18</tr></table> 19<hr size=1 noshade> 20<tt> 21<b><pre> 22#include <db_cxx.h> 23<p> 24int 25Dbc::put(Dbt *key, Dbt *data, u_int32_t flags); 26</pre></b> 27<hr size=1 noshade> 28<b>Description: Dbc::put</b> 29<p>The Dbc::put method stores key/data pairs into the database.</p> 30<p>Unless otherwise specified, the Dbc::put method 31either returns a non-zero error value 32or throws an exception that encapsulates a non-zero error value on 33failure, and returns 0 on success. 34</p> 35<p>If Dbc::put fails for any reason, the state of the cursor will be 36unchanged. If Dbc::put succeeds and an item is inserted into the 37database, the cursor is always positioned to refer to the newly inserted 38item.</p> 39<b>Parameters</b> <br> 40 <b>data</b><ul compact><li>The data <a href="../api_cxx/dbt_class.html">Dbt</a> operated on.</ul> 41 <b>flags</b><ul compact><li>The <b>flags</b> parameter must be set to one of the following values: 42<br> 43<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 44element as a duplicate element of the key to which the cursor refers. 45The new element appears immediately after the current cursor position. 46It is an error to specify DB_AFTER if the underlying Btree or 47Hash database is not configured for unsorted duplicate data items. The 48<b>key</b> parameter is ignored. 49<p>In the case of the Recno access method, it is an error to specify 50DB_AFTER if the underlying Recno database was not created with 51the <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 52specified, a new key is created, all records after the inserted item 53are automatically renumbered, and the key of the new record is returned 54in the structure to which the <b>key</b> parameter refers. The initial 55value of the <b>key</b> parameter is ignored. See <a href="../api_cxx/db_open.html">Db::open</a> 56for more information.</p> 57<p>The DB_AFTER flag may not be specified to the Queue access method.</p> 58<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 59underlying access method is Hash. 60</p></ul> 61<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 62element as a duplicate element of the key to which the cursor refers. 63The new element appears immediately before the current cursor position. 64It is an error to specify DB_AFTER if the underlying Btree or 65Hash database is not configured for unsorted duplicate data items. The 66<b>key</b> parameter is ignored. 67<p>In the case of the Recno access method, it is an error to specify 68DB_BEFORE if the underlying Recno database was not created with 69the <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 70specified, a new key is created, the current record and all records 71after it are automatically renumbered, and the key of the new record is 72returned in the structure to which the <b>key</b> parameter refers. 73The initial value of the <b>key</b> parameter is ignored. See 74<a href="../api_cxx/db_open.html">Db::open</a> for more information.</p> 75<p>The DB_BEFORE flag may not be specified to the Queue access method.</p> 76<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 77access method is Hash. 78</p></ul> 79<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 80the specified data item. The <b>key</b> parameter is ignored. 81<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. 82</p></ul> 83<b><a name="DB_KEYFIRST">DB_KEYFIRST</a></b><ul compact><li>Insert the specified key/data pair into the database. 84<p>If the underlying database supports duplicate data items, and if the 85key already exists in the database and a duplicate sort function has 86been specified, the inserted data item is added in its sorted location. 87If the key already exists in the database and no duplicate sort function 88has been specified, the inserted data item is added as the first of the 89data items for that key.</p></ul> 90<b><a name="DB_KEYLAST">DB_KEYLAST</a></b><ul compact><li>Insert the specified key/data pair into the database. 91<p>If the underlying database supports duplicate data items, and if the 92key already exists in the database and a duplicate sort function has 93been specified, the inserted data item is added in its sorted location. 94If the key already exists in the database, and no duplicate sort 95function has been specified, the inserted data item is added as the last 96of the data items for that key.</p></ul> 97<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 98key/data pair into the database, unless a key/data pair comparing 99equally to it already exists in the database. If a matching key/data 100pair already exists in the database, <a href="../api_cxx/dbc_put.html#DB_KEYEXIST">DB_KEYEXIST</a> is returned. 101The DB_NODUPDATA flag may only be specified if the underlying 102database has been configured to support sorted duplicate data items. 103<p>The DB_NODUPDATA flag may not be specified to the Queue or Recno 104access methods.</p></ul> 105<br></ul> 106 <b>key</b><ul compact><li>The key <a href="../api_cxx/dbt_class.html">Dbt</a> operated on.</ul> 107<br> 108<br><b>Errors</b> 109<p>The Dbc::put method 110may fail and throw 111<a href="../api_cxx/except_class.html">DbException</a>, 112encapsulating one of the following non-zero errors, or return one of 113the following non-zero errors:</p> 114<br> 115<b>DB_REP_HANDLE_DEAD</b><ul compact><li>The database handle has been invalidated because a replication election 116unrolled a committed transaction.</ul> 117<br> 118<br> 119<b>DB_REP_LOCKOUT</b><ul compact><li>The operation was blocked by client/master synchronization.</ul> 120<br> 121<br> 122<b>EACCES</b><ul compact><li>An attempt was made to modify a read-only database.</ul> 123<br> 124<br> 125<b>EINVAL</b><ul compact><li>If the DB_AFTER, DB_BEFORE or DB_CURRENT flags 126were specified and the cursor has not been initialized; 127the DB_AFTER or DB_BEFORE flags were specified and a 128duplicate sort function has been specified; 129the DB_CURRENT flag was specified, a duplicate sort function has 130been specified, and the data item of the referenced key/data pair does 131not compare equally to the <b>data</b> parameter; 132the DB_AFTER or DB_BEFORE flags were specified, and the 133underlying access method is Queue; 134an attempt was made to add a record to a fixed-length database that was too 135large to fit; 136an attempt was made to add a record to a secondary index; or if an 137invalid flag value or parameter was specified.</ul> 138<br> 139<br> 140<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 141specified to <a href="../api_cxx/env_open.html">DbEnv::open</a>.</ul> 142<br> 143<p>If a transactional database environment operation was selected to 144resolve a deadlock, the Dbc::put method will fail and 145either return <a href="../ref/program/errorret.html#DB_LOCK_DEADLOCK">DB_LOCK_DEADLOCK</a> or 146throw a <a href="../api_cxx/deadlock_class.html">DbDeadlockException</a> exception.</p> 147<p>If a Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable 148to grant a lock in the allowed time, the Dbc::put method will fail and 149either return <a href="../ref/program/errorret.html#DB_LOCK_NOTGRANTED">DB_LOCK_NOTGRANTED</a> or 150throw a <a href="../api_cxx/lockng_class.html">DbLockNotGrantedException</a> exception.</p> 151<hr size=1 noshade> 152<br><b>Class</b> 153<a href="../api_cxx/dbc_class.html">Dbc</a> 154<br><b>See Also</b> 155<a href="../api_cxx/dbc_list.html">Database Cursors and Related Methods</a> 156</tt> 157<table width="100%"><tr><td><br></td><td align=right> 158<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> 159</td></tr></table> 160<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 161</body> 162</html> 163