2
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
3
<!--All rights reserved.-->
4
<!--See the file LICENSE for redistribution information.-->
7
<title>Berkeley DB Reference Guide: Partial record storage and retrieval</title>
8
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
9
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
12
<a name="2"><!--meow--></a>
13
<table width="100%"><tr valign=top>
14
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Access Methods</dl></h3></td>
15
<td align=right><a href="../../ref/am_misc/get_bulk.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/am_misc/struct.html"><img src="../../images/next.gif" alt="Next"></a>
18
<h1 align=center>Partial record storage and retrieval</h1>
19
<p>It is possible to both store and retrieve parts of data items in all
20
Berkeley DB access methods. This is done by setting the
21
<a href="../../api_c/dbt_class.html#DB_DBT_PARTIAL">DB_DBT_PARTIAL</a> flag in the <a href="../../api_c/dbt_class.html">DBT</a> structure passed to the
22
Berkeley DB interface.
23
<p>The <a href="../../api_c/dbt_class.html#DB_DBT_PARTIAL">DB_DBT_PARTIAL</a> flag is based on the values of two fields
24
of the <a href="../../api_c/dbt_class.html">DBT</a> structure: <b>dlen</b> and <b>doff</b>. The value
25
of <b>dlen</b> is the number of bytes of the record in which the
26
application is interested. The value of <b>doff</b> is the offset from
27
the beginning of the data item where those bytes start.
28
<p>For example, if the data item were <b>ABCDEFGHIJKL</b>, a <b>doff</b>
29
value of 3 would indicate that the bytes of interest started at
30
<b>D</b>, and a <b>dlen</b> value of 4 would indicate that the bytes
31
of interest were <b>DEFG</b>.
32
<p>When retrieving a data item from a database, the <b>dlen</b> bytes
33
starting <b>doff</b> bytes from the beginning of the record are
34
returned, as if they comprised the entire record. If any or all of the
35
specified bytes do not exist in the record, the retrieval is still
36
successful and any existing bytes are returned.
37
<p>When storing a data item into the database, the <b>dlen</b> bytes
38
starting <b>doff</b> bytes from the beginning of the specified key's
39
data record are replaced by the data specified by the <b>data</b> and
40
<b>size</b> fields. If <b>dlen</b> is smaller than <b>size</b>, the
41
record will grow, and if <b>dlen</b> is larger than <b>size</b>, the
42
record will shrink. If the specified bytes do not exist, the record will
43
be extended using nul bytes as necessary, and the store call will still
45
<p>The following are various examples of the put case for the
46
<a href="../../api_c/dbt_class.html#DB_DBT_PARTIAL">DB_DBT_PARTIAL</a> flag. In all examples, the initial data item is 20
48
<p><b>ABCDEFGHIJ0123456789</b>
50
<p><li><p><blockquote><pre>size = 20
53
data = abcdefghijabcdefghij
55
Result: The 20 bytes at offset 0 are replaced by the 20 bytes of data;
56
that is, the entire record is replaced.
58
ABCDEFGHIJ0123456789 -> abcdefghijabcdefghij
60
<p><li><p><blockquote><pre>size = 10
65
Result: The 0 bytes at offset 20 are replaced by the 10 bytes of data;
66
that is, the record is extended by 10 bytes.
68
ABCDEFGHIJ0123456789 -> ABCDEFGHIJ0123456789abcdefghij
70
<p><li><p><blockquote><pre>size = 10
75
Result: The 5 bytes at offset 10 are replaced by the 10 bytes of data.
77
ABCDEFGHIJ0123456789 -> ABCDEFGHIJabcdefghij56789
79
<p><li><p><blockquote><pre>size = 10
84
Result: The 0 bytes at offset 10 are replaced by the 10 bytes of data;
85
that is, 10 bytes are inserted into the record.
87
ABCDEFGHIJ0123456789 -> ABCDEFGHIJabcdefghij0123456789
89
<p><li><p><blockquote><pre>size = 10
94
Result: The 15 bytes at offset 2 are replaced by the 10 bytes of data.
96
ABCDEFGHIJ0123456789 -> ABabcdefghij789
98
<p><li><p><blockquote><pre>size = 10
103
Result: The 0 bytes at offset 0 are replaced by the 10 bytes of data;
104
that is, the 10 bytes are inserted at the beginning of the record.
106
ABCDEFGHIJ0123456789 -> abcdefghijABCDEFGHIJ0123456789
108
<p><li><p><blockquote><pre>size = 0
113
Result: The 10 bytes at offset 0 are replaced by the 0 bytes of data;
114
that is, the first 10 bytes of the record are discarded.
116
ABCDEFGHIJ0123456789 -> 0123456789
118
<p><li><p><blockquote><pre>size = 10
123
Result: The 0 bytes at offset 25 are replaced by the 10 bytes of data;
124
that is, 10 bytes are inserted into the record past the end of the
125
current data (\0 represents a nul byte).
127
ABCDEFGHIJ0123456789 -> ABCDEFGHIJ0123456789\0\0\0\0\0abcdefghij
130
<table width="100%"><tr><td><br></td><td align=right><a href="../../ref/am_misc/get_bulk.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/am_misc/struct.html"><img src="../../images/next.gif" alt="Next"></a>
132
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>