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