1<!--$Id: dbc_put.so,v 11.18 2004/12/02 18:21:08 bostic Exp $-->
2<!--$Id: m4.tcl,v 11.28 2004/12/16 19:13:05 bostic Exp $-->
3<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
4<!--See the file LICENSE for redistribution information.-->
5<html>
6<head>
7<title>Berkeley DB: dbc put</title>
8<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
9<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
10</head>
11<body bgcolor=white>
12<table width="100%"><tr valign=top>
13<td>
14<b><i>dbc</i> <b>put</b></b>
15</td>
16<td align=right>
17<a href="../api_tcl/api_tcl.html"><img src="../images/api.gif" alt="API"></a>
18<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td>
19</tr></table>
20<hr size=1 noshade>
21<tt>
22<b><pre>dbc put
23	[-after]
24	[-before]
25	[-current]
26	[-partial {doff dlen}]
27	data
28dbc put
29	[-keyfirst]
30	[-keylast]
31	[-partial {doff dlen}]
32	key data
33</pre></b>
34<b>Description(dbc put)</b>
35<p>The <i>dbc</i> <b>put</b> command stores the specified key/data pair into the
36database.  One of the following options must be specified:</p>
37<br>
38<b>-after</b><ul compact><li>In the case of the Btree and Hash access methods, insert the data element
39as a duplicate element of the key to which the cursor refers. The new
40element appears immediately after the current cursor position. It is an
41error to specify <b>-after</b> if the underlying Btree or Hash database
42was not created with the <b>-dup</b> option. No key argument should be
43specified.
44<p>In the case of the Recno access method, it is an error to specify the
45<b>-after</b> option if the underlying Recno database was not created
46with the <b>-renumber</b> option.  If the <b>-renumber</b> option was
47specified, a new key is created, all records after the inserted item
48are automatically renumbered, and the key of the new record is returned
49in the structure to which the key argument refers. The initial value of
50the key parameter is ignored. See <b>berkdb open</b> for more information.</p>
51<p>In the case of the Queue access method, it is always an error to specify
52<b>-after</b>.</p>
53<p>If the current cursor record has already been deleted, and the underlying
54access method is Hash, <i>dbc</i> <b>put</b> will throw a Tcl error. If the
55underlying access method is Btree or Recno, the operation will succeed.</p></ul>
56<b>-before</b><ul compact><li>In the case of the Btree and Hash access methods, insert the data element
57as a duplicate element of the key to which the cursor refers. The new
58element appears immediately before the current cursor position. It is an
59error to specify <b>-before</b> if the underlying Btree or Hash database
60was not created with the <b>-dup</b> option. No key argument should be
61specified.
62<p>In the case of the Recno access method, it is an error to specify
63<b>-before</b> if the underlying Recno database was not created with the
64<b>-before</b> option.  If the <b>-before</b> option was specified, a
65new key is created, the current record and all records after it are
66automatically renumbered, and the key of the new record is returned in
67the structure to which the key argument refers.  The initial value of the
68key parameter is ignored. See <b>berkdb open</b> for more information.</p>
69<p>In the case of the Queue access method, it is always an error to specify
70<b>-before</b>.</p>
71<p>If the current cursor record has already been deleted and the underlying
72access method is Hash, <i>dbc</i> <b>put</b> will throw a Tcl error. If the
73underlying access method is Btree or Recno, the operation will succeed.</p></ul>
74<b>-current</b><ul compact><li>Overwrite the data of the key/data pair to which the cursor refers with
75the specified data item.  No key argument should be specified.
76<p>If the <b>-dupsort</b> option was specified to <b>berkdb open</b> and the
77data item of the key/data pair to which the cursor refers does not
78compare equally to the data parameter, <i>dbc</i> <b>put</b> will throw a Tcl
79error.</p>
80<p>If the current cursor record has already been deleted and the underlying
81access method is Hash, <i>dbc</i> <b>put</b> will throw a Tcl error. If the
82underlying access method is Btree, Queue, or Recno, the operation will
83succeed.</p></ul>
84<b>-keyfirst</b><ul compact><li>In the case of the Btree and Hash access methods, insert the specified
85key/data pair into the database.
86<p>If the key already exists in the database, and the <b>-dupsort</b> option
87was specified to <b>berkdb open</b>, the inserted data item is added in its
88sorted location.  If the key already exists in the database, and the
89<b>-dupsort</b> option was not specified, the inserted data item is added
90as the first of the data items for that key.</p>
91<p>The <b>-keyfirst</b> option may not be specified to the Queue or Recno
92access methods.</p></ul>
93<b>-keylast</b><ul compact><li>In the case of the Btree and Hash access methods, insert the specified
94key/data pair into the database.
95<p>If the key already exists in the database, and the <b>-dupsort</b> option
96was specified to <b>berkdb open</b>, the inserted data item is added in its
97sorted location.  If the key already exists in the database, and the
98<b>-dupsort</b> option was not specified, the inserted data item is added
99as the last of the data items for that key.</p>
100<p>The <b>-keylast</b> option may not be specified to the Queue or Recno
101access methods.</p></ul>
102<b>-partial {doff dlen}</b><ul compact><li><p>The <b>dlen</b> bytes starting <b>doff</b> bytes from the beginning
103of the specified key's data record are replaced by the data specified
104by the data and size structure elements.  If <b>dlen</b> is smaller
105than the length of the supplied data, the record will grow; if
106<b>dlen</b> is larger than the length of the supplied data, the record
107will shrink.  If the specified bytes do not exist, the record will be
108extended using nul bytes as necessary, and the <i>dbc</i> <b>put</b> call will succeed.
109</p>
110<p>It is an error to attempt a partial put using the <i>dbc</i> <b>put</b> command in a database
111that supports duplicate records. Partial puts in databases supporting
112duplicate records must be done using a <i>dbc</i> <b>put</b> command.</p>
113<p>It is an error to attempt a partial put with differing <b>dlen</b> and
114supplied data length values in Queue or Recno databases with fixed-length
115records.</p></ul>
116<br>
117<p>If a key is specified, and
118if the underlying database is a Queue or Recno database, the given key
119will be interpreted by Tcl as an integer.  For all other database types,
120the key is interpreted by Tcl as a byte array.</p>
121<p>If <i>dbc</i> <b>put</b> fails for any reason, the state of the cursor will be
122unchanged. If <i>dbc</i> <b>put</b> succeeds and an item is inserted into the
123database, the cursor is always positioned to refer to the newly inserted
124item.</p>
125<p>The <i>dbc</i> <b>put</b> command returns 0 on success, and in the case of error, a Tcl error
126is thrown.</p>
127</tt>
128<table width="100%"><tr><td><br></td><td align=right>
129<a href="../api_tcl/api_tcl.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a>
130</td></tr></table>
131<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
132</body>
133</html>
134