1
<!--$Id: db_put.so,v 10.37 2001/04/02 00:36:35 bostic Exp $-->
2
<!--Copyright 1997-2001 by Sleepycat Software, Inc.-->
3
<!--All rights reserved.-->
6
<title>Berkeley DB: DB->put</title>
7
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
11
<a name="2"><!--meow--></a>
12
<table width="100%"><tr valign=top>
17
<a href="../api_c/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
26
DB_TXN *txnid, DBT *key, DBT *data, u_int32_t flags);
29
<p>The DB->put function stores key/data pairs in the database. The default
30
behavior of the DB->put function is to enter the new key/data
31
pair, replacing any previously existing key if duplicates are disallowed,
32
or adding a duplicate data item if duplicates are allowed. If the database
33
supports duplicates, the DB->put function adds the new data value at the
34
end of the duplicate set. If the database supports sorted duplicates,
35
the new data value is inserted at the correct sorted location.
36
<p>If the operation is to be transaction-protected, the <b>txnid</b>
37
parameter is a transaction handle returned from <a href="../api_c/txn_begin.html">txn_begin</a>;
39
<p>The <b>flags</b> value must be set to 0 or
40
one of the following values:
42
<p><dt><a name="DB_APPEND">DB_APPEND</a><dd>Append the key/data pair to the end of the database. For the
43
DB_APPEND flag to be specified, the underlying database must be
44
a Queue or Recno database. The record number allocated to the record is
45
returned in the specified <b>key</b>.
46
<p>There is a minor behavioral difference between the Recno and Queue access
47
methods for the DB_APPEND flag. If a transaction enclosing a
48
DB->put operation with the DB_APPEND flag aborts, the
49
record number may be decremented (and later reallocated by a subsequent
50
DB_APPEND operation) by the Recno access method, but will not be
51
decremented or reallocated by the Queue access method.
52
<p><dt><a name="DB_NODUPDATA">DB_NODUPDATA</a><dd>In the case of the Btree and Hash access methods, enter the new key/data
53
pair only if it does not already appear in the database. If the
54
key/data pair already appears in the database, <a href="../api_c/dbc_put.html#DB_KEYEXIST">DB_KEYEXIST</a> is
55
returned. The DB_NODUPDATA flag may only be specified if the
56
underlying database has been configured to support sorted duplicates.
57
<p>The DB_NODUPDATA flag may not be specified to the Queue or Recno
59
<p><dt><a name="DB_NOOVERWRITE">DB_NOOVERWRITE</a><dd>Enter the new key/data pair only if the key does not already appear in
60
the database. If the key already appears in the database,
61
<a href="../api_c/dbc_put.html#DB_KEYEXIST">DB_KEYEXIST</a> is returned. Even if the database allows duplicates,
62
a call to DB->put with the DB_NOOVERWRITE flag set will
63
fail if the key already exists in the database.
65
<p>Otherwise, the DB->put function returns a non-zero error value on failure and 0 on success.
67
<p>The DB->put function may fail and return a non-zero error for the following conditions:
69
<p><dt>DB_LOCK_DEADLOCK<dd>The operation was selected to resolve a deadlock.
72
<p><dt>EACCES<dd>An attempt was made to modify a read-only database.
75
<p><dt>EINVAL<dd>An invalid flag value or parameter was specified.
76
<p>A record number of 0 was specified.
77
<p>An attempt was made to add a record to a fixed-length database that was too
79
<p>An attempt was made to do a partial put.
80
<p>An attempt was made to add a record to a secondary index.
83
<p><dt>ENOSPC<dd>A btree exceeded the maximum btree depth (255).
85
<p>The DB->put function may fail and return a non-zero error for errors specified for other Berkeley DB and C library or system functions.
86
If a catastrophic error has occurred, the DB->put function may fail and return
87
<a href="../ref/program/errorret.html#DB_RUNRECOVERY">DB_RUNRECOVERY</a>, in which case all subsequent Berkeley DB calls will fail
90
<a href="../api_c/db_create.html">db_create</a>,
91
<a href="../api_c/db_associate.html">DB->associate</a>,
92
<a href="../api_c/db_close.html">DB->close</a>,
93
<a href="../api_c/db_cursor.html">DB->cursor</a>,
94
<a href="../api_c/db_del.html">DB->del</a>,
95
<a href="../api_c/db_err.html">DB->err</a>, <a href="../api_c/db_err.html">DB->errx</a>
96
<a href="../api_c/db_fd.html">DB->fd</a>,
97
<a href="../api_c/db_get.html">DB->get</a>,
98
<a href="../api_c/db_get.html">DB->pget</a>,
99
<a href="../api_c/db_get_byteswapped.html">DB->get_byteswapped</a>,
100
<a href="../api_c/db_get_type.html">DB->get_type</a>,
101
<a href="../api_c/db_join.html">DB->join</a>,
102
<a href="../api_c/db_key_range.html">DB->key_range</a>,
103
<a href="../api_c/db_open.html">DB->open</a>,
104
<a href="../api_c/db_put.html">DB->put</a>,
105
<a href="../api_c/db_remove.html">DB->remove</a>,
106
<a href="../api_c/db_rename.html">DB->rename</a>,
107
<a href="../api_c/db_set_alloc.html">DB->set_alloc</a>,
108
<a href="../api_c/db_set_append_recno.html">DB->set_append_recno</a>,
109
<a href="../api_c/db_set_bt_compare.html">DB->set_bt_compare</a>,
110
<a href="../api_c/db_set_bt_minkey.html">DB->set_bt_minkey</a>,
111
<a href="../api_c/db_set_bt_prefix.html">DB->set_bt_prefix</a>,
112
<a href="../api_c/db_set_cachesize.html">DB->set_cachesize</a>,
113
<a href="../api_c/db_set_dup_compare.html">DB->set_dup_compare</a>,
114
<a href="../api_c/db_set_errcall.html">DB->set_errcall</a>,
115
<a href="../api_c/db_set_errfile.html">DB->set_errfile</a>,
116
<a href="../api_c/db_set_errpfx.html">DB->set_errpfx</a>,
117
<a href="../api_c/db_set_feedback.html">DB->set_feedback</a>,
118
<a href="../api_c/db_set_flags.html">DB->set_flags</a>,
119
<a href="../api_c/db_set_h_ffactor.html">DB->set_h_ffactor</a>,
120
<a href="../api_c/db_set_h_hash.html">DB->set_h_hash</a>,
121
<a href="../api_c/db_set_h_nelem.html">DB->set_h_nelem</a>,
122
<a href="../api_c/db_set_lorder.html">DB->set_lorder</a>,
123
<a href="../api_c/db_set_pagesize.html">DB->set_pagesize</a>,
124
<a href="../api_c/db_set_paniccall.html">DB->set_paniccall</a>,
125
<a href="../api_c/db_set_q_extentsize.html">DB->set_q_extentsize</a>,
126
<a href="../api_c/db_set_re_delim.html">DB->set_re_delim</a>,
127
<a href="../api_c/db_set_re_len.html">DB->set_re_len</a>,
128
<a href="../api_c/db_set_re_pad.html">DB->set_re_pad</a>,
129
<a href="../api_c/db_set_re_source.html">DB->set_re_source</a>,
130
<a href="../api_c/db_stat.html">DB->stat</a>,
131
<a href="../api_c/db_sync.html">DB->sync</a>,
132
<a href="../api_c/db_truncate.html">DB->truncate</a>,
133
<a href="../api_c/db_upgrade.html">DB->upgrade</a>,
135
<a href="../api_c/db_verify.html">DB->verify</a>.
137
<table width="100%"><tr><td><br></td><td align=right>
138
<a href="../api_c/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
140
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>