Debian Codegraph @

docs/programmer_reference/am_misc_partial.html

raw symbols SCIP
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>Partial record storage and retrieval</title>
7 <link rel="stylesheet" href="gettingStarted.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 Programmer's Reference Guide" />
10 <link rel="up" href="am_misc.html" title="Chapter 4.  Access Method Wrapup" />
11 <link rel="prev" href="am_misc_bulk.html" title="Retrieving and updating records in bulk" />
12 <link rel="next" href="am_misc_struct.html" title="Storing C/C++ structures/objects" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Partial record storage and retrieval</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="am_misc_bulk.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 4. 
26 Access Method Wrapup
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="am_misc_struct.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="am_misc_partial"></a>Partial record storage and retrieval</h2>
38 </div>
39 </div>
40 </div>
41 <p>It is possible to both store and retrieve parts of data items in all
42 Berkeley DB access methods. This is done by setting the
43 <a href="../api_reference/C/dbt.html#dbt_DB_DBT_PARTIAL" class="olink">DB_DBT_PARTIAL</a> flag <a href="../api_reference/C/dbt.html" class="olink">DBT</a> structure passed to the
44 Berkeley DB method.</p>
45 <p>The <a href="../api_reference/C/dbt.html#dbt_DB_DBT_PARTIAL" class="olink">DB_DBT_PARTIAL</a> flag is based on the values of two fields
46 of the <a href="../api_reference/C/dbt.html" class="olink">DBT</a> structure: <span class="bold"><strong>dlen</strong></span> and <span class="bold"><strong>doff</strong></span>. The value
47 of <span class="bold"><strong>dlen</strong></span> is the number of bytes of the record in which the
48 application is interested. The value of <span class="bold"><strong>doff</strong></span> is the offset from
49 the beginning of the data item where those bytes start.</p>
50 <p>For example, if the data item were <span class="bold"><strong>ABCDEFGHIJKL</strong></span>, a <span class="bold"><strong>doff</strong></span>
51 value of 3 would indicate that the bytes of interest started at
52 <span class="bold"><strong>D</strong></span>, and a <span class="bold"><strong>dlen</strong></span> value of 4 would indicate that the bytes
53 of interest were <span class="bold"><strong>DEFG</strong></span>.</p>
54 <p>When retrieving a data item from a database, the <span class="bold"><strong>dlen</strong></span> bytes
55 starting <span class="bold"><strong>doff</strong></span> bytes from the beginning of the record are
56 returned, as if they comprised the entire record. If any or all of the
57 specified bytes do not exist in the record, the retrieval is still
58 successful and any existing bytes are returned.</p>
59 <p>When storing a data item into the database, the <span class="bold"><strong>dlen</strong></span> bytes
60 starting <span class="bold"><strong>doff</strong></span> bytes from the beginning of the specified key's
61 data record are replaced by the data specified by the <span class="bold"><strong>data</strong></span> and
62 <span class="bold"><strong>size</strong></span> fields. If <span class="bold"><strong>dlen</strong></span> is smaller than <span class="bold"><strong>size</strong></span>, the
63 record will grow, and if <span class="bold"><strong>dlen</strong></span> is larger than <span class="bold"><strong>size</strong></span>, the
64 record will shrink. If the specified bytes do not exist, the record will
65 be extended using nul bytes as necessary, and the store call will still
66 succeed.</p>
67 <p>The following are various examples of the put case for the
68 <a href="../api_reference/C/dbt.html#dbt_DB_DBT_PARTIAL" class="olink">DB_DBT_PARTIAL</a> flag. In all examples, the initial data item is 20
69 bytes in length:</p>
70 <p>
71 <span class="bold">
72 <strong>ABCDEFGHIJ0123456789</strong>
73 </span>
74 </p>
75 <div class="orderedlist">
76 <ol type="1">
77 <li>
78 <pre class="programlisting">size = 20
79 doff = 0
80 dlen = 20
81 data = abcdefghijabcdefghij
82
83 Result: The 20 bytes at offset 0 are replaced by the 20 bytes of
84 data; that is, the entire record is replaced.
85
86 ABCDEFGHIJ0123456789 -&gt; abcdefghijabcdefghij </pre>
87 </li>
88 <li>
89 <pre class="programlisting">size = 10
90 doff = 20
91 dlen = 0
92 data = abcdefghij
93
94 Result: The 0 bytes at offset 20 are replaced by the 10 bytes of
95 data; that is, the record is extended by 10 bytes.
96
97 ABCDEFGHIJ0123456789 -&gt; ABCDEFGHIJ0123456789abcdefghij </pre>
98 </li>
99 <li>
100 <pre class="programlisting">size = 10
101 doff = 10
102 dlen = 5
103 data = abcdefghij
104
105 Result: The 5 bytes at offset 10 are replaced by the 10 bytes of
106 data.
107
108 ABCDEFGHIJ0123456789 -&gt; ABCDEFGHIJabcdefghij56789 </pre>
109 </li>
110 <li>
111 <pre class="programlisting">size = 10
112 doff = 10
113 dlen = 0
114 data = abcdefghij
115
116 Result: The 0 bytes at offset 10 are replaced by the 10 bytes of
117 data; that is, 10 bytes are inserted into the record.
118
119 ABCDEFGHIJ0123456789 -&gt; ABCDEFGHIJabcdefghij0123456789 </pre>
120 </li>
121 <li>
122 <pre class="programlisting">size = 10
123 doff = 2
124 dlen = 15
125 data = abcdefghij
126
127 Result: The 15 bytes at offset 2 are replaced by the 10 bytes of
128 data.
129
130 ABCDEFGHIJ0123456789 -&gt; ABabcdefghij789 </pre>
131 </li>
132 <li>
133 <pre class="programlisting">size = 10
134 doff = 0
135 dlen = 0
136 data = abcdefghij
137
138 Result: The 0 bytes at offset 0 are replaced by the 10 bytes of
139 data; that is, the 10 bytes are inserted at the beginning of the
140 record.
141
142 ABCDEFGHIJ0123456789 -&gt; abcdefghijABCDEFGHIJ0123456789 </pre>
143 </li>
144 <li>
145 <pre class="programlisting">size = 0
146 doff = 0
147 dlen = 10
148 data = ""
149
150 Result: The 10 bytes at offset 0 are replaced by the 0 bytes of
151 data; that is, the first 10 bytes of the record are discarded.
152
153 ABCDEFGHIJ0123456789 -&gt; 0123456789 </pre>
154 </li>
155 <li>
156 <pre class="programlisting">size = 10
157 doff = 25
158 dlen = 0
159 data = abcdefghij
160
161 Result: The 0 bytes at offset 25 are replaced by the 10 bytes of
162 data; that is, 10 bytes are inserted into the record past the end
163 of the current data (\0 represents a nul byte).
164
165 ABCDEFGHIJ0123456789 -&gt; ABCDEFGHIJ0123456789\0\0\0\0\0abcdefghij </pre>
166 </li>
167 </ol>
168 </div>
169 </div>
170 <div class="navfooter">
171 <hr />
172 <table width="100%" summary="Navigation footer">
173 <tr>
174 <td width="40%" align="left"><a accesskey="p" href="am_misc_bulk.html">Prev</a> </td>
175 <td width="20%" align="center">
176 <a accesskey="u" href="am_misc.html">Up</a>
177 </td>
178 <td width="40%" align="right"> <a accesskey="n" href="am_misc_struct.html">Next</a></td>
179 </tr>
180 <tr>
181 <td width="40%" align="left" valign="top">Retrieving and updating records in bulk </td>
182 <td width="20%" align="center">
183 <a accesskey="h" href="index.html">Home</a>
184 </td>
185 <td width="40%" align="right" valign="top"> Storing C/C++ structures/objects</td>
186 </tr>
187 </table>
188 </div>
189 </body>
190 </html>