Debian Codegraph @

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