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