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