• 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::set_dup_compare()</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="dbset_create_dir.html" title="Db::set_create_dir()" />
12    <link rel="next" href="dbset_encrypt.html" title="Db::set_encrypt()" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Db::set_dup_compare()</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="dbset_create_dir.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="dbset_encrypt.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="dbset_dup_compare"></a>Db::set_dup_compare()</h2>
35          </div>
36        </div>
37      </div>
38      <pre class="programlisting">#include &lt;db_cxx.h&gt;
39 
40extern "C" {
41    typedef int (*dup_compare_fcn_type)(DB *db, const DBT *dbt1, 
42    const DBT *dbt2);
43};
44int
45Db::set_dup_compare(dup_compare_fcn_type dup_compare_fcn);</pre>
46      <p>
47         Set the duplicate data item comparison function.  The comparison
48         function is called whenever it is necessary to compare a data item
49         specified by the application with a data item currently stored in the
50         database.  Calling <code class="methodname">Db::set_dup_compare()</code> implies calling 
51         <a class="xref" href="dbset_flags.html" title="Db::set_flags()">Db::set_flags()</a>  with the
52         <a class="link" href="dbset_flags.html#dbset_flags_DB_DUPSORT">DB_DUPSORT</a> 
53         flag.
54    </p>
55      <p>
56         If no comparison function is specified, the data items are compared
57         lexically, with shorter data items collating before longer data items.
58    </p>
59      <p>
60         The <code class="methodname">Db::set_dup_compare()</code> method may not be called after the 
61         <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a>  method is called. If
62         the database already exists when <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a>  
63         is called, the information specified to <code class="methodname">Db::set_dup_compare()</code> must be the same as
64         that historically used to create the database or corruption can occur.
65    </p>
66      <p>
67         The <code class="methodname">Db::set_dup_compare()</code> <span>
68            
69            <span>
70                method either returns a non-zero error value or throws an
71                exception that encapsulates a non-zero error value on
72                failure, and returns 0 on success.
73            </span>
74        </span>
75    </p>
76      <div class="sect2" lang="en" xml:lang="en">
77        <div class="titlepage">
78          <div>
79            <div>
80              <h3 class="title"><a id="id1645225"></a>Parameters</h3>
81            </div>
82          </div>
83        </div>
84        <div class="sect3" lang="en" xml:lang="en">
85          <div class="titlepage">
86            <div>
87              <div>
88                <h4 class="title"><a id="id1645197"></a>dup_compare_fcn</h4>
89              </div>
90            </div>
91          </div>
92          <p>
93                          The <span class="bold"><strong>dup_compare_fcn</strong></span> function is the
94                          application-specified duplicate data item comparison function.  The
95                          function takes three arguments:
96                     </p>
97          <div class="itemizedlist">
98            <ul type="disc">
99              <li>
100                <p>
101                                <code class="literal">db</code>
102                            </p>
103                <p>
104                                 The <span class="bold"><strong>db</strong></span> parameter is the enclosing
105                                 database handle.
106                            </p>
107              </li>
108              <li>
109                <p>
110                                <code class="literal">dbt1</code>
111                            </p>
112                <p>
113                                 The <span class="bold"><strong>dbt1</strong></span> parameter is a 
114                                 <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>  representing the application
115                                 supplied data item.
116                            </p>
117              </li>
118              <li>
119                <p>
120                                <code class="literal">dbt2</code>
121                            </p>
122                <p>
123                                 The <span class="bold"><strong>dbt2</strong></span> parameter is a 
124                                 <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>  representing the current
125                                 tree's data item.
126                            </p>
127              </li>
128            </ul>
129          </div>
130          <p>
131                    The <span class="bold"><strong>dup_compare_fcn</strong></span> function must return an
132                    integer value less than, equal to, or greater than zero if the first data item
133                    parameter is considered to be respectively less than, equal to, or greater than
134                    the second data item parameter. In addition, the comparison function must cause
135                    the data items in the set to be <span class="emphasis"><em>well-ordered</em></span>. The
136                    comparison function must correctly handle any data item values used by the
137                    application (possibly including zero-length data items).  The 
138                    <span class="bold"><strong>data</strong></span> and <span class="bold"><strong>size</strong></span>
139                    fields of the <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> are the only fields
140                    that may be used for the purposes of this comparison, and no particular
141                    alignment of the memory to which the <span class="bold"><strong>data</strong></span> field
142                    refers may be assumed.
143            </p>
144        </div>
145      </div>
146      <div class="sect2" lang="en" xml:lang="en">
147        <div class="titlepage">
148          <div>
149            <div>
150              <h3 class="title"><a id="id1645452"></a>Errors</h3>
151            </div>
152          </div>
153        </div>
154        <p>
155                         The <code class="methodname">Db::set_dup_compare()</code> <span>
156            
157            <span>
158                method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> 
159                exception, encapsulating one of the following non-zero errors, or return one
160                of the following non-zero errors:
161            </span>
162        </span>
163                    </p>
164        <div class="sect3" lang="en" xml:lang="en">
165          <div class="titlepage">
166            <div>
167              <div>
168                <h4 class="title"><a id="id1645363"></a>EINVAL</h4>
169              </div>
170            </div>
171          </div>
172          <p>
173                An invalid flag value or parameter was specified.
174            </p>
175        </div>
176      </div>
177      <div class="sect2" lang="en" xml:lang="en">
178        <div class="titlepage">
179          <div>
180            <div>
181              <h3 class="title"><a id="id1645364"></a>Class</h3>
182            </div>
183          </div>
184        </div>
185        <p>
186                <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>  
187            </p>
188      </div>
189      <div class="sect2" lang="en" xml:lang="en">
190        <div class="titlepage">
191          <div>
192            <div>
193              <h3 class="title"><a id="id1645459"></a>See Also</h3>
194            </div>
195          </div>
196        </div>
197        <p>
198                     <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 
199                </p>
200      </div>
201    </div>
202    <div class="navfooter">
203      <hr />
204      <table width="100%" summary="Navigation footer">
205        <tr>
206          <td width="40%" align="left"><a accesskey="p" href="dbset_create_dir.html">Prev</a> </td>
207          <td width="20%" align="center">
208            <a accesskey="u" href="db.html">Up</a>
209          </td>
210          <td width="40%" align="right"> <a accesskey="n" href="dbset_encrypt.html">Next</a></td>
211        </tr>
212        <tr>
213          <td width="40%" align="left" valign="top">Db::set_create_dir() </td>
214          <td width="20%" align="center">
215            <a accesskey="h" href="index.html">Home</a>
216          </td>
217          <td width="40%" align="right" valign="top"> Db::set_encrypt()</td>
218        </tr>
219      </table>
220    </div>
221  </body>
222</html>
223