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