Debian Codegraph @

docs/api_reference/CXX/dbcput.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>Dbc::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="dbc.html" title="Chapter 3.  The Dbc Handle" />
11 <link rel="prev" href="dbcget_priority.html" title="Dbc::get_priority()" />
12 <link rel="next" href="dbcset_priority.html" title="Dbc::set_priority()" />
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">Dbc::put()</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="dbcget_priority.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 3. 
26 The Dbc Handle
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="dbcset_priority.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="dbcput"></a>Dbc::put()</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#include &lt;db_cxx.h&gt;
42
43 int
44 Dbc::put(Dbt *key, Dbt *data, u_int32_t flags);</pre>
45 <p>
46 The <code class="methodname">Dbc::put()</code> method stores key/data pairs into the database.
47 </p>
48 <p>
49 Unless otherwise specified, the <code class="methodname">Dbc::put()</code> <span>
50
51 <span>
52 method either returns a non-zero error value or throws an
53 exception that encapsulates a non-zero error value on
54 failure, and returns 0 on success.
55 </span>
56 </span>
57 </p>
58 <p>
59 If <code class="methodname">Dbc::put()</code> fails for any reason, the state of the cursor will
60 be unchanged. If <code class="methodname">Dbc::put()</code> succeeds and an item is inserted
61 into the database, the cursor is always positioned to refer to the
62 newly inserted item.
63 </p>
64 <div class="sect2" lang="en" xml:lang="en">
65 <div class="titlepage">
66 <div>
67 <div>
68 <h3 class="title"><a id="idp6310816"></a>Parameters</h3>
69 </div>
70 </div>
71 </div>
72 <div class="sect3" lang="en" xml:lang="en">
73 <div class="titlepage">
74 <div>
75 <div>
76 <h4 class="title"><a id="idp6311008"></a>key</h4>
77 </div>
78 </div>
79 </div>
80 <p>
81 The key <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> operated on.
82 </p>
83 <p>
84 If creating a new record in a Heap database, the
85 key <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>
86 must be empty. The <code class="literal">put</code>
87 method will return the new record's
88 <a class="link" href="db_heap_rid.html" title="DbHeapRecordId">Record ID (RID)</a>
89 in the key <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>.
90 </p>
91 </div>
92 <div class="sect3" lang="en" xml:lang="en">
93 <div class="titlepage">
94 <div>
95 <div>
96 <h4 class="title"><a id="idp6201832"></a>data</h4>
97 </div>
98 </div>
99 </div>
100 <p>
101 The data <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> operated on.
102 </p>
103 </div>
104 <div class="sect3" lang="en" xml:lang="en">
105 <div class="titlepage">
106 <div>
107 <div>
108 <h4 class="title"><a id="idp6283912"></a>flags</h4>
109 </div>
110 </div>
111 </div>
112 <p>
113 The <span class="bold"><strong>flags</strong></span> parameter must be set to
114 one of the following values:
115 </p>
116 <div class="itemizedlist">
117 <ul type="disc">
118 <li>
119 <p><a id="dbcput_DB_AFTER"></a>
120 <code class="literal">DB_AFTER</code>
121 </p>
122 <p>
123 In the case of the Btree and Hash access methods, insert the data
124 element as a duplicate element of the key to which the cursor refers.
125 The new element appears immediately after the current cursor position.
126 It is an error to specify DB_AFTER if the underlying Btree or Hash
127 database is not configured for unsorted duplicate data items. The
128 <span class="bold"><strong>key</strong></span> parameter is ignored.
129 </p>
130 <p>
131 In the case of the Recno access method, it is an error to specify
132 DB_AFTER if the underlying Recno database was not created with the
133 <a class="link" href="dbset_flags.html#dbset_flags_DB_RENUMBER">DB_RENUMBER</a>
134 flag. If the
135 <a class="link" href="dbset_flags.html#dbset_flags_DB_RENUMBER">DB_RENUMBER</a>
136 flag was specified, a new key is created, all records after the inserted
137 item are automatically renumbered, and the key of the new record is
138 returned in the structure to which the <span class="bold"><strong>key</strong></span> parameter refers. The initial value of the
139 <span class="bold"><strong>key</strong></span> parameter is ignored. See
140 <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> for more information.
141 </p>
142 <p>
143 The DB_AFTER flag may not be specified to the Queue access method.
144 </p>
145 <p>
146 The <code class="methodname">Dbc::put()</code> method will return
147 <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a>
148 if the current cursor record has already been deleted
149 and the underlying access method is Hash.
150 </p>
151 </li>
152 <li>
153 <p><a id="dbcput_DB_BEFORE"></a>
154 <code class="literal">DB_BEFORE</code>
155 </p>
156 <p>
157 In the case of the Btree and Hash access methods, insert the data
158 element as a duplicate element of the key to which the cursor refers.
159 The new element appears immediately before the current cursor
160 position. It is an error to specify DB_AFTER if the underlying Btree
161 or Hash database is not configured for unsorted duplicate data items.
162 The <span class="bold"><strong>key</strong></span> parameter is ignored.
163 </p>
164 <p>
165 In the case of the Recno access method, it is an error to specify
166 DB_BEFORE if the underlying Recno database was not created with the
167 <a class="link" href="dbset_flags.html#dbset_flags_DB_RENUMBER">DB_RENUMBER</a>
168 flag. If the
169 <a class="link" href="dbset_flags.html#dbset_flags_DB_RENUMBER">DB_RENUMBER</a>
170 flag was specified, a new key is created, the current record and all
171 records after it are automatically renumbered, and the key of the new
172 record is returned in the structure to which the <span class="bold"><strong>key</strong></span> parameter refers. The initial value of the
173 <span class="bold"><strong>key</strong></span> parameter is ignored. See
174 <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> for more information.
175 </p>
176 <p>
177 The DB_BEFORE flag may not be specified to the Queue access method.
178 </p>
179 <p>
180 The <code class="methodname">Dbc::put()</code> method will return
181 <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a>
182 if the current cursor record has already been deleted
183 and the underlying access method is Hash.
184 </p>
185 </li>
186 <li>
187 <p><a id="dbcput_DB_CURRENT"></a>
188 <code class="literal">DB_CURRENT</code>
189 </p>
190 <p>
191 Overwrite the data of the key/data pair to which the cursor refers
192 with the specified data item. The <span class="bold"><strong>key</strong></span> parameter is ignored.
193 </p>
194 <p>
195 The <code class="methodname">Dbc::put()</code> method will return
196 <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a>
197 if the current cursor record has already been deleted.
198 </p>
199 </li>
200 <li>
201 <p><a id="dbcput_DB_KEYFIRST"></a>
202 <code class="literal">DB_KEYFIRST</code>
203 </p>
204 <p>
205 Insert the specified key/data pair into the database.
206 </p>
207 <p>
208 If the underlying database supports duplicate data items, and if the
209 key already exists in the database and a duplicate sort function has
210 been specified, the inserted data item is added in its sorted
211 location. If the key already exists in the database and no duplicate
212 sort function has been specified, the inserted data item is added as
213 the first of the data items for that key.
214 </p>
215 </li>
216 <li>
217 <p><a id="dbcput_DB_KEYLAST"></a>
218 <code class="literal">DB_KEYLAST</code>
219 </p>
220 <p>
221 Insert the specified key/data pair into the database.
222 </p>
223 <p>
224 If the underlying database supports duplicate data items, and if the
225 key already exists in the database and a duplicate sort function has
226 been specified, the inserted data item is added in its sorted
227 location. If the key already exists in the database, and no duplicate
228 sort function has been specified, the inserted data item is added as
229 the last of the data items for that key.
230 </p>
231 </li>
232 <li>
233 <p><a id="dbcput_DB_NODUPDATA"></a>
234 <code class="literal">DB_NODUPDATA</code>
235 </p>
236 <p>
237 In the case of the Btree and Hash access methods, insert the specified
238 key/data pair into the database, unless a key/data pair comparing
239 equally to it already exists in the database. If a matching key/data
240 pair already exists in the database,
241 <a class="xref" href="dbcput.html#dbcput_DB_KEYEXIST" title="DB_KEYEXIST">DB_KEYEXIST</a> is
242 returned. The DB_NODUPDATA flag may only be specified if the
243 underlying database has been configured to support sorted duplicate
244 data items.
245 </p>
246 <p>
247 The DB_NODUPDATA flag may not be specified to the Queue or Recno
248 access methods.
249 </p>
250 </li>
251 </ul>
252 </div>
253 </div>
254 </div>
255 <div class="sect2" lang="en" xml:lang="en">
256 <div class="titlepage">
257 <div>
258 <div>
259 <h3 class="title"><a id="idp6321920"></a>Errors</h3>
260 </div>
261 </div>
262 </div>
263 <p>
264 The <code class="methodname">Dbc::put()</code> <span>
265
266 <span>
267 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a>
268 exception, encapsulating one of the following non-zero errors, or return one
269 of the following non-zero errors:
270 </span>
271 </span>
272 </p>
273 <div class="sect3" lang="en" xml:lang="en">
274 <div class="titlepage">
275 <div>
276 <div>
277 <h4 class="title"><a id="dbcput_DB_KEYEXIST"></a>DB_KEYEXIST</h4>
278 </div>
279 </div>
280 </div>
281 <p>
282 An attempt was made to insert a duplicate key
283 into a database not configured for duplicate
284 data.
285 </p>
286 </div>
287 <div class="sect3" lang="en" xml:lang="en">
288 <div class="titlepage">
289 <div>
290 <div>
291 <h4 class="title"><a id="idp6337016"></a>DB_FOREIGN_CONFLICT</h4>
292 </div>
293 </div>
294 </div>
295 <p>
296 A <a class="link" href="dbassociate_foreign.html" title="Db::associate_foreign()">foreign key constraint violation</a>
297 has occurred. This can be caused by one of two things:
298 </p>
299 <div class="orderedlist">
300 <ol type="1">
301 <li>
302 <p>
303 An attempt was made to add a record to a
304 constrained database, and the key used for that
305 record does not exist in the foreign key
306 database.
307 </p>
308 </li>
309 <li>
310 <p>
311 <a class="link" href="dbassociate_foreign.html#associate_foreign_DB_FOREIGN_ABORT">DB_FOREIGN_ABORT</a>
312 was declared for a foreign key database, and then
313 subsequently a record was deleted from the
314 foreign key database without first removing it
315 from the constrained secondary database.
316 </p>
317 </li>
318 </ol>
319 </div>
320 </div>
321 <div class="sect3" lang="en" xml:lang="en">
322 <div class="titlepage">
323 <div>
324 <div>
325 <h4 class="title"><a id="idp6307424"></a>DB_HEAP_FULL</h4>
326 </div>
327 </div>
328 </div>
329 <p>
330 An attempt was made to add or update a record in a Heap
331 database. However, the size of the database was constrained
332 using the
333 <a class="xref" href="dbset_heapsize.html" title="Db::set_heapsize()">Db::set_heapsize()</a>
334 method, and that limit has been reached.
335 </p>
336 </div>
337 <div class="sect3" lang="en" xml:lang="en">
338 <div class="titlepage">
339 <div>
340 <div>
341 <h4 class="title"><a id="idp6342680"></a><span>DbDeadlockException or </span>DB_LOCK_DEADLOCK</h4>
342 </div>
343 </div>
344 </div>
345 <p>
346 A transactional database environment operation was selected to resolve
347 a deadlock.
348 </p>
349 <p>
350 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if
351 your Berkeley DB API is configured to throw exceptions.
352 Otherwise, <code class="literal">DB_LOCK_DEADLOCK</code> is returned.
353 </p>
354 </div>
355 <div class="sect3" lang="en" xml:lang="en">
356 <div class="titlepage">
357 <div>
358 <div>
359 <h4 class="title"><a id="idp6323784"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4>
360 </div>
361 </div>
362 </div>
363 <p>
364 A Berkeley DB Concurrent Data Store database environment configured
365 for lock timeouts was unable to grant a lock in the allowed time.
366 </p>
367 <p>
368 You attempted to open a database handle that is configured
369 for no waiting exclusive locking, but the exclusive lock could not be
370 immediately obtained. See
371 <a class="xref" href="dbset_lk_exclusive.html" title="Db::set_lk_exclusive()">Db::set_lk_exclusive()</a>
372 for more information.
373 </p>
374 <p>
375 <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if
376 your Berkeley DB API is configured to throw exceptions.
377 Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned.
378 </p>
379 </div>
380 <div class="sect3" lang="en" xml:lang="en">
381 <div class="titlepage">
382 <div>
383 <div>
384 <h4 class="title"><a id="idp6299016"></a> <span>DbRepHandleDeadException or</span> DB_REP_HANDLE_DEAD</h4>
385 </div>
386 </div>
387 </div>
388 <p>
389 When a client synchronizes with the master, it is possible for committed
390 transactions to be rolled back. This invalidates all the database and cursor
391 handles opened in the replication environment. Once this occurs, an attempt to use
392 such a handle will
393 <span>
394 throw a <a class="xref" href="dbrephandledead.html" title="DbRepHandleDeadException">DbRepHandleDeadException</a> (if
395 your application is configured to throw exceptions), or
396 </span>
397 return <code class="literal">DB_REP_HANDLE_DEAD</code>.
398 The application will need to discard the handle and open a new one in order to
399 continue processing.
400 </p>
401 </div>
402 <div class="sect3" lang="en" xml:lang="en">
403 <div class="titlepage">
404 <div>
405 <div>
406 <h4 class="title"><a id="idp6346784"></a><span>DbDeadlockException or </span>DB_REP_LOCKOUT</h4>
407 </div>
408 </div>
409 </div>
410 <p>
411 The operation was blocked by client/master synchronization.
412 </p>
413 <p>
414 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if
415 your Berkeley DB API is configured to throw exceptions.
416 Otherwise, <code class="literal">DB_REP_LOCKOUT</code> is returned.
417 </p>
418 </div>
419 <div class="sect3" lang="en" xml:lang="en">
420 <div class="titlepage">
421 <div>
422 <div>
423 <h4 class="title"><a id="idp6349160"></a>EACCES</h4>
424 </div>
425 </div>
426 </div>
427 <p>
428 An attempt was made to modify a read-only database.
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="idp6344696"></a>EINVAL</h4>
436 </div>
437 </div>
438 </div>
439 <p>
440 If the DB_AFTER, DB_BEFORE or DB_CURRENT flags were specified and the
441 cursor has not been initialized; the DB_AFTER or DB_BEFORE flags were
442 specified and a duplicate sort function has been specified; the
443 DB_CURRENT flag was specified, a duplicate sort function has been
444 specified, and the data item of the referenced key/data pair does not
445 compare equally to the <span class="bold"><strong>data</strong></span>
446 parameter; the DB_AFTER or DB_BEFORE flags were specified, and the
447 underlying access method is Queue; an attempt was made to add a record
448 to a fixed-length database that was too large to fit; an attempt was
449 made to add a record to a secondary index; or if an invalid flag value
450 or parameter was specified.
451 </p>
452 </div>
453 <div class="sect3" lang="en" xml:lang="en">
454 <div class="titlepage">
455 <div>
456 <div>
457 <h4 class="title"><a id="idp6309512"></a>EPERM</h4>
458 </div>
459 </div>
460 </div>
461 <p>
462 Write attempted on read-only cursor when the
463 <a class="link" href="envopen.html#envopen_DB_INIT_CDB">DB_INIT_CDB</a>
464 flag was specified to <a class="xref" href="envopen.html" title="DbEnv::open()">DbEnv::open()</a>.
465 </p>
466 </div>
467 </div>
468 <div class="sect2" lang="en" xml:lang="en">
469 <div class="titlepage">
470 <div>
471 <div>
472 <h3 class="title"><a id="idp6319176"></a>Class</h3>
473 </div>
474 </div>
475 </div>
476 <p>
477 <a class="link" href="dbc.html" title="Chapter 3.  The Dbc Handle">Dbc</a>
478 </p>
479 </div>
480 <div class="sect2" lang="en" xml:lang="en">
481 <div class="titlepage">
482 <div>
483 <div>
484 <h3 class="title"><a id="idp6346456"></a>See Also</h3>
485 </div>
486 </div>
487 </div>
488 <p>
489 <a class="xref" href="dbc.html#dbclist" title="Database Cursors and Related Methods">Database Cursors and Related Methods</a>
490 </p>
491 </div>
492 </div>
493 <div class="navfooter">
494 <hr />
495 <table width="100%" summary="Navigation footer">
496 <tr>
497 <td width="40%" align="left"><a accesskey="p" href="dbcget_priority.html">Prev</a> </td>
498 <td width="20%" align="center">
499 <a accesskey="u" href="dbc.html">Up</a>
500 </td>
501 <td width="40%" align="right"> <a accesskey="n" href="dbcset_priority.html">Next</a></td>
502 </tr>
503 <tr>
504 <td width="40%" align="left" valign="top">Dbc::get_priority() </td>
505 <td width="20%" align="center">
506 <a accesskey="h" href="index.html">Home</a>
507 </td>
508 <td width="40%" align="right" valign="top"> Dbc::set_priority()</td>
509 </tr>
510 </table>
511 </div>
512 </body>
513 </html>