| 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::get()</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="dbcdup.html" title="Dbc::dup()" /> |
| 12 | <link rel="next" href="dbcget_priority.html" title="Dbc::get_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::get()</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="dbcdup.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="dbcget_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="dbcget"></a>Dbc::get()</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db_cxx.h> |
| 42 | |
| 43 | int |
| 44 | Dbc::get(Dbt *key, Dbt *data, u_int32_t flags); |
| 45 | |
| 46 | int |
| 47 | Dbc::pget(Dbt *key, Dbt *pkey, Dbt *data, u_int32_t flags); </pre> |
| 48 | <p> |
| 49 | The <code class="methodname">Dbc::get()</code> method retrieves key/data pairs from the |
| 50 | database. The address and length of the key are returned in the |
| 51 | object to which <span class="bold"><strong>key</strong></span> refers (except |
| 52 | for the case of the DB_SET flag, in which the <span class="bold"><strong>key</strong></span> object is unchanged), and the address and |
| 53 | length of the data are returned in the object to which <span class="bold"><strong>data</strong></span> refers. |
| 54 | </p> |
| 55 | <p> |
| 56 | When called on a cursor opened on a database that has been made into a |
| 57 | secondary index using the |
| 58 | <a class="xref" href="dbassociate.html" title="Db::associate()">Db::associate()</a> method, the |
| 59 | <code class="methodname">Dbc::get()</code> and <code class="methodname">Dbc::pget()</code> |
| 60 | methods return the key from the |
| 61 | secondary index and the data item from the primary database. In |
| 62 | addition, the <code class="methodname">Dbc::pget()</code> method returns the key from the |
| 63 | primary database. In databases that are not secondary indices, the |
| 64 | <code class="methodname">Dbc::pget()</code> method will always fail. |
| 65 | </p> |
| 66 | <p> |
| 67 | Modifications to the database during a sequential scan will be |
| 68 | reflected in the scan; that is, records inserted behind a cursor will |
| 69 | not be returned while records inserted in front of a cursor will be |
| 70 | returned. |
| 71 | </p> |
| 72 | <p> |
| 73 | In Queue and Recno databases, missing entries (that is, entries that |
| 74 | were never explicitly created or that were created and then deleted) |
| 75 | will be skipped during a sequential scan. |
| 76 | </p> |
| 77 | <p> |
| 78 | Unless otherwise specified, the <code class="methodname">Dbc::get()</code> <span> |
| 79 | |
| 80 | <span> |
| 81 | method either returns a non-zero error value or throws an |
| 82 | exception that encapsulates a non-zero error value on |
| 83 | failure, and returns 0 on success. |
| 84 | </span> |
| 85 | </span> |
| 86 | </p> |
| 87 | <p> |
| 88 | If <code class="methodname">Dbc::get()</code> fails for any reason, the state of the cursor will |
| 89 | be unchanged. |
| 90 | </p> |
| 91 | <div class="sect2" lang="en" xml:lang="en"> |
| 92 | <div class="titlepage"> |
| 93 | <div> |
| 94 | <div> |
| 95 | <h3 class="title"><a id="idp6167896"></a>Parameters</h3> |
| 96 | </div> |
| 97 | </div> |
| 98 | </div> |
| 99 | <div class="sect3" lang="en" xml:lang="en"> |
| 100 | <div class="titlepage"> |
| 101 | <div> |
| 102 | <div> |
| 103 | <h4 class="title"><a id="idp6203160"></a>key</h4> |
| 104 | </div> |
| 105 | </div> |
| 106 | </div> |
| 107 | <p> |
| 108 | The key <a class="link" href="dbt.html" title="Chapter 4. The Dbt Handle">Dbt</a> operated on. |
| 109 | </p> |
| 110 | <p> |
| 111 | If <a class="link" href="dbt.html#dbt_DB_DBT_PARTIAL">DB_DBT_PARTIAL</a> |
| 112 | is set for the Dbt used for this parameter, |
| 113 | and if the <span class="bold"><strong>flags</strong></span> parameter |
| 114 | is set to |
| 115 | <a class="link" href="dbcget.html#dbcget_DB_GET_BOTH">DB_GET_BOTH</a>, |
| 116 | <a class="link" href="dbcget.html#dbcget_DB_GET_BOTH_RANGE">DB_GET_BOTH_RANGE</a>, |
| 117 | <a class="link" href="dbcget.html#dbcget_DB_SET">DB_SET</a>, or |
| 118 | <a class="link" href="dbcget.html#dbcget_DB_SET_RECNO">DB_SET_RECNO</a>, |
| 119 | then this method will fail and return <code class="literal">EINVAL</code>. |
| 120 | </p> |
| 121 | </div> |
| 122 | <div class="sect3" lang="en" xml:lang="en"> |
| 123 | <div class="titlepage"> |
| 124 | <div> |
| 125 | <div> |
| 126 | <h4 class="title"><a id="idp6207616"></a>pkey</h4> |
| 127 | </div> |
| 128 | </div> |
| 129 | </div> |
| 130 | <p> |
| 131 | The return key from the primary database. |
| 132 | If |
| 133 | <a class="link" href="dbt.html#dbt_DB_DBT_PARTIAL">DB_DBT_PARTIAL</a> |
| 134 | is set for the Dbt used for this parameter, |
| 135 | then this method will fail and return <code class="literal">EINVAL</code>. |
| 136 | </p> |
| 137 | </div> |
| 138 | <div class="sect3" lang="en" xml:lang="en"> |
| 139 | <div class="titlepage"> |
| 140 | <div> |
| 141 | <div> |
| 142 | <h4 class="title"><a id="idp6173912"></a>data</h4> |
| 143 | </div> |
| 144 | </div> |
| 145 | </div> |
| 146 | <p> |
| 147 | The data <a class="link" href="dbt.html" title="Chapter 4. The Dbt Handle">Dbt</a> operated on. |
| 148 | </p> |
| 149 | </div> |
| 150 | <div class="sect3" lang="en" xml:lang="en"> |
| 151 | <div class="titlepage"> |
| 152 | <div> |
| 153 | <div> |
| 154 | <h4 class="title"><a id="idp6199728"></a>flags</h4> |
| 155 | </div> |
| 156 | </div> |
| 157 | </div> |
| 158 | <p> |
| 159 | The <span class="bold"><strong>flags</strong></span> parameter must be set to |
| 160 | one of the following values: |
| 161 | </p> |
| 162 | <div class="itemizedlist"> |
| 163 | <ul type="disc"> |
| 164 | <li> |
| 165 | <p><a id="dbcget_DB_CURRENT"></a> |
| 166 | <code class="literal">DB_CURRENT</code> |
| 167 | </p> |
| 168 | <p> |
| 169 | Return the key/data pair to which the cursor refers. |
| 170 | </p> |
| 171 | <p> |
| 172 | The <code class="methodname">Dbc::get()</code> method |
| 173 | will return |
| 174 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_KEYEMPTY" class="olink">DB_KEYEMPTY</a> |
| 175 | if DB_CURRENT is set and the cursor key/data pair |
| 176 | was deleted. |
| 177 | </p> |
| 178 | </li> |
| 179 | <li> |
| 180 | <p><a id="dbcget_DB_FIRST"></a> |
| 181 | <code class="literal">DB_FIRST</code> |
| 182 | </p> |
| 183 | <p> |
| 184 | The cursor is set to refer to the first key/data |
| 185 | pair of the database, and that pair is returned. |
| 186 | If the first key has duplicate values, the first |
| 187 | data item in the set of duplicates is returned. |
| 188 | </p> |
| 189 | <p> |
| 190 | If the database is a Queue or Recno database, |
| 191 | <code class="methodname">Dbc::get()</code> using the |
| 192 | DB_FIRST flag will ignore any keys that exist but |
| 193 | were never explicitly created by the application, |
| 194 | or were created and later deleted. |
| 195 | </p> |
| 196 | <p> |
| 197 | The <code class="methodname">Dbc::get()</code> method |
| 198 | will return |
| 199 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 200 | if DB_FIRST is set and the database is empty. |
| 201 | </p> |
| 202 | </li> |
| 203 | <li> |
| 204 | <p><a id="dbcget_DB_GET_BOTH"></a> |
| 205 | <code class="literal">DB_GET_BOTH</code> |
| 206 | </p> |
| 207 | <p> |
| 208 | Move the cursor to the specified key/data pair of |
| 209 | the database. The cursor is positioned to a |
| 210 | key/data pair if both the key and data match the |
| 211 | values provided on the key and data parameters. |
| 212 | </p> |
| 213 | <p> |
| 214 | In all other ways, this flag is identical to the |
| 215 | <a class="link" href="dbcget.html#dbcget_DB_SET">DB_SET</a> |
| 216 | flag. |
| 217 | </p> |
| 218 | <p> |
| 219 | When used with |
| 220 | <code class="methodname">Dbc::pget()</code> on a |
| 221 | secondary index handle, both the secondary and |
| 222 | primary keys must be matched by the secondary and |
| 223 | primary key item in the database. It is an error |
| 224 | to use the DB_GET_BOTH flag with the |
| 225 | <code class="methodname">Dbc::get()</code> version |
| 226 | of this method and a cursor that has been opened on a secondary index |
| 227 | handle. |
| 228 | </p> |
| 229 | </li> |
| 230 | <li> |
| 231 | <p><a id="dbcget_DB_GET_BOTH_RANGE"></a> |
| 232 | <code class="literal">DB_GET_BOTH_RANGE</code> |
| 233 | </p> |
| 234 | <p> |
| 235 | Move the cursor to the specified key/data pair of the |
| 236 | database. The key parameter must be an exact match with a |
| 237 | key in the database. The data item retrieved is the item in |
| 238 | a duplicate set that is the smallest value which is greater than or equal |
| 239 | to the value provided by the data parameter (as determined by the comparison |
| 240 | function). If this flag is specified on a database |
| 241 | configured without sorted duplicate support, the behavior |
| 242 | is identical to the <code class="literal">DB_GET_BOTH</code> flag. Returns the datum |
| 243 | associated with the given key/data pair. |
| 244 | </p> |
| 245 | <p> |
| 246 | In all other ways, this flag is identical to the |
| 247 | <a class="link" href="dbcget.html#dbcget_DB_GET_BOTH">DB_GET_BOTH</a> |
| 248 | flag. |
| 249 | </p> |
| 250 | </li> |
| 251 | <li> |
| 252 | <p><a id="dbcget_DB_GET_RECNO"></a> |
| 253 | <code class="literal">DB_GET_RECNO</code> |
| 254 | </p> |
| 255 | <p> |
| 256 | Return the record number associated with the cursor. The record |
| 257 | number will be returned in <span class="bold"><strong>data</strong></span>, as |
| 258 | described in <a class="link" href="dbt.html" title="Chapter 4. The Dbt Handle">Dbt</a>. The |
| 259 | <span class="bold"><strong>key</strong></span> parameter is ignored. |
| 260 | </p> |
| 261 | <p> |
| 262 | For DB_GET_RECNO to be specified, the underlying database must be of |
| 263 | type Btree, and it must have been created with the |
| 264 | <a class="link" href="dbset_flags.html#dbset_flags_DB_RECNUM">DB_RECNUM</a> |
| 265 | flag. |
| 266 | </p> |
| 267 | <p> |
| 268 | When called on a cursor opened on a database that has been made into a |
| 269 | secondary index, the <code class="methodname">Dbc::get()</code> and |
| 270 | <code class="methodname">Dbc::pget()</code> methods return the record |
| 271 | number of the primary database in <span class="bold"><strong>data</strong></span>. |
| 272 | In addition, the <code class="methodname">Dbc::pget()</code> |
| 273 | method returns the record number of the secondary index in <span class="bold"><strong>pkey</strong></span>. If either underlying database is not of |
| 274 | type Btree or is not created with the |
| 275 | <a class="link" href="dbset_flags.html#dbset_flags_DB_RECNUM">DB_RECNUM</a> |
| 276 | flag, the out-of-band record number of 0 is returned. |
| 277 | </p> |
| 278 | </li> |
| 279 | <li> |
| 280 | <p><a id="dbcget_DB_JOIN_ITEM"></a> |
| 281 | <code class="literal">DB_JOIN_ITEM</code> |
| 282 | </p> |
| 283 | <p> |
| 284 | Do not use the data value found in all of the cursors as a lookup key |
| 285 | for the primary database, but simply return it in the key parameter |
| 286 | instead. The data parameter is left unchanged. |
| 287 | </p> |
| 288 | <p> |
| 289 | For DB_JOIN_ITEM to be specified, the underlying cursor must have been |
| 290 | returned from the <a class="xref" href="dbjoin.html" title="Db::join()">Db::join()</a> method. |
| 291 | </p> |
| 292 | <p> |
| 293 | This flag is not supported for Heap databases. |
| 294 | </p> |
| 295 | </li> |
| 296 | <li> |
| 297 | <p><a id="dbcget_DB_LAST"></a> |
| 298 | <code class="literal">DB_LAST</code> |
| 299 | </p> |
| 300 | <p> |
| 301 | The cursor is set to refer to the last key/data pair of the database, |
| 302 | and that pair is returned. If the last key has duplicate values, the |
| 303 | last data item in the set of duplicates is returned. |
| 304 | </p> |
| 305 | <p> |
| 306 | If the database is a Queue or Recno database, |
| 307 | <code class="methodname">Dbc::get()</code> using the |
| 308 | DB_LAST flag will ignore any keys that exist but |
| 309 | were never explicitly created by the application, |
| 310 | or were created and later deleted. |
| 311 | </p> |
| 312 | <p> |
| 313 | The <code class="methodname">Dbc::get()</code> method |
| 314 | will return |
| 315 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 316 | if DB_LAST is set and the database is empty. |
| 317 | </p> |
| 318 | </li> |
| 319 | <li> |
| 320 | <p><a id="dbcget_DB_NEXT"></a> |
| 321 | <code class="literal">DB_NEXT</code> |
| 322 | </p> |
| 323 | <p> |
| 324 | If the cursor is not yet initialized, DB_NEXT is identical to |
| 325 | DB_FIRST. Otherwise, the cursor is moved to the next key/data pair of |
| 326 | the database, and that pair is returned. In the presence of duplicate |
| 327 | key values, the value of the key may not change. |
| 328 | </p> |
| 329 | <p> |
| 330 | If the database is a Queue or Recno database, |
| 331 | <code class="methodname">Dbc::get()</code> using the |
| 332 | DB_NEXT flag will skip any keys that exist but |
| 333 | were never explicitly created by the application, |
| 334 | or those that were created and later deleted. |
| 335 | </p> |
| 336 | <p> |
| 337 | The <code class="methodname">Dbc::get()</code> method |
| 338 | will return |
| 339 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 340 | if DB_NEXT is set and the cursor is already on the |
| 341 | last record in the database. |
| 342 | </p> |
| 343 | </li> |
| 344 | <li> |
| 345 | <p><a id="dbcget_DB_NEXT_DUP"></a> |
| 346 | <code class="literal">DB_NEXT_DUP</code> |
| 347 | </p> |
| 348 | <p> |
| 349 | If the next key/data pair of the database is a duplicate data record |
| 350 | for the current key/data pair, the cursor is moved to the next |
| 351 | key/data pair of the database, and that pair is returned. |
| 352 | </p> |
| 353 | <p> |
| 354 | The <code class="methodname">Dbc::get()</code> method |
| 355 | will return |
| 356 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 357 | if DB_NEXT_DUP is set and the next key/data pair |
| 358 | of the database is not a duplicate data record for |
| 359 | the current key/data pair. |
| 360 | </p> |
| 361 | <p> |
| 362 | If using a Heap database, this flag results in this |
| 363 | method returning |
| 364 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a>. |
| 365 | </p> |
| 366 | </li> |
| 367 | <li> |
| 368 | <p><a id="dbcget_DB_NEXT_NODUP"></a> |
| 369 | <code class="literal">DB_NEXT_NODUP</code> |
| 370 | </p> |
| 371 | <p> |
| 372 | If the cursor is not yet initialized, DB_NEXT_NODUP is identical to |
| 373 | DB_FIRST. Otherwise, the cursor is moved to the next non-duplicate |
| 374 | key of the database, and that key/data pair is returned. |
| 375 | </p> |
| 376 | <p> |
| 377 | If the database is a Queue or Recno database, |
| 378 | <code class="methodname">Dbc::get()</code> using the |
| 379 | DB_NEXT_NODUP flag will ignore any keys that exist |
| 380 | but were never explicitly created by the |
| 381 | application, or those that were created and later |
| 382 | deleted. |
| 383 | </p> |
| 384 | <p> |
| 385 | The <code class="methodname">Dbc::get()</code> method |
| 386 | will return |
| 387 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 388 | if DB_NEXT_NODUP is set and no non-duplicate |
| 389 | key/data pairs exist after the cursor position in |
| 390 | the database. |
| 391 | </p> |
| 392 | <p> |
| 393 | If using a Heap database, this flag is identical to |
| 394 | the <code class="literal">DB_NEXT</code> flag. |
| 395 | </p> |
| 396 | </li> |
| 397 | <li> |
| 398 | <p><a id="dbcget_DB_PREV"></a> |
| 399 | <code class="literal">DB_PREV</code> |
| 400 | </p> |
| 401 | <p> |
| 402 | If the cursor is not yet initialized, DB_PREV is identical to DB_LAST. |
| 403 | Otherwise, the cursor is moved to the previous key/data pair of the |
| 404 | database, and that pair is returned. In the presence of duplicate key |
| 405 | values, the value of the key may not change. |
| 406 | </p> |
| 407 | <p> |
| 408 | If the database is a Queue or Recno database, |
| 409 | <code class="methodname">Dbc::get()</code> using the |
| 410 | DB_PREV flag will skip any keys that exist but |
| 411 | were never explicitly created by the application, |
| 412 | or those that were created and later deleted. |
| 413 | </p> |
| 414 | <p> |
| 415 | The <code class="methodname">Dbc::get()</code> method |
| 416 | will return |
| 417 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 418 | if DB_PREV is set and the cursor is already on the |
| 419 | first record in the database. |
| 420 | </p> |
| 421 | </li> |
| 422 | <li> |
| 423 | <p><a id="dbcget_DB_PREV_DUP"></a> |
| 424 | <code class="literal">DB_PREV_DUP</code> |
| 425 | </p> |
| 426 | <p> |
| 427 | If the previous key/data pair of the database is a duplicate data |
| 428 | record for the current key/data pair, the cursor is moved to the |
| 429 | previous key/data pair of the database, and that pair is returned. |
| 430 | </p> |
| 431 | <p> |
| 432 | The <code class="methodname">Dbc::get()</code> method |
| 433 | will return |
| 434 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 435 | if DB_PREV_DUP is set and the previous key/data |
| 436 | pair of the database is not a duplicate data |
| 437 | record for the current key/data pair. |
| 438 | </p> |
| 439 | <p> |
| 440 | If using a Heap database, this flag results in this |
| 441 | method returning |
| 442 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a>. |
| 443 | </p> |
| 444 | </li> |
| 445 | <li> |
| 446 | <p><a id="dbcget_DB_PREV_NODUP"></a> |
| 447 | <code class="literal">DB_PREV_NODUP</code> |
| 448 | </p> |
| 449 | <p> |
| 450 | If the cursor is not yet initialized, |
| 451 | DB_PREV_NODUP is identical to DB_LAST. Otherwise, |
| 452 | the cursor is moved to the previous non-duplicate |
| 453 | key of the database, and that key/data pair is |
| 454 | returned. |
| 455 | </p> |
| 456 | <p> |
| 457 | If the database is a Queue or Recno database, |
| 458 | <code class="methodname">Dbc::get()</code> using the |
| 459 | DB_PREV_NODUP flag will ignore any keys that exist |
| 460 | but were never explicitly created by the |
| 461 | application, or those that were created and later |
| 462 | deleted. |
| 463 | </p> |
| 464 | <p> |
| 465 | The <code class="methodname">Dbc::get()</code> method |
| 466 | will return |
| 467 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 468 | if DB_PREV_NODUP is set and no non-duplicate |
| 469 | key/data pairs exist before the cursor position in |
| 470 | the database. |
| 471 | </p> |
| 472 | <p> |
| 473 | If using a Heap database, this flag is identical to |
| 474 | the <code class="literal">DB_PREV</code> flag. |
| 475 | </p> |
| 476 | </li> |
| 477 | <li> |
| 478 | <p><a id="dbcget_DB_SET"></a> |
| 479 | <code class="literal">DB_SET</code> |
| 480 | </p> |
| 481 | <p> |
| 482 | Move the cursor to the specified key/data pair of the database, and |
| 483 | return the datum associated with the given key. |
| 484 | </p> |
| 485 | <p> |
| 486 | The <code class="methodname">Dbc::get()</code> method will return |
| 487 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 488 | if DB_SET is set and no matching keys are found. |
| 489 | The <code class="methodname">Dbc::get()</code> method |
| 490 | will return |
| 491 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_KEYEMPTY" class="olink">DB_KEYEMPTY</a> |
| 492 | if DB_SET is set and the database is a Queue or |
| 493 | Recno database, and the specified key exists, but |
| 494 | was never explicitly created by the application or |
| 495 | was later deleted. In the presence of duplicate key |
| 496 | values, <code class="methodname">Dbc::get()</code> will |
| 497 | return the first data item for the given key. |
| 498 | </p> |
| 499 | </li> |
| 500 | <li> |
| 501 | <p><a id="dbcget_DB_SET_RANGE"></a> |
| 502 | <code class="literal">DB_SET_RANGE</code> |
| 503 | </p> |
| 504 | <p> |
| 505 | Move the cursor to the specified key/data pair of the |
| 506 | database. In the case of the Btree access method, the key |
| 507 | is returned as well as the data item and the returned |
| 508 | key/data pair is the smallest key greater than or equal to |
| 509 | the specified key (as determined by the Btree comparison |
| 510 | function), permitting partial key matches and range |
| 511 | searches. |
| 512 | </p> |
| 513 | <p> |
| 514 | In all other ways the behavior of this flag is the same |
| 515 | as the |
| 516 | <a class="link" href="dbcget.html#dbcget_DB_SET">DB_SET</a> flag. |
| 517 | </p> |
| 518 | </li> |
| 519 | <li> |
| 520 | <p><a id="dbcget_DB_SET_RECNO"></a> |
| 521 | <code class="literal">DB_SET_RECNO</code> |
| 522 | </p> |
| 523 | <p> |
| 524 | Move the cursor to the specific numbered record of |
| 525 | the database, and return the associated key/data |
| 526 | pair. The <span class="bold"><strong>data</strong></span> |
| 527 | field of the specified |
| 528 | <span class="bold"><strong>key</strong></span> must be a pointer |
| 529 | to a memory location from which a |
| 530 | <code class="literal">db_recno_t</code> may be read, as |
| 531 | described in |
| 532 | <a class="link" href="dbt.html" title="Chapter 4. The Dbt Handle">Dbt</a>. This memory |
| 533 | location will be read to determine the record to |
| 534 | be retrieved. |
| 535 | </p> |
| 536 | <p> |
| 537 | For DB_SET_RECNO to be specified, the underlying database must be of |
| 538 | type Btree, and it must have been created with the |
| 539 | <a class="link" href="dbset_flags.html#dbset_flags_DB_RECNUM">DB_RECNUM</a> |
| 540 | flag. |
| 541 | </p> |
| 542 | </li> |
| 543 | </ul> |
| 544 | </div> |
| 545 | <p> |
| 546 | In addition, the following flags may be set by bitwise inclusively |
| 547 | <span class="bold"><strong>OR</strong></span>'ing them into the <span class="bold"><strong>flags</strong></span> parameter: |
| 548 | </p> |
| 549 | <div class="itemizedlist"> |
| 550 | <ul type="disc"> |
| 551 | <li> |
| 552 | <p> |
| 553 | <code class="literal">DB_IGNORE_LEASE</code> |
| 554 | </p> |
| 555 | <p> |
| 556 | This flag is relevant only when using a replicated |
| 557 | environment. |
| 558 | </p> |
| 559 | <p> |
| 560 | Return the data item irrespective of the state of |
| 561 | master leases. The item will be returned under |
| 562 | all conditions: if master leases are not |
| 563 | configured, if the request is made to a client, if |
| 564 | the request is made to a master with a valid |
| 565 | lease, or if the request is made to a master |
| 566 | without a valid lease. |
| 567 | </p> |
| 568 | </li> |
| 569 | <li> |
| 570 | <p><a id="dbcget_DB_READ_COMMITTED"></a> |
| 571 | <code class="literal">DB_READ_COMMITTED</code> |
| 572 | </p> |
| 573 | <p> |
| 574 | Configure a transactional get operation to have degree 2 isolation |
| 575 | (the read is not repeatable). |
| 576 | </p> |
| 577 | </li> |
| 578 | <li> |
| 579 | <p> |
| 580 | <code class="literal">DB_READ_UNCOMMITTED</code> |
| 581 | </p> |
| 582 | <p> |
| 583 | Database items read during a transactional call will have degree 1 |
| 584 | isolation, including modified but not yet committed data. Silently |
| 585 | ignored if the |
| 586 | <a class="link" href="dbopen.html#dbopen_DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a> |
| 587 | flag was not specified when the underlying database was opened. |
| 588 | </p> |
| 589 | </li> |
| 590 | <li> |
| 591 | <p><a id="dbcget_DB_MULTIPLE"></a> |
| 592 | <code class="literal">DB_MULTIPLE</code> |
| 593 | </p> |
| 594 | <p> |
| 595 | Return multiple data items in the <span class="bold"><strong>data</strong></span> parameter. |
| 596 | </p> |
| 597 | <p> |
| 598 | In the case of Btree or Hash databases, duplicate data items for the |
| 599 | current key, starting at the current cursor position, are entered into |
| 600 | the buffer. Subsequent calls with both the DB_NEXT_DUP and |
| 601 | DB_MULTIPLE flags specified will return additional duplicate data |
| 602 | items associated with the current key or |
| 603 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 604 | if there are no additional duplicate data items to |
| 605 | return. Subsequent calls with both the DB_NEXT |
| 606 | and DB_MULTIPLE flags specified will return |
| 607 | additional duplicate data items associated with |
| 608 | the current key or if there are no additional |
| 609 | duplicate data items will return the next key and |
| 610 | its data items or |
| 611 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 612 | if there are no additional keys in the database. |
| 613 | </p> |
| 614 | <p> |
| 615 | In the case of Queue, Recno, or Heap databases, |
| 616 | data items starting at the current cursor position |
| 617 | are entered into the buffer. The record number |
| 618 | (or the RID, in the case of Heap) of |
| 619 | the first record will be returned in the |
| 620 | <span class="bold"><strong>key</strong></span> parameter. |
| 621 | For Queue and Recno, the record number of each |
| 622 | subsequent returned record must be calculated from |
| 623 | this value. For Heap databases, the RID of |
| 624 | subsequent returned records cannot be known. Subsequent |
| 625 | calls with the DB_MULTIPLE flag specified will |
| 626 | return additional data items or |
| 627 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 628 | if there are no additional data items to return. |
| 629 | </p> |
| 630 | <p> |
| 631 | The buffer to which the <span class="bold"><strong>data</strong></span> |
| 632 | parameter refers must be provided from user memory (see |
| 633 | <a class="link" href="dbt.html#dbt_DB_DBT_USERMEM">DB_DBT_USERMEM</a> ). |
| 634 | The buffer must be at least as large as the page size of the |
| 635 | underlying database, aligned for unsigned integer access, and be a |
| 636 | multiple of 1024 bytes in size. If the buffer size is insufficient, |
| 637 | then upon return from the call the size field of the <span class="bold"><strong>data</strong></span> parameter will have been set to an |
| 638 | estimated buffer size, and the error DB_BUFFER_SMALL is returned. |
| 639 | (The size is an estimate as the exact size needed may not be known |
| 640 | until all entries are read. It is best to initially provide a |
| 641 | relatively large buffer, but applications should be prepared to resize |
| 642 | the buffer as necessary and repeatedly call the method.) |
| 643 | </p> |
| 644 | <p> |
| 645 | The multiple data items can be iterated over using the |
| 646 | |
| 647 | <span> |
| 648 | <a class="xref" href="dbmultipledataiterator.html" title="DbMultipleDataIterator">DbMultipleDataIterator</a> class. |
| 649 | </span> |
| 650 | </p> |
| 651 | <p> |
| 652 | The DB_MULTIPLE flag may only be used with the DB_CURRENT, DB_FIRST, |
| 653 | DB_GET_BOTH, DB_GET_BOTH_RANGE, DB_NEXT, DB_NEXT_DUP, DB_NEXT_NODUP, |
| 654 | DB_SET, DB_SET_RANGE, and DB_SET_RECNO options. The DB_MULTIPLE flag |
| 655 | may not be used when accessing databases made into secondary indices |
| 656 | using the <a class="xref" href="dbassociate.html" title="Db::associate()">Db::associate()</a> method. |
| 657 | </p> |
| 658 | </li> |
| 659 | <li> |
| 660 | <p><a id="dbcget_DB_MULTIPLE_KEY"></a> |
| 661 | <code class="literal">DB_MULTIPLE_KEY</code> |
| 662 | </p> |
| 663 | <p> |
| 664 | Return multiple key and data pairs in the <span class="bold"><strong>data</strong></span> parameter. |
| 665 | </p> |
| 666 | <p> |
| 667 | Key and data pairs, starting at the current cursor position, are |
| 668 | entered into the buffer. Subsequent calls with both the DB_NEXT and |
| 669 | DB_MULTIPLE_KEY flags specified will return additional key and data |
| 670 | pairs or |
| 671 | <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> |
| 672 | if there are no additional key and data items to return. |
| 673 | </p> |
| 674 | <p> |
| 675 | In the case of Btree, Hash or Heap databases, the multiple key and data |
| 676 | pairs can be iterated over using the |
| 677 | |
| 678 | <span> |
| 679 | <a class="xref" href="dbmultiplekeydataiterator.html" title="DbMultipleKeyDataIterator">DbMultipleKeyDataIterator</a> class. |
| 680 | </span> |
| 681 | </p> |
| 682 | <p> |
| 683 | In the case of Queue or Recno databases, |
| 684 | the multiple record number and data pairs can be |
| 685 | iterated over using the |
| 686 | |
| 687 | <span> |
| 688 | <a class="xref" href="dbmultiplerecnodataiterator.html" title="DbMultipleRecnoDataIterator">DbMultipleRecnoDataIterator</a> class. |
| 689 | </span> |
| 690 | </p> |
| 691 | <p> |
| 692 | The buffer to which the <span class="bold"><strong>data</strong></span> |
| 693 | parameter refers must be provided from user memory (see |
| 694 | <a class="link" href="dbt.html#dbt_DB_DBT_USERMEM">DB_DBT_USERMEM</a> ). |
| 695 | The buffer must be at least as large as the page size of the |
| 696 | underlying database, aligned for unsigned integer access, and be a |
| 697 | multiple of 1024 bytes in size. If the buffer size is insufficient, |
| 698 | then upon return from the call the size field of the <span class="bold"><strong>data</strong></span> parameter will have been set to an |
| 699 | estimated buffer size, and the error DB_BUFFER_SMALL is returned. |
| 700 | (The size is an estimate as the exact size needed may not be known |
| 701 | until all entries are read. It is best to initially provide a |
| 702 | relatively large buffer, but applications should be prepared to resize |
| 703 | the buffer as necessary and repeatedly call the method.) |
| 704 | </p> |
| 705 | <p> |
| 706 | The DB_MULTIPLE_KEY flag may only be used with the DB_CURRENT, |
| 707 | DB_FIRST, DB_GET_BOTH, DB_GET_BOTH_RANGE, DB_NEXT, DB_NEXT_DUP, |
| 708 | DB_NEXT_NODUP, DB_SET, DB_SET_RANGE, and DB_SET_RECNO options. The |
| 709 | DB_MULTIPLE_KEY flag may not be used when accessing databases made |
| 710 | into secondary indices using the |
| 711 | <a class="xref" href="dbassociate.html" title="Db::associate()">Db::associate()</a> method. |
| 712 | </p> |
| 713 | </li> |
| 714 | <li> |
| 715 | <p><a id="dbcget_DB_RMW"></a> |
| 716 | <code class="literal">DB_RMW</code> |
| 717 | </p> |
| 718 | <p> |
| 719 | Acquire write locks instead of read locks when doing the read, if |
| 720 | locking is configured. Setting this flag can eliminate deadlock |
| 721 | during a read-modify-write cycle by acquiring the write lock during |
| 722 | the read part of the cycle so that another thread of control acquiring |
| 723 | a read lock for the same item, in its own read-modify-write cycle, |
| 724 | will not result in deadlock. |
| 725 | </p> |
| 726 | </li> |
| 727 | </ul> |
| 728 | </div> |
| 729 | </div> |
| 730 | </div> |
| 731 | <div class="sect2" lang="en" xml:lang="en"> |
| 732 | <div class="titlepage"> |
| 733 | <div> |
| 734 | <div> |
| 735 | <h3 class="title"><a id="idp6283416"></a>Errors</h3> |
| 736 | </div> |
| 737 | </div> |
| 738 | </div> |
| 739 | <p> |
| 740 | The <code class="methodname">Dbc::get()</code> <span> |
| 741 | |
| 742 | <span> |
| 743 | method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> |
| 744 | exception, encapsulating one of the following non-zero errors, or return one |
| 745 | of the following non-zero errors: |
| 746 | </span> |
| 747 | </span> |
| 748 | </p> |
| 749 | <div class="sect3" lang="en" xml:lang="en"> |
| 750 | <div class="titlepage"> |
| 751 | <div> |
| 752 | <div> |
| 753 | <h4 class="title"><a id="idp6291480"></a><span>DbMemoryException or </span>DB_BUFFER_SMALL</h4> |
| 754 | </div> |
| 755 | </div> |
| 756 | </div> |
| 757 | <p> |
| 758 | The requested item could not be returned due to undersized buffer. |
| 759 | </p> |
| 760 | <p> |
| 761 | <a class="xref" href="dbmemory.html" title="DbMemoryException">DbMemoryException</a> is thrown if |
| 762 | your Berkeley DB API is configured to throw exceptions. |
| 763 | Otherwise, <code class="literal">DB_BUFFER_SMALL</code> is returned. |
| 764 | </p> |
| 765 | </div> |
| 766 | <div class="sect3" lang="en" xml:lang="en"> |
| 767 | <div class="titlepage"> |
| 768 | <div> |
| 769 | <div> |
| 770 | <h4 class="title"><a id="idp6288496"></a><span>DbDeadlockException or </span>DB_LOCK_DEADLOCK</h4> |
| 771 | </div> |
| 772 | </div> |
| 773 | </div> |
| 774 | <p> |
| 775 | A transactional database environment operation was selected to resolve |
| 776 | a deadlock. |
| 777 | </p> |
| 778 | <p> |
| 779 | <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if |
| 780 | your Berkeley DB API is configured to throw exceptions. |
| 781 | Otherwise, <code class="literal">DB_LOCK_DEADLOCK</code> is returned. |
| 782 | </p> |
| 783 | </div> |
| 784 | <div class="sect3" lang="en" xml:lang="en"> |
| 785 | <div class="titlepage"> |
| 786 | <div> |
| 787 | <div> |
| 788 | <h4 class="title"><a id="idp6201488"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4> |
| 789 | </div> |
| 790 | </div> |
| 791 | </div> |
| 792 | <p> |
| 793 | A Berkeley DB Concurrent Data Store database environment configured |
| 794 | for lock timeouts was unable to grant a lock in the allowed time. |
| 795 | </p> |
| 796 | <p> |
| 797 | You attempted to open a database handle that is configured |
| 798 | for no waiting exclusive locking, but the exclusive lock could not be |
| 799 | immediately obtained. See |
| 800 | <a class="xref" href="dbset_lk_exclusive.html" title="Db::set_lk_exclusive()">Db::set_lk_exclusive()</a> |
| 801 | for more information. |
| 802 | </p> |
| 803 | <p> |
| 804 | <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if |
| 805 | your Berkeley DB API is configured to throw exceptions. |
| 806 | Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned. |
| 807 | </p> |
| 808 | </div> |
| 809 | <div class="sect3" lang="en" xml:lang="en"> |
| 810 | <div class="titlepage"> |
| 811 | <div> |
| 812 | <div> |
| 813 | <h4 class="title"><a id="idp6127128"></a> <span>DbRepHandleDeadException or</span> DB_REP_HANDLE_DEAD</h4> |
| 814 | </div> |
| 815 | </div> |
| 816 | </div> |
| 817 | <p> |
| 818 | When a client synchronizes with the master, it is possible for committed |
| 819 | transactions to be rolled back. This invalidates all the database and cursor |
| 820 | handles opened in the replication environment. Once this occurs, an attempt to use |
| 821 | such a handle will |
| 822 | <span> |
| 823 | throw a <a class="xref" href="dbrephandledead.html" title="DbRepHandleDeadException">DbRepHandleDeadException</a> (if |
| 824 | your application is configured to throw exceptions), or |
| 825 | </span> |
| 826 | return <code class="literal">DB_REP_HANDLE_DEAD</code>. |
| 827 | The application will need to discard the handle and open a new one in order to |
| 828 | continue processing. |
| 829 | </p> |
| 830 | </div> |
| 831 | <div class="sect3" lang="en" xml:lang="en"> |
| 832 | <div class="titlepage"> |
| 833 | <div> |
| 834 | <div> |
| 835 | <h4 class="title"><a id="idp6218328"></a>DB_REP_LEASE_EXPIRED</h4> |
| 836 | </div> |
| 837 | </div> |
| 838 | </div> |
| 839 | <p> |
| 840 | The operation failed because the site's replication master lease has expired. |
| 841 | </p> |
| 842 | </div> |
| 843 | <div class="sect3" lang="en" xml:lang="en"> |
| 844 | <div class="titlepage"> |
| 845 | <div> |
| 846 | <div> |
| 847 | <h4 class="title"><a id="idp6216376"></a><span>DbDeadlockException or </span>DB_REP_LOCKOUT</h4> |
| 848 | </div> |
| 849 | </div> |
| 850 | </div> |
| 851 | <p> |
| 852 | The operation was blocked by client/master synchronization. |
| 853 | </p> |
| 854 | <p> |
| 855 | <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if |
| 856 | your Berkeley DB API is configured to throw exceptions. |
| 857 | Otherwise, <code class="literal">DB_REP_LOCKOUT</code> is returned. |
| 858 | </p> |
| 859 | </div> |
| 860 | <div class="sect3" lang="en" xml:lang="en"> |
| 861 | <div class="titlepage"> |
| 862 | <div> |
| 863 | <div> |
| 864 | <h4 class="title"><a id="idp6197752"></a>DB_SECONDARY_BAD</h4> |
| 865 | </div> |
| 866 | </div> |
| 867 | </div> |
| 868 | <p> |
| 869 | A secondary index references a nonexistent primary key. |
| 870 | </p> |
| 871 | </div> |
| 872 | <div class="sect3" lang="en" xml:lang="en"> |
| 873 | <div class="titlepage"> |
| 874 | <div> |
| 875 | <div> |
| 876 | <h4 class="title"><a id="idp6202088"></a>EINVAL</h4> |
| 877 | </div> |
| 878 | </div> |
| 879 | </div> |
| 880 | <p> |
| 881 | If the DB_CURRENT, DB_NEXT_DUP or DB_PREV_DUP flags were |
| 882 | specified and the cursor has not been initialized; the |
| 883 | <code class="methodname">Dbc::pget()</code> method was called with |
| 884 | a cursor that does not refer to a secondary index; or if an |
| 885 | invalid flag value or parameter was specified. |
| 886 | </p> |
| 887 | </div> |
| 888 | </div> |
| 889 | <div class="sect2" lang="en" xml:lang="en"> |
| 890 | <div class="titlepage"> |
| 891 | <div> |
| 892 | <div> |
| 893 | <h3 class="title"><a id="idp6289776"></a>Class</h3> |
| 894 | </div> |
| 895 | </div> |
| 896 | </div> |
| 897 | <p> |
| 898 | <a class="link" href="dbc.html" title="Chapter 3. The Dbc Handle">Dbc</a> |
| 899 | </p> |
| 900 | </div> |
| 901 | <div class="sect2" lang="en" xml:lang="en"> |
| 902 | <div class="titlepage"> |
| 903 | <div> |
| 904 | <div> |
| 905 | <h3 class="title"><a id="idp6201616"></a>See Also</h3> |
| 906 | </div> |
| 907 | </div> |
| 908 | </div> |
| 909 | <p> |
| 910 | <a class="xref" href="dbc.html#dbclist" title="Database Cursors and Related Methods">Database Cursors and Related Methods</a> |
| 911 | </p> |
| 912 | </div> |
| 913 | </div> |
| 914 | <div class="navfooter"> |
| 915 | <hr /> |
| 916 | <table width="100%" summary="Navigation footer"> |
| 917 | <tr> |
| 918 | <td width="40%" align="left"><a accesskey="p" href="dbcdup.html">Prev</a> </td> |
| 919 | <td width="20%" align="center"> |
| 920 | <a accesskey="u" href="dbc.html">Up</a> |
| 921 | </td> |
| 922 | <td width="40%" align="right"> <a accesskey="n" href="dbcget_priority.html">Next</a></td> |
| 923 | </tr> |
| 924 | <tr> |
| 925 | <td width="40%" align="left" valign="top">Dbc::dup() </td> |
| 926 | <td width="20%" align="center"> |
| 927 | <a accesskey="h" href="index.html">Home</a> |
| 928 | </td> |
| 929 | <td width="40%" align="right" valign="top"> Dbc::get_priority()</td> |
| 930 | </tr> |
| 931 | </table> |
| 932 | </div> |
| 933 | </body> |
| 934 | </html> |