• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/db-4.8.30/docs/api_reference/C/
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>DB-&gt;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="db.html" title="Chapter��2.�� The DB Handle" />
11    <link rel="prev" href="dbfd.html" title="DB-&gt;fd()" />
12    <link rel="next" href="dbget_bt_minkey.html" title="DB-&gt;get_bt_minkey()" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">DB-&gt;get()</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="dbfd.html">Prev</a>��</td>
22          <th width="60%" align="center">Chapter��2.��
23                The DB Handle
24        </th>
25          <td width="20%" align="right">��<a accesskey="n" href="dbget_bt_minkey.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="dbget"></a>DB-&gt;get()</h2>
35          </div>
36        </div>
37      </div>
38      <pre class="programlisting">#include &lt;db.h&gt;
39
40int
41DB-&gt;get(DB *db,
42    DB_TXN *txnid, DBT *key, DBT *data, u_int32_t flags);
43
44int
45DB-&gt;pget(DB *db,
46    DB_TXN *txnid, DBT *key, DBT *pkey, DBT *data, u_int32_t flags);  </pre>
47      <p>
48         The <code class="methodname">DB-&gt;get()</code> method retrieves key/data pairs from the database.  The
49         address and length of the data associated with the specified <span class="bold"><strong>key</strong></span> are returned in the structure to which
50         <span class="bold"><strong>data</strong></span> refers.
51    </p>
52      <p>
53         In the presence of duplicate key values,
54         <code class="methodname">DB-&gt;get()</code> will return the first data
55         item for the designated key.  Duplicates are sorted by:
56     </p>
57      <div class="itemizedlist">
58        <ul type="disc">
59          <li>
60            <p>
61                Their sort order, if a duplicate sort function was specified. 
62             </p>
63          </li>
64          <li>
65            <p>
66                Any explicit cursor designated insertion. 
67             </p>
68          </li>
69          <li>
70            <p>
71                By insert order. This is the default behavior.
72             </p>
73          </li>
74        </ul>
75      </div>
76      <p>
77         <span class="bold"><strong>Retrieval of duplicates requires the
78         use of cursor operations.</strong></span> See 
79         <a class="xref" href="dbcget.html" title="DBcursor-&gt;get()">DBcursor-&gt;get()</a>  for details.
80    </p>
81      <p>
82         When called on a database that has been made into a secondary index
83         using the <a class="xref" href="dbassociate.html" title="DB-&gt;associate()">DB-&gt;associate()</a>  
84         method, the <code class="methodname">DB-&gt;get()</code> and <code class="methodname">DB-&gt;pget()</code> 
85         methods return the key from the secondary
86         index and the data item from the primary database.  In addition, the
87         <code class="methodname">DB-&gt;pget()</code> method returns the key from the primary database.  In
88         databases that are not secondary indices, the <code class="methodname">DB-&gt;pget()</code> method will
89         always fail.
90    </p>
91      <p>
92         The <code class="methodname">DB-&gt;get()</code> method will return <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> if
93         the specified key is not in the database. The <code class="methodname">DB-&gt;get()</code> method will
94         return <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_KEYEMPTY" class="olink">DB_KEYEMPTY</a> if
95         the database is a Queue or Recno database and the specified key
96         exists, but was never explicitly created by the application or was
97         later deleted. Unless otherwise specified, the
98         <code class="methodname">DB-&gt;get()</code> <span>
99            <span>
100                  method returns a non-zero error value on failure and 0 on success.
101            </span>
102            
103        </span>
104    </p>
105      <div class="sect2" lang="en" xml:lang="en">
106        <div class="titlepage">
107          <div>
108            <div>
109              <h3 class="title"><a id="id1634398"></a>Parameters</h3>
110            </div>
111          </div>
112        </div>
113        <div class="sect3" lang="en" xml:lang="en">
114          <div class="titlepage">
115            <div>
116              <div>
117                <h4 class="title"><a id="id1634708"></a>data</h4>
118              </div>
119            </div>
120          </div>
121          <p>
122                          The data <a class="link" href="dbt.html" title="Chapter��4.�� The DBT Handle">DBT</a>  operated on.
123                     </p>
124        </div>
125        <div class="sect3" lang="en" xml:lang="en">
126          <div class="titlepage">
127            <div>
128              <div>
129                <h4 class="title"><a id="id1634754"></a>flags</h4>
130              </div>
131            </div>
132          </div>
133          <p>
134                          The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
135                          or one of the following values:
136                     </p>
137          <div class="itemizedlist">
138            <ul type="disc">
139              <li>
140                <p><a id="dbget_DB_CONSUME"></a>
141                  <code class="literal">DB_CONSUME</code>
142            </p>
143                <p>
144                 Return the record number and data from the available record closest to
145                 the head of the queue, and delete the record.  The record number will
146                 be returned in <span class="bold"><strong>key</strong></span>, as described in
147                 <a class="link" href="dbt.html" title="Chapter��4.�� The DBT Handle">DBT</a>.  The data will be
148                 returned in the <span class="bold"><strong>data</strong></span> parameter.  A
149                 record is available if it is not deleted and is not currently locked. 
150                 The underlying database must be of type Queue for DB_CONSUME to be
151                 specified.
152            </p>
153              </li>
154              <li>
155                <p><a id="dbget_DB_CONSUME_WAIT"></a>
156                  <code class="literal">DB_CONSUME_WAIT</code>
157            </p>
158                <p>
159                 The DB_CONSUME_WAIT flag is the same as the DB_CONSUME flag, except
160                 that if the Queue database is empty, the thread of control will wait
161                 until there is data in the queue before returning.  The underlying
162                 database must be of type Queue for DB_CONSUME_WAIT to be specified.
163            </p>
164                <p>
165                If lock or transaction timeouts have been specified, the <code class="methodname">DB-&gt;get()</code>
166                method with the DB_CONSUME_WAIT flag may return <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_LOCK_NOTGRANTED" class="olink">DB_LOCK_NOTGRANTED</a>.
167                This failure, by itself, does not require the enclosing transaction be
168                aborted.
169            </p>
170              </li>
171              <li>
172                <p><a id="get_DB_GET_BOTH"></a>
173                  <code class="literal">DB_GET_BOTH</code>
174            </p>
175                <p>
176                 Retrieve the key/data pair only if both the key and data match the
177                 arguments.
178            </p>
179                <p>
180                When using a secondary index handle, the <code class="literal">DB_GET_BOTH</code>:
181                flag causes:
182            </p>
183                <div class="itemizedlist">
184                  <ul type="circle">
185                    <li>
186                      <p>
187                        the <code class="methodname">DB-&gt;pget()</code> version of
188                        this method to retun the secondary key/primary
189                        key/data tuple only if both the primary and
190                        secondary keys match the arguments.
191                    </p>
192                    </li>
193                    <li>
194                      <p>
195                        the <code class="methodname">DB-&gt;get()</code> version of this method
196                        to result in an error.
197                    </p>
198                    </li>
199                  </ul>
200                </div>
201              </li>
202              <li>
203                <p><a id="dbget_DB_SET_RECNO"></a>
204                  <code class="literal">DB_SET_RECNO</code>
205            </p>
206                <p>
207                 Retrieve the specified numbered key/data pair from a database.  Upon
208                 return, both the <span class="bold"><strong>key</strong></span> and <span class="bold"><strong>data</strong></span> items will have been filled in.
209            </p>
210                <p>
211                 The <span class="bold"><strong>data</strong></span> field of the specified
212                 <span class="bold"><strong>key</strong></span> must be a pointer to a logical
213                 record number (that is, a <span class="bold"><strong>db_recno_t</strong></span>).  This record number determines the
214                 record to be retrieved.
215            </p>
216                <p>
217                 For DB_SET_RECNO to be specified, the underlying database must be of
218                 type Btree, and it must have been created with the DB_RECNUM flag.
219            </p>
220              </li>
221            </ul>
222          </div>
223          <p>
224                 In addition, the following flags may be set by bitwise inclusively
225                 <span class="bold"><strong>OR</strong></span>'ing them into the <span class="bold"><strong>flags</strong></span> parameter:
226            </p>
227          <div class="itemizedlist">
228            <ul type="disc">
229              <li>
230                <p><a id="get_DB_IGNORE_LEASE"></a>
231                  <code class="literal">DB_IGNORE_LEASE</code>
232            </p>
233                <p>
234                 Return the data item irrespective of the state of master leases.  The
235                 item will be returned under all conditions: if master leases are not
236                 configured, if the request is made to a client, if the request is made
237                 to a master with a valid lease, or if the request is made to a master
238                 without a valid lease.
239            </p>
240              </li>
241              <li>
242                <p><a id="get_DB_MULTIPLE"></a>
243                  <code class="literal">DB_MULTIPLE</code>
244            </p>
245                <p>
246                 Return multiple data items in the buffer to which the <span class="bold"><strong>data</strong></span> parameter refers.
247            </p>
248                <p>
249                 In the case of Btree or Hash databases, all of the data items
250                 associated with the specified key are entered into the buffer.  In the
251                 case of Queue or Recno databases, all of the data items in the
252                 database, starting at, and subsequent to, the specified key, are
253                 entered into the buffer.
254            </p>
255                <p>
256                 The buffer to which the <span class="bold"><strong>data</strong></span>
257                 parameter refers must be provided from user memory (see 
258                 <a class="link" href="dbt.html#dbt_DB_DBT_USERMEM">DB_DBT_USERMEM</a>). 
259                 The buffer must be at least as large as the page size of the
260                 underlying database, aligned for unsigned integer access, and be a
261                 multiple of 1024 bytes in size.  If the buffer size is insufficient,
262                 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
263                 estimated buffer size, and the error DB_BUFFER_SMALL is returned. 
264                 (The size is an estimate as the exact size needed may not be known
265                 until all entries are read.  It is best to initially provide a
266                 relatively large buffer, but applications should be prepared to resize
267                 the buffer as necessary and repeatedly call the method.)
268            </p>
269                <p>
270                 The DB_MULTIPLE flag may only be used alone, or with the DB_GET_BOTH
271                 and DB_SET_RECNO options.  The DB_MULTIPLE flag may not be used when
272                 accessing databases made into secondary indices using the 
273                 <a class="xref" href="dbassociate.html" title="DB-&gt;associate()">DB-&gt;associate()</a>  method.
274            </p>
275                <p>
276                 See the <a class="xref" href="dbt.html#dbtlist" title="DBT and Bulk Operations">DBT and Bulk Operations</a>
277                 for more information on working with bulk get.
278            </p>
279              </li>
280              <li>
281                <p><a id="get_DB_READ_COMMITTED"></a>
282                  <code class="literal">DB_READ_COMMITTED</code>
283            </p>
284                <p>
285                 Configure a transactional get operation to have degree 2 isolation
286                 (the read is not repeatable).
287            </p>
288              </li>
289              <li>
290                <p><a id="get_DB_READ_UNCOMMITTED"></a>
291                  <code class="literal">DB_READ_UNCOMMITTED</code>
292            </p>
293                <p>
294                 Configure a transactional get operation to have degree 1 isolation,
295                 reading modified but not yet committed data.  Silently ignored if the
296                 <a class="link" href="dbopen.html#dbopen_DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a> 
297                 flag was not specified when the underlying database was opened.
298            </p>
299              </li>
300              <li>
301                <p><a id="get_DB_RMW"></a>
302                 <code class="literal">DB_RMW</code>
303            </p>
304                <p>
305                 Acquire write locks instead of read locks when doing the read, if
306                 locking is configured.  Setting this flag can eliminate deadlock
307                 during a read-modify-write cycle by acquiring the write lock during
308                 the read part of the cycle so that another thread of control acquiring
309                 a read lock for the same item, in its own read-modify-write cycle,
310                 will not result in deadlock.
311            </p>
312                <p>
313                 Because the <code class="methodname">DB-&gt;get()</code> method will not hold locks across Berkeley DB
314                 calls in non-transactional operations, the 
315                 <a class="link" href="dbcget.html#dbcget_DB_RMW">DB_RMW</a>  flag to the
316                 <code class="methodname">DB-&gt;get()</code> call is meaningful only in the presence of transactions.
317            </p>
318              </li>
319            </ul>
320          </div>
321        </div>
322        <div class="sect3" lang="en" xml:lang="en">
323          <div class="titlepage">
324            <div>
325              <div>
326                <h4 class="title"><a id="id1635213"></a>key</h4>
327              </div>
328            </div>
329          </div>
330          <p>
331                          The key <a class="link" href="dbt.html" title="Chapter��4.�� The DBT Handle">DBT</a> operated on.
332                     </p>
333        </div>
334        <div class="sect3" lang="en" xml:lang="en">
335          <div class="titlepage">
336            <div>
337              <div>
338                <h4 class="title"><a id="id1634709"></a>pkey</h4>
339              </div>
340            </div>
341          </div>
342          <p>
343                          The <span class="bold"><strong>pkey</strong></span> parameter is the return key
344                          from the primary database.
345                     </p>
346        </div>
347        <div class="sect3" lang="en" xml:lang="en">
348          <div class="titlepage">
349            <div>
350              <div>
351                <h4 class="title"><a id="id1635117"></a>txnid</h4>
352              </div>
353            </div>
354          </div>
355          <p>
356                          If the operation is part of an application-specified transaction, the
357                          <span class="bold"><strong>txnid</strong></span> parameter is a transaction
358                          handle returned from <a class="xref" href="txnbegin.html" title="DB_ENV-&gt;txn_begin()">DB_ENV-&gt;txn_begin()</a>; 
359                          if the operation is part of a Berkeley DB Concurrent Data Store group, the
360                          <span class="bold"><strong>txnid</strong></span> parameter is a handle returned
361                          from <a class="xref" href="envcdsgroup_begin.html" title="DB_ENV-&gt;cdsgroup_begin()">DB_ENV-&gt;cdsgroup_begin()</a>;
362                          otherwise NULL. If no transaction handle is specified, but the
363                          operation occurs in a transactional database, the operation will be
364                          implicitly transaction protected.
365                     </p>
366        </div>
367      </div>
368      <div class="sect2" lang="en" xml:lang="en">
369        <div class="titlepage">
370          <div>
371            <div>
372              <h3 class="title"><a id="id1634360"></a>Errors</h3>
373            </div>
374          </div>
375        </div>
376        <p>
377                         The <code class="methodname">DB-&gt;get()</code> <span>
378            <span>
379                 method may fail and return one of the following non-zero errors:
380            </span>
381            
382        </span>
383                    </p>
384        <div class="sect3" lang="en" xml:lang="en">
385          <div class="titlepage">
386            <div>
387              <div>
388                <h4 class="title"><a id="id1635426"></a>DB_BUFFER_SMALL</h4>
389              </div>
390            </div>
391          </div>
392          <p>
393                The requested item could not be returned due to undersized buffer.
394            </p>
395        </div>
396        <div class="sect3" lang="en" xml:lang="en">
397          <div class="titlepage">
398            <div>
399              <div>
400                <h4 class="title"><a id="id1635125"></a>DB_LOCK_DEADLOCK</h4>
401              </div>
402            </div>
403          </div>
404          <p>
405                A transactional database environment operation was selected to resolve
406                a deadlock.
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="id1635087"></a>DB_LOCK_NOTGRANTED</h4>
414              </div>
415            </div>
416          </div>
417          <p>
418                A Berkeley DB Concurrent Data Store database environment configured
419                for lock timeouts was unable to grant a lock in the allowed time.
420            </p>
421        </div>
422        <div class="sect3" lang="en" xml:lang="en">
423          <div class="titlepage">
424            <div>
425              <div>
426                <h4 class="title"><a id="id1635112"></a>DB_LOCK_NOTGRANTED</h4>
427              </div>
428            </div>
429          </div>
430          <p>
431                The <code class="literal">DB_CONSUME_WAIT</code> flag was specified, lock or transaction timers
432                were configured and the lock could not be granted before the wait-time
433                expired.
434            </p>
435        </div>
436        <div class="sect3" lang="en" xml:lang="en">
437          <div class="titlepage">
438            <div>
439              <div>
440                <h4 class="title"><a id="id1634745"></a> DB_REP_HANDLE_DEAD</h4>
441              </div>
442            </div>
443          </div>
444          <p>
445                When a client synchronizes with the master, it is possible for committed
446                transactions to be rolled back. This invalidates all  the database and cursor
447                handles opened in the replication environment. Once this occurs, an attempt to use
448                such a handle will 
449                
450                return <code class="literal">DB_REP_HANDLE_DEAD</code>.
451                The application will need to discard the handle and open a new one in order to
452                continue processing.
453            </p>
454        </div>
455        <div class="sect3" lang="en" xml:lang="en">
456          <div class="titlepage">
457            <div>
458              <div>
459                <h4 class="title"><a id="id1635405"></a>DB_REP_LEASE_EXPIRED</h4>
460              </div>
461            </div>
462          </div>
463          <p>
464                The operation failed because the site's replication master lease has expired.
465            </p>
466        </div>
467        <div class="sect3" lang="en" xml:lang="en">
468          <div class="titlepage">
469            <div>
470              <div>
471                <h4 class="title"><a id="id1635202"></a>DB_REP_LOCKOUT</h4>
472              </div>
473            </div>
474          </div>
475          <p>
476                The operation was blocked by client/master synchronization.
477            </p>
478        </div>
479        <div class="sect3" lang="en" xml:lang="en">
480          <div class="titlepage">
481            <div>
482              <div>
483                <h4 class="title"><a id="id1634888"></a>DB_SECONDARY_BAD</h4>
484              </div>
485            </div>
486          </div>
487          <p>
488                A secondary index references a nonexistent primary key.
489            </p>
490        </div>
491        <div class="sect3" lang="en" xml:lang="en">
492          <div class="titlepage">
493            <div>
494              <div>
495                <h4 class="title"><a id="id1635167"></a>EINVAL</h4>
496              </div>
497            </div>
498          </div>
499          <p>
500                          If a record number of 0 was specified; the 
501                          <a class="link" href="envopen.html#envopen_DB_THREAD">DB_THREAD</a>  flag was
502                          specified to the <a class="xref" href="dbopen.html" title="DB-&gt;open()">DB-&gt;open()</a>  method and none of the
503                          <a class="link" href="dbt.html#dbt_DB_DBT_MALLOC">DB_DBT_MALLOC</a>,
504                          <a class="link" href="dbt.html#dbt_DB_DBT_REALLOC">DB_DBT_REALLOC</a>  or
505                          <a class="link" href="dbt.html#dbt_DB_DBT_USERMEM">DB_DBT_USERMEM</a> 
506                          flags were set in the <a class="link" href="dbt.html" title="Chapter��4.�� The DBT Handle">DBT</a>; 
507                          the <code class="methodname">DB-&gt;pget()</code> method was called with a 
508                          <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a>  handle
509                          that does not refer to a secondary index; or if an invalid flag value
510                          or parameter was specified.
511                    </p>
512        </div>
513      </div>
514      <div class="sect2" lang="en" xml:lang="en">
515        <div class="titlepage">
516          <div>
517            <div>
518              <h3 class="title"><a id="id1635252"></a>Class</h3>
519            </div>
520          </div>
521        </div>
522        <p>
523                <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a>  
524            </p>
525      </div>
526      <div class="sect2" lang="en" xml:lang="en">
527        <div class="titlepage">
528          <div>
529            <div>
530              <h3 class="title"><a id="id1634720"></a>See Also</h3>
531            </div>
532          </div>
533        </div>
534        <p>
535                     <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 
536                </p>
537      </div>
538    </div>
539    <div class="navfooter">
540      <hr />
541      <table width="100%" summary="Navigation footer">
542        <tr>
543          <td width="40%" align="left"><a accesskey="p" href="dbfd.html">Prev</a>��</td>
544          <td width="20%" align="center">
545            <a accesskey="u" href="db.html">Up</a>
546          </td>
547          <td width="40%" align="right">��<a accesskey="n" href="dbget_bt_minkey.html">Next</a></td>
548        </tr>
549        <tr>
550          <td width="40%" align="left" valign="top">DB-&gt;fd()��</td>
551          <td width="20%" align="center">
552            <a accesskey="h" href="index.html">Home</a>
553          </td>
554          <td width="40%" align="right" valign="top">��DB-&gt;get_bt_minkey()</td>
555        </tr>
556      </table>
557    </div>
558  </body>
559</html>
560