1
<!--$Id: dbc_get.so,v 10.66 2001/07/12 21:13:02 bostic Exp $-->
2
<!--Copyright 1997-2001 by Sleepycat Software, Inc.-->
3
<!--All rights reserved.-->
6
<title>Berkeley DB: Dbc.get</title>
7
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
11
<a name="2"><!--meow--></a>
12
<table width="100%"><tr valign=top>
17
<a href="../api_java/java_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
22
import com.sleepycat.db.*;
24
public int get(Dbt key, Dbt data, int flags)
26
public int pget(Dbt key, Dbt pkey, Dbt data, int flags)
30
<p>The Dbc.get method retrieves key/data pairs from the database. The
31
byte array and length of the key
32
are returned in the object to which <b>key</b> refers (except for the
33
case of the Db.DB_SET flag, in which the <b>key</b> object is
34
unchanged), and the byte array
35
and length of the data are returned in the object to which <b>data</b>
37
<p>When called on a cursor opened on a database that has been made into a
38
secondary index using the <a href="../api_java/db_associate.html">Db.associate</a> method, the Dbc.get
39
and Dbc.pget methods return the key from the secondary index and the
40
data item from the primary database. In addition, the Dbc.pget method
41
returns the key from the primary database. In databases that are not
42
secondary indices, the Dbc.pget interface will always fail and
44
<p>Modifications to the database during a sequential scan will be reflected
45
in the scan; that is, records inserted behind a cursor will not be
46
returned while records inserted in front of a cursor will be returned.
47
<p>In Queue and Recno databases, missing entries (that is, entries that
48
were never explicitly created or that were created and then deleted)
49
will be skipped during a sequential scan.
50
<p>The <b>flags</b> value must be set to one of the following values:
52
<p><dt><a name="Db.DB_CURRENT">Db.DB_CURRENT</a><dd>Return the key/data pair to which the cursor refers.
53
<p>If the cursor key/data pair was deleted, Dbc.get will return
54
<a href="../ref/program/errorret.html#DB_KEYEMPTY">Db.DB_KEYEMPTY</a>.
55
<p>If the cursor is not yet initialized, the Dbc.get method throws an exception that encapsulates EINVAL.
56
<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
57
database, and that pair is returned. In the presence of duplicate key
58
values, the first (last) data item in the set of duplicates is returned.
59
<p>If the database is a Queue or Recno database, Dbc.get using the
60
Db.DB_FIRST (Db.DB_LAST) flags will ignore any keys that exist
61
but were never explicitly created by the application, or were created and
63
<p>If the database is empty, Dbc.get will return <a href="../ref/program/errorret.html#DB_NOTFOUND">Db.DB_NOTFOUND</a>.
64
<p><dt><a name="Db.DB_GET_BOTH">Db.DB_GET_BOTH</a><dd>identical to the Db.DB_SET flag, except that both the key and the data
65
arguments must be matched by the key and data item in the database.
66
<p>When used with the Dbc.pget version of this interface on a secondary
67
index handle, both the secondary and primary keys must be matched by the
68
secondary and primary key item in the database. It is an error to use the
69
Db.DB_GET_BOTH flag with the Dbc.get version of this interface and
70
a cursor that has been opened on a secondary index handle.
71
<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
72
will be returned in <b>data</b>, as described in <a href="../api_java/dbt_class.html">Dbt</a>. The
73
<b>key</b> parameter is ignored.
74
<p>For Db.DB_GET_RECNO to be specified, the underlying database must be
75
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>
77
<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
78
the primary database, but simply return it in the key parameter instead.
79
The data parameter is left unchanged.
80
<p>For Db.DB_JOIN_ITEM to be specified, the underlying cursor must have
81
been returned from the <a href="../api_java/db_join.html">Db.join</a> method.
82
<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)
83
is identical to Db.DB_FIRST (Db.DB_LAST). Otherwise, the cursor
84
is moved to the next (previous) key/data pair of the database, and that
85
pair is returned. In the presence of duplicate key values, the value of
86
the key may not change.
87
<p>If the database is a Queue or Recno database, Dbc.get using the
88
Db.DB_NEXT (Db.DB_PREV) flag will skip any keys that exist
89
but were never explicitly created by the application, or those that were
90
created and later deleted.
91
<p>If the cursor is already on the last (first) record in the database,
92
Dbc.get will return <a href="../ref/program/errorret.html#DB_NOTFOUND">Db.DB_NOTFOUND</a>.
93
<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
94
the current key/data pair, the cursor is moved to the next key/data pair
95
of the database, and that pair is returned. Otherwise, Dbc.get
96
will return <a href="../ref/program/errorret.html#DB_NOTFOUND">Db.DB_NOTFOUND</a>.
97
<p>If the cursor is not yet initialized, the Dbc.get method throws an exception that encapsulates EINVAL.
98
<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
99
(Db.DB_PREV_NODUP) is identical to Db.DB_FIRST
100
(Db.DB_LAST). Otherwise, the cursor is moved to the next (previous)
101
non-duplicate key of the database, and that key/data pair is returned.
102
<p>If the database is a Queue or Recno database, Dbc.get using the
103
Db.DB_NEXT_NODUP (Db.DB_PREV_NODUP) flags will ignore any keys
104
that exist but were never explicitly created by the application, or those
105
that were created and later deleted.
106
<p>If no non-duplicate key/data pairs occur after (before) the cursor
107
position in the database, Dbc.get will return <a href="../ref/program/errorret.html#DB_NOTFOUND">Db.DB_NOTFOUND</a>.
108
<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
109
return the datum associated with the given key.
110
<p>In the presence of duplicate key values, Dbc.get will return the
111
first data item for the given key.
112
<p>If the database is a Queue or Recno database, and the specified key exists,
113
but was never explicitly created by the application or was later deleted,
114
Dbc.get will return <a href="../ref/program/errorret.html#DB_KEYEMPTY">Db.DB_KEYEMPTY</a>.
115
<p>If no matching keys are found, Dbc.get will return
116
<a href="../ref/program/errorret.html#DB_NOTFOUND">Db.DB_NOTFOUND</a>.
117
<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,
118
except that the key is returned as well as the data item; and, in the case
119
of the Btree access method, the returned key/data pair is the smallest
120
key greater than or equal to the specified key (as determined by the
121
comparison method), permitting partial key matches and range
123
<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
124
return the associated key/data pair. The <b>data</b> field of the
126
must be a byte array containing a record number, as described in
127
<a href="../api_java/dbt_class.html">Dbt</a>. This determines the record to be retrieved.
128
<p>For Db.DB_SET_RECNO to be specified, the underlying database must be
129
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>
132
<p>In addition, the following flags may be set by
133
bitwise inclusively <b>OR</b>'ing them into the <b>flags</b> parameter:
135
<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
136
<a href="../api_java/db_open.html#DB_DIRTY_READ">Db.DB_DIRTY_READ</a> flag was not specified when the underlying
138
<p><dt><a name="Db.DB_MULTIPLE">Db.DB_MULTIPLE</a><dd>Return multiple data items. The buffer to which the <b>data</b>
139
argument refers is filled with the specified key's data items. If the
140
first data item associated with the key cannot fit into the buffer, the
141
size field of the <b>data</b> argument is set to the length needed to
142
retrieve it, and a <a href="../api_java/mem_class.html">DbMemoryException</a> is thrown. Subsequent calls with both the
143
Db.DB_NEXT_DUP and Db.DB_MULTIPLE flags specified will return
144
additional data items associated with the current key or
145
<a href="../ref/program/errorret.html#DB_NOTFOUND">Db.DB_NOTFOUND</a> if there is no additional data items to return.
146
<p>If Db.DB_MULTIPLE is specified for the Queue and Recno access
147
methods, the buffer will be filled with as many data records as
148
possible. The record number of the first record will be returned in
149
the <b>key</b> argument. The record number of each subsequent returned
150
record must be calculated from this value.
151
<p>The buffer to which the <b>data</b> argument refers should be large
152
relative to the page size of the underlying database, aligned for
153
unsigned integer access, and be a multiple of 1024 bytes in size.
154
<p>The Db.DB_MULTIPLE flag may only be used with the
155
Db.DB_CURRENT, Db.DB_FIRST, Db.DB_GET_BOTH,
156
Db.DB_NEXT, Db.DB_NEXT_DUP, Db.DB_NEXT_NODUP,
157
Db.DB_SET, Db.DB_SET_RANGE, and Db.DB_SET_RECNO
159
<p>The Db.DB_MULTIPLE flag may not be used when accessing databases
160
made into secondary indices using the <a href="../api_java/db_associate.html">Db.associate</a> method.
161
<p>See <a href="../api_java/dbt_bulk_class.html">DbMultipleDataIterator</a> for more information.
162
<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
163
<b>data</b> argument refers is filled with key and data pairs. If the
164
first key and data pair cannot fit into the buffer, the size field of
165
the <b>data</b> argument is set to the length needed to retrieve them,
166
and a <a href="../api_java/mem_class.html">DbMemoryException</a> is thrown.
167
<p>The buffer to which the <b>data</b> argument refers should be large
168
relative to the page size of the underlying database, aligned for
169
unsigned integer access, and be a multiple of 1024 bytes in size.
170
<p>The Db.DB_MULTIPLE_KEY flag may only be used with the
171
Db.DB_CURRENT, Db.DB_FIRST, Db.DB_GET_BOTH,
172
Db.DB_NEXT, Db.DB_NEXT_NODUP, Db.DB_SET,
173
Db.DB_SET_RANGE, and Db.DB_SET_RECNO options. The
174
Db.DB_MULTIPLE_KEY flag may not be used when accessing databases
175
made into secondary indices using the <a href="../api_java/db_associate.html">Db.associate</a> method.
176
<p>See <a href="../api_java/dbt_bulk_class.html">DbMultipleKeyDataIterator</a> for more information.
177
<p><dt><a name="Db.DB_RMW">Db.DB_RMW</a><dd>Acquire write locks instead of read locks when doing the retrieval.
178
Setting this flag can eliminate deadlock during a read-modify-write
179
cycle by acquiring the write lock during the read part of the cycle so
180
that another thread of control acquiring a read lock for the same item,
181
in its own read-modify-write cycle, will not result in deadlock.
183
<p>Otherwise, the Dbc.get method throws an exception that encapsulates a non-zero error value on
185
<p>If Dbc.get fails for any reason, the state of the cursor will be
188
<p>The Dbc.get method may fail and throw an exception encapsulating a non-zero error for the following conditions:
190
<p><dt>Db.DB_SECONDARY_BAD<dd>A secondary index references a nonexistent primary key.
193
<p><dt>EINVAL<dd>An invalid flag value or parameter was specified.
194
<p>The specified cursor was not currently initialized.
195
<p>The Dbc.pget interface was called with a cursor that does not
196
refer to a secondary index.
198
<p>If the operation was selected to resolve a deadlock, the
199
Dbc.get method will fail and
200
throw a <a href="../api_java/deadlock_class.html">DbDeadlockException</a> exception.
201
<p>If the requested item could not be returned due to insufficient memory,
202
the Dbc.get method will fail and
203
throw a <a href="../api_java/mem_class.html">DbMemoryException</a> exception.
204
<p>The Dbc.get method may fail and throw an exception for errors specified for other Berkeley DB and C library or system methods.
205
If a catastrophic error has occurred, the Dbc.get method may fail and throw
206
a <a href="../api_java/runrec_class.html">DbRunRecoveryException</a>, in which case all subsequent Berkeley DB calls
207
will fail in the same way.
209
<a href="../api_java/dbc_class.html">Dbc</a>
211
<a href="../api_java/dbc_close.html">Dbc.close</a>,
212
<a href="../api_java/dbc_count.html">Dbc.count</a>,
213
<a href="../api_java/dbc_del.html">Dbc.del</a>,
214
<a href="../api_java/dbc_dup.html">Dbc.dup</a>,
215
<a href="../api_java/dbc_get.html">Dbc.get</a>,
216
<a href="../api_java/dbc_get.html">Dbc.pget</a>,
218
<a href="../api_java/dbc_put.html">Dbc.put</a>.
220
<table width="100%"><tr><td><br></td><td align=right>
221
<a href="../api_java/java_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
223
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>