• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/db-4.8.30/docs/gsg/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>Using Cursors with Secondary Databases</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="Getting Started with Berkeley DB" />
10    <link rel="up" href="indexes.html" title="Chapter��5.��Secondary Databases" />
11    <link rel="prev" href="secondaryDelete.html" title="Deleting Secondary Database Records" />
12    <link rel="next" href="joins.html" title="Database Joins" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">
19        
20        <span>Using Cursors with Secondary Databases</span>
21    </th>
22        </tr>
23        <tr>
24          <td width="20%" align="left"><a accesskey="p" href="secondaryDelete.html">Prev</a>��</td>
25          <th width="60%" align="center">Chapter��5.��Secondary Databases</th>
26          <td width="20%" align="right">��<a accesskey="n" href="joins.html">Next</a></td>
27        </tr>
28      </table>
29      <hr />
30    </div>
31    <div class="sect1" lang="en" xml:lang="en">
32      <div class="titlepage">
33        <div>
34          <div>
35            <h2 class="title" style="clear: both"><a id="secondaryCursor"></a>
36        
37        <span>Using Cursors with Secondary Databases</span>
38    </h2>
39          </div>
40        </div>
41      </div>
42      <p>
43        Just like cursors on a primary database, you can use 
44             
45            <span>cursors on secondary databases</span> 
46        to iterate over the records in a secondary database. Like
47
48          
49         <span>cursors used with primary databases,</span> 
50        
51        you can also use 
52          
53         <span>cursors with secondary databases</span> 
54        to search for specific records in a database, to seek to the first 
55        or last record in the database, to get the next duplicate record, 
56            
57        and so forth. For a complete description on cursors and their capabilities, see
58        <a class="xref" href="Cursors.html" title="Chapter��4.��Using Cursors">Using Cursors</a>.
59    </p>
60      <p>
61        However, when you use 
62             
63            <span>cursors with secondary databases:</span> 
64    </p>
65      <div class="itemizedlist">
66        <ul type="disc">
67          <li>
68            <p>
69            Any data returned is the data contained on the primary database
70            record referenced by the secondary record.
71        </p>
72          </li>
73          <li>
74            <p>
75            You cannot use <code class="literal">DB_GET_BOTH</code> and related flags with
76                
77                <code class="methodname">Db::get()</code>
78            and a secondary database. Instead, you must use 
79                
80                <span><code class="methodname">Db::pget()</code>.</span>
81            Also, in that case the primary and secondary key given on the call to 
82                
83                <code class="methodname">Db::pget()</code>
84            must match the secondary key and associated primary record key in
85            order for that primary record to be returned as a result of the
86            call.
87        </p>
88          </li>
89        </ul>
90      </div>
91      <p>
92        For example, suppose you are using the databases, classes, and key
93        
94        <span>extractors</span>
95        described in <a class="xref" href="keyCreator.html" title="Implementing Key Extractors">Implementing Key 
96        
97        <span>Extractors</span>
98        </a>. 
99        Then the following searches for a person's
100        name in the secondary database, and deletes all secondary and primary
101        records that use that name.
102    </p>
103      <a id="cxx_index8"></a>
104      <pre class="programlisting">#include &lt;db_cxx.h&gt;
105                                                                                                                                     
106...
107                                                                                                                                     
108Db my_database(NULL, 0);
109Db my_index(NULL, 0);
110
111
112// Get a cursor on the secondary database
113Dbc *cursorp;
114my_index.cursor(NULL, &amp;cursorp, 0);
115
116
117// Name to delete
118char *search_name = "John Doe"; 
119
120// Instantiate Dbts as normal
121Dbt key(search_name, strlen(search_name) + 1);
122Dbt data;
123
124 
125// Position the cursor
126while (cursorp-&gt;get(&amp;key, &amp;data, DB_SET) == 0)
127    cursorp-&gt;del(0); </pre>
128    </div>
129    <div class="navfooter">
130      <hr />
131      <table width="100%" summary="Navigation footer">
132        <tr>
133          <td width="40%" align="left"><a accesskey="p" href="secondaryDelete.html">Prev</a>��</td>
134          <td width="20%" align="center">
135            <a accesskey="u" href="indexes.html">Up</a>
136          </td>
137          <td width="40%" align="right">��<a accesskey="n" href="joins.html">Next</a></td>
138        </tr>
139        <tr>
140          <td width="40%" align="left" valign="top">Deleting Secondary Database Records��</td>
141          <td width="20%" align="center">
142            <a accesskey="h" href="index.html">Home</a>
143          </td>
144          <td width="40%" align="right" valign="top">��Database Joins</td>
145        </tr>
146      </table>
147    </div>
148  </body>
149</html>
150