• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src/router/db-4.8.30/docs/api_reference/CXX/
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>Db::join()</title>
7    <link rel="stylesheet" href="apiReference.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 C++ API Reference" />
10    <link rel="up" href="db.html" title="Chapter 2.  The Db Handle" />
11    <link rel="prev" href="dbget_type.html" title="Db::get_type()" />
12    <link rel="next" href="dbkey_range.html" title="Db::key_range()" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Db::join()</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="dbget_type.html">Prev</a> </td>
22          <th width="60%" align="center">Chapter 2. 
23                The Db Handle
24        </th>
25          <td width="20%" align="right"> <a accesskey="n" href="dbkey_range.html">Next</a></td>
26        </tr>
27      </table>
28      <hr />
29    </div>
30    <div class="sect1" lang="en" xml:lang="en">
31      <div class="titlepage">
32        <div>
33          <div>
34            <h2 class="title" style="clear: both"><a id="dbjoin"></a>Db::join()</h2>
35          </div>
36        </div>
37      </div>
38      <pre class="programlisting">#include &lt;db_cxx.h&gt;
39 
40int
41Db::join(Dbc **curslist, Dbc **dbcp, u_int32_t flags);</pre>
42      <p>
43         The <code class="methodname">Db::join()</code> method creates a specialized join cursor for use in
44         performing equality or natural joins on secondary indices.  For
45         information on how to organize your data to use this functionality,
46         see <a href="../../programmer_reference/am_cursor.html#am_join" class="olink">Equality join</a>.
47    </p>
48      <p>
49             The <code class="methodname">Db::join()</code> method is called using the 
50             <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>  handle of the primary
51             database.
52    </p>
53      <p>
54         The join cursor supports only the <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a>  and 
55         <a class="xref" href="dbcclose.html" title="Dbc::close()">Dbc::close()</a> cursor functions:
56    </p>
57      <div class="itemizedlist">
58        <ul type="disc">
59          <li>
60            <p>
61                        <span class="bold"><strong> <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a> </strong></span>
62                </p>
63            <p>
64                         Iterates over the values associated with the keys to which each item
65                         in <span class="bold"><strong>curslist</strong></span> was initialized.  Any
66                         data value that appears in all items specified by the <span class="bold"><strong>curslist</strong></span> parameter is then used as a key into
67                         the <span class="bold"><strong>primary</strong></span>, and the key/data pair
68                         found in the <span class="bold"><strong>primary</strong></span> is returned. The
69                         <span class="bold"><strong>flags</strong></span> parameter must be set to 0 or
70                         the following value:  
71                         
72                 </p>
73            <div class="itemizedlist">
74              <ul type="circle">
75                <li>
76                  <p>
77                                         <span class="bold"><strong><code class="literal">DB_JOIN_ITEM</code></strong></span>
78                                 </p>
79                  <p>
80                                         Do not use the data value found in all the cursors as a lookup key for
81                                         the <span class="bold"><strong>primary</strong></span>, but simply return it in
82                                         the key parameter instead. The data parameter is left unchanged.
83                                 </p>
84                </li>
85              </ul>
86            </div>
87            <p>
88                         In addition, the following flag may be set by bitwise inclusively
89                         <span class="bold"><strong>OR</strong></span>'ing it into the <span class="bold"><strong>flags</strong></span> parameter:  
90                 </p>
91            <div class="itemizedlist">
92              <ul type="circle">
93                <li>
94                  <p>
95                                         <span class="bold"><strong> <code class="literal">DB_READ_UNCOMMITTED</code></strong></span>
96                                </p>
97                  <p>
98                                         Configure a transactional join operation to have degree 1 isolation,
99                                         reading modified but not yet committed data.  Silently ignored if the
100                                         <a class="link" href="dbopen.html#dbopen_DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a> 
101                                         flag was not specified when the underlying database was opened.
102                                </p>
103                </li>
104                <li>
105                  <p>
106                                         <span class="bold"><strong><code class="literal">DB_RMW</code></strong></span>
107                                </p>
108                  <p>
109                                         Acquire write locks instead of read locks when doing the read, if
110                                         locking is configured.  Setting this flag can eliminate deadlock
111                                         during a read-modify-write cycle by acquiring the write lock during
112                                         the read part of the cycle so that another thread of control acquiring
113                                         a read lock for the same item, in its own read-modify-write cycle,
114                                         will not result in deadlock.
115                                 </p>
116                </li>
117              </ul>
118            </div>
119          </li>
120          <li>
121            <p>
122                        <span class="bold"><strong> <a class="xref" href="dbcclose.html" title="Dbc::close()">Dbc::close()</a> </strong></span>
123                     </p>
124            <p>
125                          Close the returned cursor and release all resources.  (Closing the
126                          cursors in <span class="bold"><strong>curslist</strong></span> is the
127                          responsibility of the caller.)
128                      </p>
129          </li>
130        </ul>
131      </div>
132      <p>
133          The <code class="methodname">Db::join()</code> <span>
134            
135            <span>
136                method either returns a non-zero error value or throws an
137                exception that encapsulates a non-zero error value on
138                failure, and returns 0 on success.
139            </span>
140        </span>
141      </p>
142      <div class="sect2" lang="en" xml:lang="en">
143        <div class="titlepage">
144          <div>
145            <div>
146              <h3 class="title"><a id="id1639144"></a>Parameters</h3>
147            </div>
148          </div>
149        </div>
150        <div class="sect3" lang="en" xml:lang="en">
151          <div class="titlepage">
152            <div>
153              <div>
154                <h4 class="title"><a id="id1638877"></a>curslist</h4>
155              </div>
156            </div>
157          </div>
158          <p>
159                          The <span class="bold"><strong>curslist</strong></span> parameter contains a
160                          NULL terminated array of cursors. Each cursor must have been
161                          initialized to refer to the key on which the underlying database
162                          should be joined.  Typically, this initialization is done by a 
163                          <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a>  call with the
164                          <a class="link" href="dbcget.html#dbcget_DB_SET">DB_SET</a>  flag
165                          specified.  Once the cursors have been passed as part of a <span class="bold"><strong>curslist</strong></span>, they should not be accessed or
166                          modified until the newly created join cursor has been closed, or else
167                          inconsistent results may be returned.
168                     </p>
169          <p>
170                          Joined values are retrieved by doing a sequential iteration over the
171                          first cursor in the <span class="bold"><strong>curslist</strong></span>
172                          parameter, and a nested iteration over each secondary cursor in the
173                          order they are specified in the <span class="bold"><strong>curslist</strong></span> parameter.  This requires database
174                          traversals to search for the current datum in all the cursors after
175                          the first.  For this reason, the best join performance normally
176                          results from sorting the cursors from the one that refers to the least
177                          number of data items to the one that refers to the most.  By default,
178                          <code class="methodname">Db::join()</code> does this sort on behalf of its caller.
179                     </p>
180          <p>
181                          For the returned join cursor to be used in a transaction-protected
182                          manner, the cursors listed in <span class="bold"><strong>curslist</strong></span> must have been created within the
183                          context of the same transaction.
184                     </p>
185        </div>
186        <div class="sect3" lang="en" xml:lang="en">
187          <div class="titlepage">
188            <div>
189              <div>
190                <h4 class="title"><a id="id1638370"></a>dbcp</h4>
191              </div>
192            </div>
193          </div>
194          <p>
195                          The newly created join cursor is returned in the memory location to
196                          which <span class="bold"><strong>dbcp</strong></span> refers.
197                     </p>
198        </div>
199        <div class="sect3" lang="en" xml:lang="en">
200          <div class="titlepage">
201            <div>
202              <div>
203                <h4 class="title"><a id="id1639064"></a>flags</h4>
204              </div>
205            </div>
206          </div>
207          <p>
208                          The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
209                          or the following value:
210                     </p>
211          <div class="itemizedlist">
212            <ul type="disc">
213              <li>
214                <p><a id="join_DB_JOIN_NOSORT"></a>
215                                <code class="literal">DB_JOIN_NOSORT</code>
216                            </p>
217                <p>
218                                Do not sort the cursors based on the number of data items to which
219                                they refer.  If the data are structured so that cursors with many data
220                                items also share many common elements, higher performance will result
221                                from listing those cursors before cursors with fewer data items; that
222                                is, a sort order other than the default.  The DB_JOIN_NOSORT flag
223                                permits applications to perform join optimization prior to calling the
224                                <code class="methodname">Db::join()</code> method.
225                            </p>
226              </li>
227            </ul>
228          </div>
229        </div>
230      </div>
231      <div class="sect2" lang="en" xml:lang="en">
232        <div class="titlepage">
233          <div>
234            <div>
235              <h3 class="title"><a id="id1638984"></a>Errors</h3>
236            </div>
237          </div>
238        </div>
239        <p>
240                         The <code class="methodname">Db::join()</code> <span>
241            
242            <span>
243                method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> 
244                exception, encapsulating one of the following non-zero errors, or return one
245                of the following non-zero errors:
246            </span>
247        </span>
248                    </p>
249        <div class="sect3" lang="en" xml:lang="en">
250          <div class="titlepage">
251            <div>
252              <div>
253                <h4 class="title"><a id="id1638820"></a><span>DbRepHandleDeadException or</span> DB_REP_HANDLE_DEAD</h4>
254              </div>
255            </div>
256          </div>
257          <p>
258                When a client synchronizes with the master, it is possible for committed
259                transactions to be rolled back. This invalidates all  the database and cursor
260                handles opened in the replication environment. Once this occurs, an attempt to use
261                such a handle will 
262                <span>
263                    throw a <a class="xref" href="dbrephandledead.html" title="DbRepHandleDeadException">DbRepHandleDeadException</a> (if
264                    your application is configured to throw exceptions), or 
265                </span>
266                return <code class="literal">DB_REP_HANDLE_DEAD</code>.
267                The application will need to discard the handle and open a new one in order to
268                continue processing.
269            </p>
270        </div>
271        <div class="sect3" lang="en" xml:lang="en">
272          <div class="titlepage">
273            <div>
274              <div>
275                <h4 class="title"><a id="id1639412"></a><span>DbDeadlockException or </span>DB_REP_LOCKOUT</h4>
276              </div>
277            </div>
278          </div>
279          <p>
280                The operation was blocked by client/master synchronization.
281            </p>
282          <p>
283                <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if
284                your Berkeley DB API is configured to throw exceptions.
285                Otherwise, <code class="literal">DB_REP_LOCKOUT</code> is returned.
286            </p>
287        </div>
288        <div class="sect3" lang="en" xml:lang="en">
289          <div class="titlepage">
290            <div>
291              <div>
292                <h4 class="title"><a id="id1639067"></a>DB_SECONDARY_BAD</h4>
293              </div>
294            </div>
295          </div>
296          <p>
297                A secondary index references a nonexistent primary key.
298            </p>
299        </div>
300        <div class="sect3" lang="en" xml:lang="en">
301          <div class="titlepage">
302            <div>
303              <div>
304                <h4 class="title"><a id="id1639168"></a>EINVAL</h4>
305              </div>
306            </div>
307          </div>
308          <p>
309                          If cursor methods other than  <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a>  
310                          or <a class="xref" href="dbcclose.html" title="Dbc::close()">Dbc::close()</a>  were called;
311                          or if an invalid flag value or parameter was specified.
312                        </p>
313        </div>
314      </div>
315      <div class="sect2" lang="en" xml:lang="en">
316        <div class="titlepage">
317          <div>
318            <div>
319              <h3 class="title"><a id="id1639111"></a>Class</h3>
320            </div>
321          </div>
322        </div>
323        <p>
324                    <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>  
325            </p>
326      </div>
327      <div class="sect2" lang="en" xml:lang="en">
328        <div class="titlepage">
329          <div>
330            <div>
331              <h3 class="title"><a id="id1638707"></a>See Also</h3>
332            </div>
333          </div>
334        </div>
335        <p>
336                     <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 
337                </p>
338      </div>
339    </div>
340    <div class="navfooter">
341      <hr />
342      <table width="100%" summary="Navigation footer">
343        <tr>
344          <td width="40%" align="left"><a accesskey="p" href="dbget_type.html">Prev</a> </td>
345          <td width="20%" align="center">
346            <a accesskey="u" href="db.html">Up</a>
347          </td>
348          <td width="40%" align="right"> <a accesskey="n" href="dbkey_range.html">Next</a></td>
349        </tr>
350        <tr>
351          <td width="40%" align="left" valign="top">Db::get_type() </td>
352          <td width="20%" align="center">
353            <a accesskey="h" href="index.html">Home</a>
354          </td>
355          <td width="40%" align="right" valign="top"> Db::key_range()</td>
356        </tr>
357      </table>
358    </div>
359  </body>
360</html>
361