Debian Codegraph @

docs/api_reference/C/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-&gt;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-&gt;open()" />
12 <link rel="next" href="dbremove.html" title="DB-&gt;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-&gt;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-&gt;put()</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#include &lt;db.h&gt;
42
43 int
44 DB-&gt;put(DB *db,
45 DB_TXN *txnid, DBT *key, DBT *data, u_int32_t flags); </pre>
46 <p>
47 The <code class="methodname">DB-&gt;put()</code> method stores key/data
48 pairs in the database. The default behavior of the
49 <code class="methodname">DB-&gt;put()</code> function is to enter the new
50 key/data pair, replacing any previously existing key if duplicates
51 are disallowed, or adding a duplicate data item if duplicates are
52 allowed. If the database supports duplicates, the
53 <code class="methodname">DB-&gt;put()</code> method adds the new data value
54 at the end of the duplicate set. If the database supports sorted
55 duplicates, the new data value is inserted at the correct sorted
56 location.
57 </p>
58 <p>
59 Unless otherwise specified, the
60 <code class="methodname">DB-&gt;put()</code> <span>
61 <span>
62 method returns a non-zero error value on failure and 0 on success.
63 </span>
64
65 </span>
66 </p>
67 <div class="sect2" lang="en" xml:lang="en">
68 <div class="titlepage">
69 <div>
70 <div>
71 <h3 class="title"><a id="idp49947912"></a>Parameters</h3>
72 </div>
73 </div>
74 </div>
75 <div class="sect3" lang="en" xml:lang="en">
76 <div class="titlepage">
77 <div>
78 <div>
79 <h4 class="title"><a id="idp49948104"></a>txnid</h4>
80 </div>
81 </div>
82 </div>
83 <p>
84 If the operation is part of an application-specified
85 transaction, the <span class="bold"><strong>txnid</strong></span>
86 parameter is a transaction handle returned from
87 <a class="xref" href="txnbegin.html" title="DB_ENV-&gt;txn_begin()">DB_ENV-&gt;txn_begin()</a>; if
88 the operation is part of a Berkeley DB Concurrent Data
89 Store group, the <span class="bold"><strong>txnid</strong></span>
90 parameter is a handle returned from
91 <a class="xref" href="envcdsgroup_begin.html" title="DB_ENV-&gt;cdsgroup_begin()">DB_ENV-&gt;cdsgroup_begin()</a>;
92 otherwise NULL. If no transaction handle is specified,
93 but the operation occurs in a transactional database, the
94 operation will be implicitly transaction protected.
95 </p>
96 </div>
97 <div class="sect3" lang="en" xml:lang="en">
98 <div class="titlepage">
99 <div>
100 <div>
101 <h4 class="title"><a id="idp49874432"></a>key</h4>
102 </div>
103 </div>
104 </div>
105 <p>
106 The key <a class="link" href="dbt.html" title="Chapter 4.  The DBT Handle">DBT</a> operated on.
107 </p>
108 <p>
109 If creating a new record in a Heap database, the
110 key <a class="link" href="dbt.html" title="Chapter 4.  The DBT Handle">DBT</a>
111 must be empty. The <code class="literal">put</code>
112 method will return the new record's
113 <a class="link" href="db_heap_rid.html" title="DB_HEAP_RID">Record ID (RID)</a>
114 in the key <a class="link" href="dbt.html" title="Chapter 4.  The DBT Handle">DBT</a>.
115 </p>
116 </div>
117 <div class="sect3" lang="en" xml:lang="en">
118 <div class="titlepage">
119 <div>
120 <div>
121 <h4 class="title"><a id="idp49892680"></a>data</h4>
122 </div>
123 </div>
124 </div>
125 <p>
126 The data <a class="link" href="dbt.html" title="Chapter 4.  The DBT Handle">DBT</a> operated on.
127 </p>
128 </div>
129 <div class="sect3" lang="en" xml:lang="en">
130 <div class="titlepage">
131 <div>
132 <div>
133 <h4 class="title"><a id="idp49942656"></a>flags</h4>
134 </div>
135 </div>
136 </div>
137 <p>
138 The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
139 or one of the following values:
140 </p>
141 <div class="itemizedlist">
142 <ul type="disc">
143 <li>
144 <p><a id="dbput_DB_APPEND"></a>
145 <code class="literal">DB_APPEND</code>
146 </p>
147 <p>
148 Append the key/data pair to the end of the
149 database. For the DB_APPEND flag to be specified,
150 the underlying database must be a Heap, Queue or
151 Recno database. The record number allocated to
152 the record is returned in the specified
153 <span class="bold"><strong>key</strong></span>.
154 </p>
155 <p>
156 There is a minor behavioral difference between the Recno
157 and Queue access methods for the DB_APPEND flag. If a
158 transaction enclosing a
159 <code class="methodname">DB-&gt;put()</code> operation with the
160 DB_APPEND flag aborts, the record number may be
161 reallocated in a subsequent <code class="literal">DB_APPEND</code>
162 operation if you are using the Recno access method, but it
163 will not be reallocated if you are using the Queue access
164 method.
165 </p>
166 <p>
167 For a Heap database, if the put operation results
168 in the creation of a new record, then this flag is
169 required.
170 </p>
171 </li>
172 <li>
173 <p><a id="put_DB_NODUPDATA"></a>
174 <code class="literal">DB_NODUPDATA</code>
175 </p>
176 <p>
177 In the case of the Btree and Hash access methods,
178 enter the new key/data pair only if it does not
179 already appear in the database.
180 </p>
181 <p>
182 The DB_NODUPDATA flag may only be specified if the
183 underlying database has been configured to support
184 sorted duplicates. The DB_NODUPDATA flag may not
185 be specified to the Queue or Recno access methods.
186 </p>
187 <p>
188 The <code class="methodname">DB-&gt;put()</code> method will return
189 <a class="xref" href="dbcput.html#dbcput_DB_KEYEXIST" title="DB_KEYEXIST">DB_KEYEXIST</a>
190 if DB_NODUPDATA is set and the key/data pair already appears in the
191 database.
192 </p>
193 </li>
194 <li>
195 <p><a id="put_DB_NOOVERWRITE"></a>
196 <code class="literal">DB_NOOVERWRITE</code>
197 </p>
198 <p>
199 Enter the new key/data pair only if the key does
200 not already appear in the database. The
201 <code class="methodname">DB-&gt;put()</code> method call
202 with the DB_NOOVERWRITE flag set will fail if the
203 key already exists in the database, even if the
204 database supports duplicates.
205 </p>
206 <p>
207 The <code class="methodname">DB-&gt;put()</code> method will return
208 <a class="xref" href="dbcput.html#dbcput_DB_KEYEXIST" title="DB_KEYEXIST">DB_KEYEXIST</a>
209 if DB_NOOVERWRITE is set and the key already appears in the database.
210 </p>
211 <p>
212 This enforcement of uniqueness of keys applies only
213 to the primary key. The behavior of insertions
214 into secondary databases is not affected by the
215 DB_NOOVERWRITE flag. In particular, the insertion
216 of a record that would result in the creation of a
217 duplicate key in a secondary database that allows
218 duplicates would not be prevented by the use of
219 this flag.
220 </p>
221 </li>
222 <li>
223 <p><a id="put_DB_MULTIPLE"></a>
224 <code class="literal">DB_MULTIPLE</code>
225 </p>
226 <p>
227 Put multiple data items using keys from the buffer
228 to which the <span class="bold"><strong>key</strong></span>
229 parameter refers and data values from the buffer to
230 which the <span class="bold"><strong>data</strong></span>
231 parameter refers.
232 </p>
233 <p>
234 To put records in bulk with the btree or hash
235 access methods, construct bulk buffers in the
236 <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="DB_MULTIPLE_WRITE_INIT.html" title="DB_MULTIPLE_WRITE_INIT">DB_MULTIPLE_WRITE_INIT</a> and
237 <a class="xref" href="DB_MULTIPLE_WRITE_NEXT.html" title="DB_MULTIPLE_WRITE_NEXT">DB_MULTIPLE_WRITE_NEXT</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="DB_MULTIPLE_RECNO_WRITE_INIT.html" title="DB_MULTIPLE_RECNO_WRITE_INIT">DB_MULTIPLE_RECNO_WRITE_INIT</a>
242 and <a class="xref" href="DB_MULTIPLE_RECNO_WRITE_NEXT.html" title="DB_MULTIPLE_RECNO_WRITE_NEXT">DB_MULTIPLE_RECNO_WRITE_NEXT</a>
243 with a data size of zero.
244 </p>
245 <p>
246 A successful bulk operation is logically equivalent
247 to a loop through each key/data pair, performing a
248 <a class="xref" href="dbput.html" title="DB-&gt;put()">DB-&gt;put()</a> for each one.
249 </p>
250 <p>
251 See
252 <a class="xref" href="dbt.html#dbtlist" title="DBT and Bulk Operations">DBT and Bulk Operations</a>
253 for more information on working with bulk
254 updates.
255 </p>
256 <p>
257 The <code class="literal">DB_MULTIPLE</code> flag may only be
258 used alone, or with the
259 <code class="literal">DB_OVERWRITE_DUP</code> option.
260 </p>
261 </li>
262 <li>
263 <p><a id="put_DB_MULTIPLE_KEY"></a>
264 <code class="literal">DB_MULTIPLE_KEY</code>
265 </p>
266 <p>
267 Put multiple data items using keys and data from
268 the buffer to which the <span class="bold"><strong>key</strong></span> parameter refers.
269 </p>
270 <p>
271 To put records in bulk with the btree or hash
272 access methods, construct a single bulk buffer in
273 the <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="DB_MULTIPLE_WRITE_INIT.html" title="DB_MULTIPLE_WRITE_INIT">DB_MULTIPLE_WRITE_INIT</a> and
274 <a class="xref" href="DB_MULTIPLE_KEY_WRITE_NEXT.html" title="DB_MULTIPLE_KEY_WRITE_NEXT">DB_MULTIPLE_KEY_WRITE_NEXT</a>.
275 To put records in bulk with the recno or queue
276 access methods, construct a bulk buffer in the
277 <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="DB_MULTIPLE_RECNO_WRITE_INIT.html" title="DB_MULTIPLE_RECNO_WRITE_INIT">DB_MULTIPLE_RECNO_WRITE_INIT</a>
278 and <a class="xref" href="DB_MULTIPLE_RECNO_WRITE_NEXT.html" title="DB_MULTIPLE_RECNO_WRITE_NEXT">DB_MULTIPLE_RECNO_WRITE_NEXT</a>.
279 </p>
280 <p>
281 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
282 updates.
283 </p>
284 <p>
285 The <code class="literal">DB_MULTIPLE_KEY</code> flag may
286 only be used alone, or with the
287 <code class="literal">DB_OVERWRITE_DUP</code> option.
288 </p>
289 </li>
290 <li>
291 <p><a id="put_DB_OVERWRITE_DUP"></a>
292 <code class="literal">DB_OVERWRITE_DUP</code>
293 </p>
294 <p>
295 Ignore duplicate records when overwriting records
296 in a database configured for sorted duplicates.
297 </p>
298 <p>
299 Normally, if a database is configured for sorted
300 duplicates, an attempt to put a record that
301 compares identically to a record already existing
302 in the database will fail. Using this flag causes
303 the put to silently proceed, without failure.
304 </p>
305 <p>
306 This flag is extremely useful when performing bulk
307 puts (using the <code class="literal">DB_MULTIPLE</code> or
308 <code class="literal">DB_MULTIPLE_KEY</code> flags).
309 Depending on the number of records you are writing
310 to the database with a bulk put, you may not want
311 the operation to fail in the event that a
312 duplicate record is encountered. Using this flag
313 along with the <code class="literal">DB_MULTIPLE</code> or
314 <code class="literal">DB_MULTIPLE_KEY</code> flags allows
315 the bulk put to complete, even if a duplicate
316 record is encountered.
317 </p>
318 <p>
319 This flag is also useful if you are using a custom
320 comparison function that compares only part of the
321 data portion of a record. In this case, two
322 records can compare equally when, in fact, they
323 are not equal. This flag allows the put to
324 complete, even if your custom comparison routine
325 claims the two records are equal.
326 </p>
327 </li>
328 </ul>
329 </div>
330 </div>
331 </div>
332 <div class="sect2" lang="en" xml:lang="en">
333 <div class="titlepage">
334 <div>
335 <div>
336 <h3 class="title"><a id="idp49969776"></a>Errors</h3>
337 </div>
338 </div>
339 </div>
340 <p>
341 The <code class="methodname">DB-&gt;put()</code> <span>
342 <span>
343 method may fail and return one of the following non-zero errors:
344 </span>
345
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="idp49981992"></a>DB_FOREIGN_CONFLICT</h4>
353 </div>
354 </div>
355 </div>
356 <p>
357 A <a class="link" href="dbassociate_foreign.html" title="DB-&gt;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="idp49942080"></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-&gt;set_heapsize()">DB-&gt;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="idp49965376"></a>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 </div>
411 <div class="sect3" lang="en" xml:lang="en">
412 <div class="titlepage">
413 <div>
414 <div>
415 <h4 class="title"><a id="idp49960224"></a>DB_LOCK_NOTGRANTED</h4>
416 </div>
417 </div>
418 </div>
419 <p>
420 A Berkeley DB Concurrent Data Store database environment configured
421 for lock timeouts was unable to grant a lock in the allowed time.
422 </p>
423 <p>
424 You attempted to open a database handle that is configured
425 for no waiting exclusive locking, but the exclusive lock could not be
426 immediately obtained. See
427 <a class="xref" href="dbset_lk_exclusive.html" title="DB-&gt;set_lk_exclusive()">DB-&gt;set_lk_exclusive()</a>
428 for more information.
429 </p>
430 </div>
431 <div class="sect3" lang="en" xml:lang="en">
432 <div class="titlepage">
433 <div>
434 <div>
435 <h4 class="title"><a id="idp49933520"></a> DB_REP_HANDLE_DEAD</h4>
436 </div>
437 </div>
438 </div>
439 <p>
440 When a client synchronizes with the master, it is possible for committed
441 transactions to be rolled back. This invalidates all the database and cursor
442 handles opened in the replication environment. Once this occurs, an attempt to use
443 such a handle will
444
445 return <code class="literal">DB_REP_HANDLE_DEAD</code>.
446 The application will need to discard the handle and open a new one in order to
447 continue processing.
448 </p>
449 </div>
450 <a id="dbput_DB_REP_LOCKOUT"></a>
451 <div class="sect3" lang="en" xml:lang="en">
452 <div class="titlepage">
453 <div>
454 <div>
455 <h4 class="title"><a id="idp49976264"></a>DB_REP_LOCKOUT</h4>
456 </div>
457 </div>
458 </div>
459 <p>
460 The operation was blocked by client/master synchronization.
461 </p>
462 </div>
463 <div class="sect3" lang="en" xml:lang="en">
464 <div class="titlepage">
465 <div>
466 <div>
467 <h4 class="title"><a id="idp50009120"></a>EACCES</h4>
468 </div>
469 </div>
470 </div>
471 <p>
472 An attempt was made to modify a read-only database.
473 </p>
474 </div>
475 <div class="sect3" lang="en" xml:lang="en">
476 <div class="titlepage">
477 <div>
478 <div>
479 <h4 class="title"><a id="idp50009528"></a>EINVAL</h4>
480 </div>
481 </div>
482 </div>
483 <p>
484 If a record number of 0 was specified; an attempt was made to add a
485 record to a fixed-length database that was too large to fit; an
486 attempt was made to do a partial put; an attempt was made to add a
487 record to a secondary index; or if an invalid flag value or parameter
488 was specified.
489 </p>
490 </div>
491 <div class="sect3" lang="en" xml:lang="en">
492 <div class="titlepage">
493 <div>
494 <div>
495 <h4 class="title"><a id="idp50010224"></a>ENOSPC</h4>
496 </div>
497 </div>
498 </div>
499 <p>
500 A btree exceeded the maximum btree depth (255).
501 </p>
502 </div>
503 </div>
504 <div class="sect2" lang="en" xml:lang="en">
505 <div class="titlepage">
506 <div>
507 <div>
508 <h3 class="title"><a id="idp49969560"></a>Class</h3>
509 </div>
510 </div>
511 </div>
512 <p>
513 <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a>
514 </p>
515 </div>
516 <div class="sect2" lang="en" xml:lang="en">
517 <div class="titlepage">
518 <div>
519 <div>
520 <h3 class="title"><a id="idp49973280"></a>See Also</h3>
521 </div>
522 </div>
523 </div>
524 <p>
525 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a>
526 </p>
527 </div>
528 </div>
529 <div class="navfooter">
530 <hr />
531 <table width="100%" summary="Navigation footer">
532 <tr>
533 <td width="40%" align="left"><a accesskey="p" href="dbopen.html">Prev</a> </td>
534 <td width="20%" align="center">
535 <a accesskey="u" href="db.html">Up</a>
536 </td>
537 <td width="40%" align="right"> <a accesskey="n" href="dbremove.html">Next</a></td>
538 </tr>
539 <tr>
540 <td width="40%" align="left" valign="top">DB-&gt;open() </td>
541 <td width="20%" align="center">
542 <a accesskey="h" href="index.html">Home</a>
543 </td>
544 <td width="40%" align="right" valign="top"> DB-&gt;remove()</td>
545 </tr>
546 </table>
547 </div>
548 </body>
549 </html>