Debian Codegraph @

docs/api_reference/CXX/dbput.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Db::put()</title>
7 <link rel="stylesheet" href="apiReference.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Berkeley DB C++ API Reference" />
10 <link rel="up" href="db.html" title="Chapter 2.  The Db Handle" />
11 <link rel="prev" href="dbopen.html" title="Db::open()" />
12 <link rel="next" href="dbremove.html" title="Db::remove()" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Db::put()</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="dbopen.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 2. 
26 The Db Handle
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="dbremove.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="dbput"></a>Db::put()</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#include &lt;db_cxx.h&gt;
42
43 int
44 Db::put(DbTxn *txnid, Dbt *key, Dbt *data, u_int32_t flags);</pre>
45 <p>
46 The <code class="methodname">Db::put()</code> method stores key/data
47 pairs in the database. The default behavior of the
48 <code class="methodname">Db::put()</code> function is to enter the new
49 key/data pair, replacing any previously existing key if duplicates
50 are disallowed, or adding a duplicate data item if duplicates are
51 allowed. If the database supports duplicates, the
52 <code class="methodname">Db::put()</code> method adds the new data value
53 at the end of the duplicate set. If the database supports sorted
54 duplicates, the new data value is inserted at the correct sorted
55 location.
56 </p>
57 <p>
58 Unless otherwise specified, the
59 <code class="methodname">Db::put()</code> <span>
60
61 <span>
62 method either returns a non-zero error value or throws an
63 exception that encapsulates a non-zero error value on
64 failure, and returns 0 on success.
65 </span>
66 </span>
67 </p>
68 <div class="sect2" lang="en" xml:lang="en">
69 <div class="titlepage">
70 <div>
71 <div>
72 <h3 class="title"><a id="idm573432"></a>Parameters</h3>
73 </div>
74 </div>
75 </div>
76 <div class="sect3" lang="en" xml:lang="en">
77 <div class="titlepage">
78 <div>
79 <div>
80 <h4 class="title"><a id="idp3631152"></a>txnid</h4>
81 </div>
82 </div>
83 </div>
84 <p>
85 If the operation is part of an application-specified
86 transaction, the <span class="bold"><strong>txnid</strong></span>
87 parameter is a transaction handle returned from
88 <a class="xref" href="txnbegin.html" title="DbEnv::txn_begin()">DbEnv::txn_begin()</a>; if
89 the operation is part of a Berkeley DB Concurrent Data
90 Store group, the <span class="bold"><strong>txnid</strong></span>
91 parameter is a handle returned from
92 <a class="xref" href="envcdsgroup_begin.html" title="DbEnv::cdsgroup_begin()">DbEnv::cdsgroup_begin()</a>;
93 otherwise NULL. If no transaction handle is specified,
94 but the operation occurs in a transactional database, the
95 operation will be implicitly transaction protected.
96 </p>
97 </div>
98 <div class="sect3" lang="en" xml:lang="en">
99 <div class="titlepage">
100 <div>
101 <div>
102 <h4 class="title"><a id="idm219240"></a>key</h4>
103 </div>
104 </div>
105 </div>
106 <p>
107 The key <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> operated on.
108 </p>
109 <p>
110 If creating a new record in a Heap database, the
111 key <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>
112 must be empty. The <code class="literal">put</code>
113 method will return the new record's
114 <a class="link" href="db_heap_rid.html" title="DbHeapRecordId">Record ID (RID)</a>
115 in the key <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>.
116 </p>
117 </div>
118 <div class="sect3" lang="en" xml:lang="en">
119 <div class="titlepage">
120 <div>
121 <div>
122 <h4 class="title"><a id="idp1230496"></a>data</h4>
123 </div>
124 </div>
125 </div>
126 <p>
127 The data <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> operated on.
128 </p>
129 </div>
130 <div class="sect3" lang="en" xml:lang="en">
131 <div class="titlepage">
132 <div>
133 <div>
134 <h4 class="title"><a id="idp1617704"></a>flags</h4>
135 </div>
136 </div>
137 </div>
138 <p>
139 The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
140 or one of the following values:
141 </p>
142 <div class="itemizedlist">
143 <ul type="disc">
144 <li>
145 <p><a id="dbput_DB_APPEND"></a>
146 <code class="literal">DB_APPEND</code>
147 </p>
148 <p>
149 Append the key/data pair to the end of the
150 database. For the DB_APPEND flag to be specified,
151 the underlying database must be a Heap, Queue or
152 Recno database. The record number allocated to
153 the record is returned in the specified
154 <span class="bold"><strong>key</strong></span>.
155 </p>
156 <p>
157 There is a minor behavioral difference between the Recno
158 and Queue access methods for the DB_APPEND flag. If a
159 transaction enclosing a
160 <code class="methodname">Db::put()</code> operation with the
161 DB_APPEND flag aborts, the record number may be
162 reallocated in a subsequent <code class="literal">DB_APPEND</code>
163 operation if you are using the Recno access method, but it
164 will not be reallocated if you are using the Queue access
165 method.
166 </p>
167 <p>
168 For a Heap database, if the put operation results
169 in the creation of a new record, then this flag is
170 required.
171 </p>
172 </li>
173 <li>
174 <p><a id="put_DB_NODUPDATA"></a>
175 <code class="literal">DB_NODUPDATA</code>
176 </p>
177 <p>
178 In the case of the Btree and Hash access methods,
179 enter the new key/data pair only if it does not
180 already appear in the database.
181 </p>
182 <p>
183 The DB_NODUPDATA flag may only be specified if the
184 underlying database has been configured to support
185 sorted duplicates. The DB_NODUPDATA flag may not
186 be specified to the Queue or Recno access methods.
187 </p>
188 <p>
189 The <code class="methodname">Db::put()</code> method will return
190 <a class="xref" href="dbcput.html#dbcput_DB_KEYEXIST" title="DB_KEYEXIST">DB_KEYEXIST</a>
191 if DB_NODUPDATA is set and the key/data pair already appears in the
192 database.
193 </p>
194 </li>
195 <li>
196 <p><a id="put_DB_NOOVERWRITE"></a>
197 <code class="literal">DB_NOOVERWRITE</code>
198 </p>
199 <p>
200 Enter the new key/data pair only if the key does
201 not already appear in the database. The
202 <code class="methodname">Db::put()</code> method call
203 with the DB_NOOVERWRITE flag set will fail if the
204 key already exists in the database, even if the
205 database supports duplicates.
206 </p>
207 <p>
208 The <code class="methodname">Db::put()</code> method will return
209 <a class="xref" href="dbcput.html#dbcput_DB_KEYEXIST" title="DB_KEYEXIST">DB_KEYEXIST</a>
210 if DB_NOOVERWRITE is set and the key already appears in the database.
211 </p>
212 <p>
213 This enforcement of uniqueness of keys applies only
214 to the primary key. The behavior of insertions
215 into secondary databases is not affected by the
216 DB_NOOVERWRITE flag. In particular, the insertion
217 of a record that would result in the creation of a
218 duplicate key in a secondary database that allows
219 duplicates would not be prevented by the use of
220 this flag.
221 </p>
222 </li>
223 <li>
224 <p><a id="put_DB_MULTIPLE"></a>
225 <code class="literal">DB_MULTIPLE</code>
226 </p>
227 <p>
228 Put multiple data items using keys from the buffer
229 to which the <span class="bold"><strong>key</strong></span>
230 parameter refers and data values from the buffer to
231 which the <span class="bold"><strong>data</strong></span>
232 parameter refers.
233 </p>
234 <p>
235 To put records in bulk with the btree or hash
236 access methods, construct bulk buffers in the
237 <span class="bold"><strong>key</strong></span> and <span class="bold"><strong>data</strong></span> <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> using <a class="xref" href="dbmultipledatabuilder.html" title="DbMultipleDataBuilder">DbMultipleDataBuilder</a>. To
238 put records in bulk with the recno or queue access
239 methods, construct bulk buffers in the <span class="bold"><strong>data</strong></span> <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> as before, but
240 construct the <span class="bold"><strong>key</strong></span>
241 <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> using <a class="xref" href="dbmultiplerecnodatabuilder.html" title="DbMultipleRecnoDataBuilder">DbMultipleRecnoDataBuilder</a>
242 with a data size of zero.
243 </p>
244 <p>
245 A successful bulk operation is logically equivalent
246 to a loop through each key/data pair, performing a
247 <a class="xref" href="dbput.html" title="Db::put()">Db::put()</a> for each one.
248 </p>
249 <p>
250 See
251 <a class="xref" href="dbt.html#dbtlist" title="DBT and Bulk Operations">DBT and Bulk Operations</a>
252 for more information on working with bulk
253 updates.
254 </p>
255 <p>
256 The <code class="literal">DB_MULTIPLE</code> flag may only be
257 used alone, or with the
258 <code class="literal">DB_OVERWRITE_DUP</code> option.
259 </p>
260 </li>
261 <li>
262 <p><a id="put_DB_MULTIPLE_KEY"></a>
263 <code class="literal">DB_MULTIPLE_KEY</code>
264 </p>
265 <p>
266 Put multiple data items using keys and data from
267 the buffer to which the <span class="bold"><strong>key</strong></span> parameter refers.
268 </p>
269 <p>
270 To put records in bulk with the btree or hash
271 access methods, construct a bulk buffer in the
272 <span class="bold"><strong>key</strong></span> <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> using <a class="xref" href="dbmultiplekeydatabuilder.html" title="DbMultipleKeyDataBuilder">DbMultipleKeyDataBuilder</a>.
273 To put records in bulk with the recno or queue
274 access methods, construct a bulk
275 buffer in the <span class="bold"><strong>key</strong></span>
276 <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> using <a class="xref" href="dbmultiplerecnodatabuilder.html" title="DbMultipleRecnoDataBuilder">DbMultipleRecnoDataBuilder</a>.
277 </p>
278 <p>
279 See <a class="xref" href="dbt.html#dbtlist" title="DBT and Bulk Operations">DBT and Bulk Operations</a> for more information on working with bulk
280 updates.
281 </p>
282 <p>
283 The <code class="literal">DB_MULTIPLE_KEY</code> flag may
284 only be used alone, or with the
285 <code class="literal">DB_OVERWRITE_DUP</code> option.
286 </p>
287 </li>
288 <li>
289 <p><a id="put_DB_OVERWRITE_DUP"></a>
290 <code class="literal">DB_OVERWRITE_DUP</code>
291 </p>
292 <p>
293 Ignore duplicate records when overwriting records
294 in a database configured for sorted duplicates.
295 </p>
296 <p>
297 Normally, if a database is configured for sorted
298 duplicates, an attempt to put a record that
299 compares identically to a record already existing
300 in the database will fail. Using this flag causes
301 the put to silently proceed, without failure.
302 </p>
303 <p>
304 This flag is extremely useful when performing bulk
305 puts (using the <code class="literal">DB_MULTIPLE</code> or
306 <code class="literal">DB_MULTIPLE_KEY</code> flags).
307 Depending on the number of records you are writing
308 to the database with a bulk put, you may not want
309 the operation to fail in the event that a
310 duplicate record is encountered. Using this flag
311 along with the <code class="literal">DB_MULTIPLE</code> or
312 <code class="literal">DB_MULTIPLE_KEY</code> flags allows
313 the bulk put to complete, even if a duplicate
314 record is encountered.
315 </p>
316 <p>
317 This flag is also useful if you are using a custom
318 comparison function that compares only part of the
319 data portion of a record. In this case, two
320 records can compare equally when, in fact, they
321 are not equal. This flag allows the put to
322 complete, even if your custom comparison routine
323 claims the two records are equal.
324 </p>
325 </li>
326 </ul>
327 </div>
328 </div>
329 </div>
330 <div class="sect2" lang="en" xml:lang="en">
331 <div class="titlepage">
332 <div>
333 <div>
334 <h3 class="title"><a id="idp1907688"></a>Errors</h3>
335 </div>
336 </div>
337 </div>
338 <p>
339 The <code class="methodname">Db::put()</code> <span>
340
341 <span>
342 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a>
343 exception, encapsulating one of the following non-zero errors, or return one
344 of the following non-zero errors:
345 </span>
346 </span>
347 </p>
348 <div class="sect3" lang="en" xml:lang="en">
349 <div class="titlepage">
350 <div>
351 <div>
352 <h4 class="title"><a id="idp3972656"></a>DB_FOREIGN_CONFLICT</h4>
353 </div>
354 </div>
355 </div>
356 <p>
357 A <a class="link" href="dbassociate_foreign.html" title="Db::associate_foreign()">foreign key constraint violation</a>
358 has occurred. This can be caused by one of two things:
359 </p>
360 <div class="orderedlist">
361 <ol type="1">
362 <li>
363 <p>
364 An attempt was made to add a record to a
365 constrained database, and the key used for that
366 record does not exist in the foreign key
367 database.
368 </p>
369 </li>
370 <li>
371 <p>
372 <a class="link" href="dbassociate_foreign.html#associate_foreign_DB_FOREIGN_ABORT">DB_FOREIGN_ABORT</a>
373 was declared for a foreign key database, and then
374 subsequently a record was deleted from the
375 foreign key database without first removing it
376 from the constrained secondary database.
377 </p>
378 </li>
379 </ol>
380 </div>
381 </div>
382 <div class="sect3" lang="en" xml:lang="en">
383 <div class="titlepage">
384 <div>
385 <div>
386 <h4 class="title"><a id="idp2481304"></a>DB_HEAP_FULL</h4>
387 </div>
388 </div>
389 </div>
390 <p>
391 An attempt was made to add or update a record in a Heap
392 database. However, the size of the database was constrained
393 using the
394 <a class="xref" href="dbset_heapsize.html" title="Db::set_heapsize()">Db::set_heapsize()</a>
395 method, and that limit has been reached.
396 </p>
397 </div>
398 <div class="sect3" lang="en" xml:lang="en">
399 <div class="titlepage">
400 <div>
401 <div>
402 <h4 class="title"><a id="idp4300800"></a><span>DbDeadlockException or </span>DB_LOCK_DEADLOCK</h4>
403 </div>
404 </div>
405 </div>
406 <p>
407 A transactional database environment operation was selected to resolve
408 a deadlock.
409 </p>
410 <p>
411 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if
412 your Berkeley DB API is configured to throw exceptions.
413 Otherwise, <code class="literal">DB_LOCK_DEADLOCK</code> is returned.
414 </p>
415 </div>
416 <div class="sect3" lang="en" xml:lang="en">
417 <div class="titlepage">
418 <div>
419 <div>
420 <h4 class="title"><a id="idp1820472"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4>
421 </div>
422 </div>
423 </div>
424 <p>
425 A Berkeley DB Concurrent Data Store database environment configured
426 for lock timeouts was unable to grant a lock in the allowed time.
427 </p>
428 <p>
429 You attempted to open a database handle that is configured
430 for no waiting exclusive locking, but the exclusive lock could not be
431 immediately obtained. See
432 <a class="xref" href="dbset_lk_exclusive.html" title="Db::set_lk_exclusive()">Db::set_lk_exclusive()</a>
433 for more information.
434 </p>
435 <p>
436 <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if
437 your Berkeley DB API is configured to throw exceptions.
438 Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned.
439 </p>
440 </div>
441 <div class="sect3" lang="en" xml:lang="en">
442 <div class="titlepage">
443 <div>
444 <div>
445 <h4 class="title"><a id="idm93440"></a> <span>DbRepHandleDeadException or</span> DB_REP_HANDLE_DEAD</h4>
446 </div>
447 </div>
448 </div>
449 <p>
450 When a client synchronizes with the master, it is possible for committed
451 transactions to be rolled back. This invalidates all the database and cursor
452 handles opened in the replication environment. Once this occurs, an attempt to use
453 such a handle will
454 <span>
455 throw a <a class="xref" href="dbrephandledead.html" title="DbRepHandleDeadException">DbRepHandleDeadException</a> (if
456 your application is configured to throw exceptions), or
457 </span>
458 return <code class="literal">DB_REP_HANDLE_DEAD</code>.
459 The application will need to discard the handle and open a new one in order to
460 continue processing.
461 </p>
462 </div>
463 <a id="dbput_DB_REP_LOCKOUT"></a>
464 <div class="sect3" lang="en" xml:lang="en">
465 <div class="titlepage">
466 <div>
467 <div>
468 <h4 class="title"><a id="idm306912"></a><span>DbDeadlockException or </span>DB_REP_LOCKOUT</h4>
469 </div>
470 </div>
471 </div>
472 <p>
473 The operation was blocked by client/master synchronization.
474 </p>
475 <p>
476 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if
477 your Berkeley DB API is configured to throw exceptions.
478 Otherwise, <code class="literal">DB_REP_LOCKOUT</code> is returned.
479 </p>
480 </div>
481 <div class="sect3" lang="en" xml:lang="en">
482 <div class="titlepage">
483 <div>
484 <div>
485 <h4 class="title"><a id="idm366600"></a>EACCES</h4>
486 </div>
487 </div>
488 </div>
489 <p>
490 An attempt was made to modify a read-only database.
491 </p>
492 </div>
493 <div class="sect3" lang="en" xml:lang="en">
494 <div class="titlepage">
495 <div>
496 <div>
497 <h4 class="title"><a id="idp671256"></a>EINVAL</h4>
498 </div>
499 </div>
500 </div>
501 <p>
502 If a record number of 0 was specified; an attempt was made to add a
503 record to a fixed-length database that was too large to fit; an
504 attempt was made to do a partial put; an attempt was made to add a
505 record to a secondary index; or if an invalid flag value or parameter
506 was specified.
507 </p>
508 </div>
509 <div class="sect3" lang="en" xml:lang="en">
510 <div class="titlepage">
511 <div>
512 <div>
513 <h4 class="title"><a id="idm562800"></a>ENOSPC</h4>
514 </div>
515 </div>
516 </div>
517 <p>
518 A btree exceeded the maximum btree depth (255).
519 </p>
520 </div>
521 </div>
522 <div class="sect2" lang="en" xml:lang="en">
523 <div class="titlepage">
524 <div>
525 <div>
526 <h3 class="title"><a id="idm566984"></a>Class</h3>
527 </div>
528 </div>
529 </div>
530 <p>
531 <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>
532 </p>
533 </div>
534 <div class="sect2" lang="en" xml:lang="en">
535 <div class="titlepage">
536 <div>
537 <div>
538 <h3 class="title"><a id="idp190536"></a>See Also</h3>
539 </div>
540 </div>
541 </div>
542 <p>
543 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a>
544 </p>
545 </div>
546 </div>
547 <div class="navfooter">
548 <hr />
549 <table width="100%" summary="Navigation footer">
550 <tr>
551 <td width="40%" align="left"><a accesskey="p" href="dbopen.html">Prev</a> </td>
552 <td width="20%" align="center">
553 <a accesskey="u" href="db.html">Up</a>
554 </td>
555 <td width="40%" align="right"> <a accesskey="n" href="dbremove.html">Next</a></td>
556 </tr>
557 <tr>
558 <td width="40%" align="left" valign="top">Db::open() </td>
559 <td width="20%" align="center">
560 <a accesskey="h" href="index.html">Home</a>
561 </td>
562 <td width="40%" align="right" valign="top"> Db::remove()</td>
563 </tr>
564 </table>
565 </div>
566 </body>
567 </html>