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