dbc_get.html   [plain text]


<!--$Id: dbc_get.html,v 1.1.1.1 2003/02/15 04:55:51 zarzycki Exp $-->
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
<!--All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB: Dbc.get</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
</head>
<body bgcolor=white>
<a name="2"><!--meow--></a>
<table width="100%"><tr valign=top>
<td>
<h1>Dbc.get</h1>
</td>
<td align=right>
<a href="../api_java/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
</td></tr></table>
<hr size=1 noshade>
<tt>
<h3><pre>
import com.sleepycat.db.*;
<p>
public int get(Dbt key, Dbt data, int flags)
    throws DbException;
public int pget(Dbt key, Dbt pkey, Dbt data, int flags)
    throws DbException;
</pre></h3>
<h1>Description</h1>
<p>The Dbc.get method retrieves key/data pairs from the database.  The
byte array and length of the key
are returned in the object to which <b>key</b> refers (except for the
case of the Db.DB_SET flag, in which the <b>key</b> object is
unchanged), and the byte array
and length of the data are returned in the object to which <b>data</b>
refers.
<p>When called on a cursor opened on a database that has been made into a
secondary index using the <a href="../api_java/db_associate.html">Db.associate</a> method, the Dbc.get
and Dbc.pget methods return the key from the secondary index and the
data item from the primary database. In addition, the Dbc.pget method
returns the key from the primary database.  In databases that are not
secondary indices, the Dbc.pget interface will always fail and
return EINVAL.
<p>Modifications to the database during a sequential scan will be reflected
in the scan; that is, records inserted behind a cursor will not be
returned while records inserted in front of a cursor will be returned.
<p>In Queue and Recno databases, missing entries (that is, entries that
were never explicitly created or that were created and then deleted)
will be skipped during a sequential scan.
<p>The <b>flags</b> value must be set to one of the following values:
<p><dl compact>
<p><dt><a name="Db.DB_CURRENT">Db.DB_CURRENT</a><dd>Return the key/data pair to which the cursor refers.
<p>
If the cursor key/data pair was deleted, the Dbc.get method will return Db.DB_KEYEMPTY.
If the cursor is not yet initialized, the Dbc.get method throws an exception that encapsulates Db.EINVAL.
<p><dt><a name="Db.DB_FIRST">Db.DB_FIRST</a>, <a name="Db.DB_LAST">Db.DB_LAST</a><dd>The cursor is set to refer to the first (last) key/data pair of the
database, and that pair is returned.  In the presence of duplicate key
values, the first (last) data item in the set of duplicates is returned.
<p>If the database is a Queue or Recno database, Dbc.get using the
Db.DB_FIRST (Db.DB_LAST) flags will ignore any keys that exist
but were never explicitly created by the application, or were created and
later deleted.
<p>
If the database is empty, the Dbc.get method will return Db.DB_NOTFOUND.
<p><dt><a name="Db.DB_GET_BOTH">Db.DB_GET_BOTH</a><dd>The Db.DB_GET_BOTH flag is identical to the Db.DB_SET flag,
except that both the key and the data arguments must be matched by the
key and data item in the database.
<p>When used with the Dbc.pget version of this interface on a
secondary index handle, both the secondary and primary keys must be
matched by the secondary and primary key item in the database.  It is
an error to use the Db.DB_GET_BOTH flag with the Dbc.get
version of this interface and a cursor that has been opened on a
secondary index handle.
<p><dt><a name="Db.DB_GET_BOTH_RANGE">Db.DB_GET_BOTH_RANGE</a><dd>The Db.DB_GET_BOTH_RANGE flag is identical to the Db.DB_GET_BOTH
flag, except that, in the case of any database supporting sorted
duplicate sets, the returned key/data pair is the smallest data item
greater than or equal to the specified data item (as determined by the
comparison function), permitting partial matches and range searches in
duplicate data sets.
<p><dt><a name="Db.DB_GET_RECNO">Db.DB_GET_RECNO</a><dd>Return the record number associated with the cursor.  The record number
will be returned in <b>data</b>, as described in <a href="../api_java/dbt_class.html">Dbt</a>.  The
<b>key</b> parameter is ignored.
<p>For Db.DB_GET_RECNO to be specified, the underlying database must be
of type Btree, and it must have been created with the <a href="../api_java/db_set_flags.html#DB_RECNUM">Db.DB_RECNUM</a>
flag.
<p><dt><a name="Db.DB_JOIN_ITEM">Db.DB_JOIN_ITEM</a><dd>Do not use the data value found in all of the cursors as a lookup key for
the primary database, but simply return it in the key parameter instead.
The data parameter is left unchanged.
<p>For Db.DB_JOIN_ITEM to be specified, the underlying cursor must have
been returned from the <a href="../api_java/db_join.html">Db.join</a> method.
<p><dt><a name="Db.DB_NEXT">Db.DB_NEXT</a>, <a name="Db.DB_PREV">Db.DB_PREV</a><dd>If the cursor is not yet initialized, Db.DB_NEXT (Db.DB_PREV)
is identical to Db.DB_FIRST (Db.DB_LAST).  Otherwise, the cursor
is moved to the next (previous) key/data pair of the database, and that
pair is returned.  In the presence of duplicate key values, the value of
the key may not change.
<p>If the database is a Queue or Recno database, Dbc.get using the
Db.DB_NEXT (Db.DB_PREV) flag will skip any keys that exist
but were never explicitly created by the application, or those that were
created and later deleted.
<p>
If the cursor is already on the last (first) record in the database, the Dbc.get method will return Db.DB_NOTFOUND.
<p><dt><a name="Db.DB_NEXT_DUP">Db.DB_NEXT_DUP</a><dd>If the next key/data pair of the database is a duplicate data record for
the current key/data pair, the cursor is moved to the next key/data pair
of the database, and that pair is returned.
If the next key/data pair of the database is not a duplicate data record
for the current key/data pair, the Dbc.get method will return Db.DB_NOTFOUND.
If the cursor is not yet initialized, the Dbc.get method throws an exception that encapsulates Db.EINVAL.
<p><dt><a name="Db.DB_NEXT_NODUP">Db.DB_NEXT_NODUP</a>, <a name="Db.DB_PREV_NODUP">Db.DB_PREV_NODUP</a><dd>If the cursor is not yet initialized, Db.DB_NEXT_NODUP
(Db.DB_PREV_NODUP) is identical to Db.DB_FIRST
(Db.DB_LAST).  Otherwise, the cursor is moved to the next (previous)
non-duplicate key of the database, and that key/data pair is returned.
<p>If the database is a Queue or Recno database, Dbc.get using the
Db.DB_NEXT_NODUP (Db.DB_PREV_NODUP) flags will ignore any keys
that exist but were never explicitly created by the application, or those
that were created and later deleted.
<p>
If no non-duplicate key/data pairs occur after (before) the cursor
position in the database, the Dbc.get method will return Db.DB_NOTFOUND.
<p><dt><a name="Db.DB_SET">Db.DB_SET</a><dd>Move the cursor to the specified key/data pair of the database, and
return the datum associated with the given key.
<p>In the presence of duplicate key values, Dbc.get will return the
first data item for the given key.
If no matching keys are found, the Dbc.get method will return Db.DB_NOTFOUND.
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, the Dbc.get method will return Db.DB_KEYEMPTY.
<p><dt><a name="Db.DB_SET_RANGE">Db.DB_SET_RANGE</a><dd>The Db.DB_SET_RANGE flag is identical to the Db.DB_SET flag,
except that in the case of the Btree access method, the key is returned
as well as the data item and the returned key/data pair is the smallest
key greater than or equal to the specified key (as determined by the
comparison method), permitting partial key matches and range
searches.
<p><dt><a name="Db.DB_SET_RECNO">Db.DB_SET_RECNO</a><dd>Move the cursor to the specific numbered record of the database, and
return the associated key/data pair.  The <b>data</b> field of the
specified <b>key</b>
must be a byte array containing a record number, as described in
<a href="../api_java/dbt_class.html">Dbt</a>.  This determines the record to be retrieved.
<p>For Db.DB_SET_RECNO to be specified, the underlying database must be
of type Btree, and it must have been created with the <a href="../api_java/db_set_flags.html#DB_RECNUM">Db.DB_RECNUM</a>
flag.
</dl>
<p>In addition, the following flags may be set by
bitwise inclusively <b>OR</b>'ing them into the <b>flags</b> parameter:
<p><dl compact>
<p><dt><a name="Db.DB_DIRTY_READ">Db.DB_DIRTY_READ</a><dd>Read modified but not yet committed data.  Silently ignored if the
<a href="../api_java/db_open.html#DB_DIRTY_READ">Db.DB_DIRTY_READ</a> flag was not specified when the underlying
database was opened.
<p><dt><a name="Db.DB_MULTIPLE">Db.DB_MULTIPLE</a><dd>Return multiple data items.  The buffer to which the <b>data</b>
argument refers is filled with the specified key's data items.  If the
first data item associated with the key cannot fit into the buffer, the
size field of the <b>data</b> argument is set to the length needed to
retrieve it, and a <a href="../api_java/memp_class.html">DbMemoryException</a> is thrown.  Subsequent calls with both the
Db.DB_NEXT_DUP and Db.DB_MULTIPLE flags specified will return
additional data items associated with the current key or
<a href="../ref/program/errorret.html#DB_NOTFOUND">Db.DB_NOTFOUND</a> if there is no additional data items to return.
<p>If Db.DB_MULTIPLE is specified for the Queue and Recno access
methods, the buffer will be filled with as many data records as
possible.  The record number of the first record will be returned in
the <b>key</b> argument.  The record number of each subsequent returned
record must be calculated from this value.
<p>The buffer to which the <b>data</b> argument refers should be large
relative to the page size of the underlying database, aligned for
unsigned integer access, and be a multiple of 1024 bytes in size.
<p>The Db.DB_MULTIPLE flag may only be used with the
Db.DB_CURRENT, Db.DB_FIRST, Db.DB_GET_BOTH,
Db.DB_NEXT, Db.DB_NEXT_DUP, Db.DB_NEXT_NODUP,
Db.DB_SET, Db.DB_SET_RANGE, and Db.DB_SET_RECNO
options.
<p>The Db.DB_MULTIPLE flag may not be used when accessing databases
made into secondary indices using the <a href="../api_java/db_associate.html">Db.associate</a> method.
<p>See <a href="../api_java/dbt_bulk_class.html">DbMultipleDataIterator</a> for more information.
<p><dt><a name="Db.DB_MULTIPLE_KEY">Db.DB_MULTIPLE_KEY</a><dd>Return multiple key and data pairs.  The buffer to which the
<b>data</b> argument refers is filled with key and data pairs.  If the
first key and data pair cannot fit into the buffer, the size field of
the <b>data</b> argument is set to the length needed to retrieve them,
and a <a href="../api_java/memp_class.html">DbMemoryException</a> is thrown.
<p>The buffer to which the <b>data</b> argument refers should be large
relative to the page size of the underlying database, aligned for
unsigned integer access, and be a multiple of 1024 bytes in size.
<p>The Db.DB_MULTIPLE_KEY flag may only be used with the
Db.DB_CURRENT, Db.DB_FIRST, Db.DB_GET_BOTH,
Db.DB_NEXT, Db.DB_NEXT_NODUP, Db.DB_SET,
Db.DB_SET_RANGE, and Db.DB_SET_RECNO options.  The
Db.DB_MULTIPLE_KEY flag may not be used when accessing databases
made into secondary indices using the <a href="../api_java/db_associate.html">Db.associate</a> method.
<p>See <a href="../api_java/dbt_bulk_class.html">DbMultipleKeyDataIterator</a> for more information.
<p><dt><a name="Db.DB_RMW">Db.DB_RMW</a><dd>Acquire write locks instead of read locks when doing the retrieval.
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.
</dl>
<p>
Otherwise, the Dbc.get method throws an exception that encapsulates a non-zero error value on
failure.
<p>If Dbc.get fails for any reason, the state of the cursor will be
unchanged.
<h1>Errors</h1>
<p>The Dbc.get method may fail and throw an exception encapsulating a non-zero error for the following conditions:
<p><dl compact>
<p><dt>Db.DB_SECONDARY_BAD<dd>A secondary index references a nonexistent primary key.
</dl>
<p><dl compact>
<p><dt>EINVAL<dd>An invalid flag value or parameter was specified.
<p>The specified cursor was not currently initialized.
<p>The Dbc.pget interface was called with a cursor that does not
refer to a secondary index.
</dl>
<p>If the operation was selected to resolve a deadlock, the
Dbc.get method will fail and
throw a <a href="../api_java/deadlock_class.html">DbDeadlockException</a> exception.
<p>If the requested item could not be returned due to insufficient memory,
the Dbc.get method will fail and
throw a <a href="../api_java/memp_class.html">DbMemoryException</a> exception.
<p>The Dbc.get method may fail and throw an exception for errors specified for other Berkeley DB and C library or system methods.
If a catastrophic error has occurred, the Dbc.get method may fail and
throw a <a href="../api_java/runrec_class.html">DbRunRecoveryException</a>,
in which case all subsequent Berkeley DB calls will fail in the same way.
<h1>Class</h1>
<a href="../api_java/dbc_class.html">Dbc</a>
<h1>See Also</h1>
<a href="../api_java/dbc_list.html">Database Cursors and Related Methods</a>
</tt>
<table width="100%"><tr><td><br></td><td align=right>
<a href="../api_java/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
</td></tr></table>
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>
</body>
</html>