Sophie

Sophie

distrib > Mageia > 3 > i586 > by-pkgid > 0699fb90d9745ad7ed1b15348c479e5d > files > 430

libdb4.8-devel-4.8.30-10.mga3.i586.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Db::get()</title>
    <link rel="stylesheet" href="apiReference.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Berkeley DB C++ API Reference" />
    <link rel="up" href="db.html" title="Chapter 2.  The Db Handle" />
    <link rel="prev" href="dbfd.html" title="Db::fd()" />
    <link rel="next" href="dbget_bt_minkey.html" title="Db::get_bt_minkey()" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Db::get()</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="dbfd.html">Prev</a> </td>
          <th width="60%" align="center">Chapter 2. 
                The Db Handle
        </th>
          <td width="20%" align="right"> <a accesskey="n" href="dbget_bt_minkey.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="dbget"></a>Db::get()</h2>
          </div>
        </div>
      </div>
      <pre class="programlisting">#include &lt;db_cxx.h&gt;

int
Db::get(DbTxn *txnid, Dbt *key, Dbt *data, u_int32_t flags);

int
Db::pget(DbTxn *txnid, Dbt *key, Dbt *pkey, Dbt *data, u_int32_t flags); </pre>
      <p>
         The <code class="methodname">Db::get()</code> method retrieves key/data pairs from the database.  The
         address and length of the data associated with the specified <span class="bold"><strong>key</strong></span> are returned in the structure to which
         <span class="bold"><strong>data</strong></span> refers.
    </p>
      <p>
         In the presence of duplicate key values,
         <code class="methodname">Db::get()</code> will return the first data
         item for the designated key.  Duplicates are sorted by:
     </p>
      <div class="itemizedlist">
        <ul type="disc">
          <li>
            <p>
                Their sort order, if a duplicate sort function was specified. 
             </p>
          </li>
          <li>
            <p>
                Any explicit cursor designated insertion. 
             </p>
          </li>
          <li>
            <p>
                By insert order. This is the default behavior.
             </p>
          </li>
        </ul>
      </div>
      <p>
         <span class="bold"><strong>Retrieval of duplicates requires the
         use of cursor operations.</strong></span> See 
         <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a>  for details.
    </p>
      <p>
         When called on a database that has been made into a secondary index
         using the <a class="xref" href="dbassociate.html" title="Db::associate()">Db::associate()</a>  
         method, the <code class="methodname">Db::get()</code> and <code class="methodname">Db::pget()</code> 
         methods return the key from the secondary
         index and the data item from the primary database.  In addition, the
         <code class="methodname">Db::pget()</code> method returns the key from the primary database.  In
         databases that are not secondary indices, the <code class="methodname">Db::pget()</code> method will
         always fail.
    </p>
      <p>
         The <code class="methodname">Db::get()</code> method will return <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_NOTFOUND" class="olink">DB_NOTFOUND</a> if
         the specified key is not in the database. The <code class="methodname">Db::get()</code> method will
         return <a href="../../programmer_reference/program_errorret.html#program_errorret.DB_KEYEMPTY" class="olink">DB_KEYEMPTY</a> if
         the database is a Queue or Recno database and the specified key
         exists, but was never explicitly created by the application or was
         later deleted. Unless otherwise specified, the
         <code class="methodname">Db::get()</code> <span>
            
            <span>
                method either returns a non-zero error value or throws an
                exception that encapsulates a non-zero error value on
                failure, and returns 0 on success.
            </span>
        </span>
    </p>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="id1634132"></a>Parameters</h3>
            </div>
          </div>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1634440"></a>data</h4>
              </div>
            </div>
          </div>
          <p>
                          The data <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>  operated on.
                     </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1634571"></a>flags</h4>
              </div>
            </div>
          </div>
          <p>
                          The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
                          or one of the following values:
                     </p>
          <div class="itemizedlist">
            <ul type="disc">
              <li>
                <p><a id="dbget_DB_CONSUME"></a>
                  <code class="literal">DB_CONSUME</code>
            </p>
                <p>
                 Return the record number and data from the available record closest to
                 the head of the queue, and delete the record.  The record number will
                 be returned in <span class="bold"><strong>key</strong></span>, as described in
                 <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>.  The data will be
                 returned in the <span class="bold"><strong>data</strong></span> parameter.  A
                 record is available if it is not deleted and is not currently locked. 
                 The underlying database must be of type Queue for DB_CONSUME to be
                 specified.
            </p>
              </li>
              <li>
                <p><a id="dbget_DB_CONSUME_WAIT"></a>
                  <code class="literal">DB_CONSUME_WAIT</code>
            </p>
                <p>
                 The DB_CONSUME_WAIT flag is the same as the DB_CONSUME flag, except
                 that if the Queue database is empty, the thread of control will wait
                 until there is data in the queue before returning.  The underlying
                 database must be of type Queue for DB_CONSUME_WAIT to be specified.
            </p>
                <p>
                If lock or transaction timeouts have been specified, the <code class="methodname">Db::get()</code>
                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>.
                This failure, by itself, does not require the enclosing transaction be
                aborted.
            </p>
              </li>
              <li>
                <p><a id="get_DB_GET_BOTH"></a>
                  <code class="literal">DB_GET_BOTH</code>
            </p>
                <p>
                 Retrieve the key/data pair only if both the key and data match the
                 arguments.
            </p>
                <p>
                When using a secondary index handle, the <code class="literal">DB_GET_BOTH</code>:
                flag causes:
            </p>
                <div class="itemizedlist">
                  <ul type="circle">
                    <li>
                      <p>
                        the <code class="methodname">Db::pget()</code> version of
                        this method to retun the secondary key/primary
                        key/data tuple only if both the primary and
                        secondary keys match the arguments.
                    </p>
                    </li>
                    <li>
                      <p>
                        the <code class="methodname">Db::get()</code> version of this method
                        to result in an error.
                    </p>
                    </li>
                  </ul>
                </div>
              </li>
              <li>
                <p><a id="dbget_DB_SET_RECNO"></a>
                  <code class="literal">DB_SET_RECNO</code>
            </p>
                <p>
                 Retrieve the specified numbered key/data pair from a database.  Upon
                 return, both the <span class="bold"><strong>key</strong></span> and <span class="bold"><strong>data</strong></span> items will have been filled in.
            </p>
                <p>
                 The <span class="bold"><strong>data</strong></span> field of the specified
                 <span class="bold"><strong>key</strong></span> must be a pointer to a logical
                 record number (that is, a <span class="bold"><strong>db_recno_t</strong></span>).  This record number determines the
                 record to be retrieved.
            </p>
                <p>
                 For DB_SET_RECNO to be specified, the underlying database must be of
                 type Btree, and it must have been created with the DB_RECNUM flag.
            </p>
              </li>
            </ul>
          </div>
          <p>
                 In addition, the following flags may be set by bitwise inclusively
                 <span class="bold"><strong>OR</strong></span>'ing them into the <span class="bold"><strong>flags</strong></span> parameter:
            </p>
          <div class="itemizedlist">
            <ul type="disc">
              <li>
                <p><a id="get_DB_IGNORE_LEASE"></a>
                  <code class="literal">DB_IGNORE_LEASE</code>
            </p>
                <p>
                 Return the data item irrespective of the state of master leases.  The
                 item will be returned under all conditions: if master leases are not
                 configured, if the request is made to a client, if the request is made
                 to a master with a valid lease, or if the request is made to a master
                 without a valid lease.
            </p>
              </li>
              <li>
                <p><a id="get_DB_MULTIPLE"></a>
                  <code class="literal">DB_MULTIPLE</code>
            </p>
                <p>
                 Return multiple data items in the buffer to which the <span class="bold"><strong>data</strong></span> parameter refers.
            </p>
                <p>
                 In the case of Btree or Hash databases, all of the data items
                 associated with the specified key are entered into the buffer.  In the
                 case of Queue or Recno databases, all of the data items in the
                 database, starting at, and subsequent to, the specified key, are
                 entered into the buffer.
            </p>
                <p>
                 The buffer to which the <span class="bold"><strong>data</strong></span>
                 parameter refers must be provided from user memory (see 
                 <a class="link" href="dbt.html#dbt_DB_DBT_USERMEM">DB_DBT_USERMEM</a>). 
                 The buffer must be at least as large as the page size of the
                 underlying database, aligned for unsigned integer access, and be a
                 multiple of 1024 bytes in size.  If the buffer size is insufficient,
                 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
                 estimated buffer size, and the error DB_BUFFER_SMALL is returned. 
                 (The size is an estimate as the exact size needed may not be known
                 until all entries are read.  It is best to initially provide a
                 relatively large buffer, but applications should be prepared to resize
                 the buffer as necessary and repeatedly call the method.)
            </p>
                <p>
                 The DB_MULTIPLE flag may only be used alone, or with the DB_GET_BOTH
                 and DB_SET_RECNO options.  The DB_MULTIPLE flag may not be used when
                 accessing databases made into secondary indices using the 
                 <a class="xref" href="dbassociate.html" title="Db::associate()">Db::associate()</a>  method.
            </p>
                <p>
                 See the <a class="xref" href="dbt.html#dbtlist" title="DBT and Bulk Operations">DBT and Bulk Operations</a>
                 for more information on working with bulk get.
            </p>
              </li>
              <li>
                <p><a id="get_DB_READ_COMMITTED"></a>
                  <code class="literal">DB_READ_COMMITTED</code>
            </p>
                <p>
                 Configure a transactional get operation to have degree 2 isolation
                 (the read is not repeatable).
            </p>
              </li>
              <li>
                <p><a id="get_DB_READ_UNCOMMITTED"></a>
                  <code class="literal">DB_READ_UNCOMMITTED</code>
            </p>
                <p>
                 Configure a transactional get operation to have degree 1 isolation,
                 reading modified but not yet committed data.  Silently ignored if the
                 <a class="link" href="dbopen.html#dbopen_DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a> 
                 flag was not specified when the underlying database was opened.
            </p>
              </li>
              <li>
                <p><a id="get_DB_RMW"></a>
                 <code class="literal">DB_RMW</code>
            </p>
                <p>
                 Acquire write locks instead of read locks when doing the read, if
                 locking is configured.  Setting this flag can eliminate deadlock
                 during a read-modify-write cycle by acquiring the write lock during
                 the read part of the cycle so that another thread of control acquiring
                 a read lock for the same item, in its own read-modify-write cycle,
                 will not result in deadlock.
            </p>
                <p>
                 Because the <code class="methodname">Db::get()</code> method will not hold locks across Berkeley DB
                 calls in non-transactional operations, the 
                 <a class="link" href="dbcget.html#dbcget_DB_RMW">DB_RMW</a>  flag to the
                 <code class="methodname">Db::get()</code> call is meaningful only in the presence of transactions.
            </p>
              </li>
            </ul>
          </div>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1634585"></a>key</h4>
              </div>
            </div>
          </div>
          <p>
                          The key <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> operated on.
                     </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1634981"></a>pkey</h4>
              </div>
            </div>
          </div>
          <p>
                          The <span class="bold"><strong>pkey</strong></span> parameter is the return key
                          from the primary database.
                     </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1635162"></a>txnid</h4>
              </div>
            </div>
          </div>
          <p>
                          If the operation is part of an application-specified transaction, the
                          <span class="bold"><strong>txnid</strong></span> parameter is a transaction
                          handle returned from <a class="xref" href="txnbegin.html" title="DbEnv::txn_begin()">DbEnv::txn_begin()</a>; 
                          if the operation is part of a Berkeley DB Concurrent Data Store group, the
                          <span class="bold"><strong>txnid</strong></span> parameter is a handle returned
                          from <a class="xref" href="envcdsgroup_begin.html" title="DbEnv::cdsgroup_begin()">DbEnv::cdsgroup_begin()</a>;
                          otherwise NULL. If no transaction handle is specified, but the
                          operation occurs in a transactional database, the operation will be
                          implicitly transaction protected.
                     </p>
        </div>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="id1634464"></a>Errors</h3>
            </div>
          </div>
        </div>
        <p>
                         The <code class="methodname">Db::get()</code> <span>
            
            <span>
                method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> 
                exception, encapsulating one of the following non-zero errors, or return one
                of the following non-zero errors:
            </span>
        </span>
                    </p>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1634622"></a><span>DbMemoryException or </span>DB_BUFFER_SMALL</h4>
              </div>
            </div>
          </div>
          <p>
                The requested item could not be returned due to undersized buffer.
            </p>
          <p>
                <a class="xref" href="dbmemory.html" title="DbMemoryException">DbMemoryException</a> is thrown if
                your Berkeley DB API is configured to throw exceptions.
                Otherwise, <code class="literal">DB_BUFFER_SMALL</code> is returned.
            </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1634967"></a><span>DbDeadlockException or </span>DB_LOCK_DEADLOCK</h4>
              </div>
            </div>
          </div>
          <p>
                A transactional database environment operation was selected to resolve
                a deadlock.
            </p>
          <p>
                <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if
                your Berkeley DB API is configured to throw exceptions.
                Otherwise, <code class="literal">DB_LOCK_DEADLOCK</code> is returned.
            </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1634914"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4>
              </div>
            </div>
          </div>
          <p>
                A Berkeley DB Concurrent Data Store database environment configured
                for lock timeouts was unable to grant a lock in the allowed time.
            </p>
          <p>
                <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if
                your Berkeley DB API is configured to throw exceptions.
                Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned.
            </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1635138"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4>
              </div>
            </div>
          </div>
          <p>
                The <code class="literal">DB_CONSUME_WAIT</code> flag was specified, lock or transaction timers
                were configured and the lock could not be granted before the wait-time
                expired.
            </p>
          <p>
                <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if
                your Berkeley DB API is configured to throw exceptions.
                Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned.
            </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1635141"></a><span>DbRepHandleDeadException or</span> DB_REP_HANDLE_DEAD</h4>
              </div>
            </div>
          </div>
          <p>
                When a client synchronizes with the master, it is possible for committed
                transactions to be rolled back. This invalidates all  the database and cursor
                handles opened in the replication environment. Once this occurs, an attempt to use
                such a handle will 
                <span>
                    throw a <a class="xref" href="dbrephandledead.html" title="DbRepHandleDeadException">DbRepHandleDeadException</a> (if
                    your application is configured to throw exceptions), or 
                </span>
                return <code class="literal">DB_REP_HANDLE_DEAD</code>.
                The application will need to discard the handle and open a new one in order to
                continue processing.
            </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1635183"></a>DB_REP_LEASE_EXPIRED</h4>
              </div>
            </div>
          </div>
          <p>
                The operation failed because the site's replication master lease has expired.
            </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1635199"></a><span>DbDeadlockException or </span>DB_REP_LOCKOUT</h4>
              </div>
            </div>
          </div>
          <p>
                The operation was blocked by client/master synchronization.
            </p>
          <p>
                <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if
                your Berkeley DB API is configured to throw exceptions.
                Otherwise, <code class="literal">DB_REP_LOCKOUT</code> is returned.
            </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1635287"></a>DB_SECONDARY_BAD</h4>
              </div>
            </div>
          </div>
          <p>
                A secondary index references a nonexistent primary key.
            </p>
        </div>
        <div class="sect3" lang="en" xml:lang="en">
          <div class="titlepage">
            <div>
              <div>
                <h4 class="title"><a id="id1635218"></a>EINVAL</h4>
              </div>
            </div>
          </div>
          <p>
                          If a record number of 0 was specified; the 
                          <a class="link" href="envopen.html#envopen_DB_THREAD">DB_THREAD</a>  flag was
                          specified to the <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a>  method and none of the
                          <a class="link" href="dbt.html#dbt_DB_DBT_MALLOC">DB_DBT_MALLOC</a>,
                          <a class="link" href="dbt.html#dbt_DB_DBT_REALLOC">DB_DBT_REALLOC</a>  or
                          <a class="link" href="dbt.html#dbt_DB_DBT_USERMEM">DB_DBT_USERMEM</a> 
                          flags were set in the <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>; 
                          the <code class="methodname">Db::pget()</code> method was called with a 
                          <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>  handle
                          that does not refer to a secondary index; or if an invalid flag value
                          or parameter was specified.
                    </p>
        </div>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="id1634577"></a>Class</h3>
            </div>
          </div>
        </div>
        <p>
                <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>  
            </p>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <div class="titlepage">
          <div>
            <div>
              <h3 class="title"><a id="id1634467"></a>See Also</h3>
            </div>
          </div>
        </div>
        <p>
                     <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 
                </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="dbfd.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="db.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="dbget_bt_minkey.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Db::fd() </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Db::get_bt_minkey()</td>
        </tr>
      </table>
    </div>
  </body>
</html>