• 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_bt_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_append_recno.html" title="DB-&gt;set_append_recno()" />
12    <link rel="next" href="dbset_bt_compress.html" title="DB-&gt;set_bt_compress()" />
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_bt_compare()</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="dbset_append_recno.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_bt_compress.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_bt_compare"></a>DB-&gt;set_bt_compare()</h2>
35          </div>
36        </div>
37      </div>
38      <pre class="programlisting">#include &lt;db.h&gt;
39
40int
41DB-&gt;set_bt_compare(DB *db,
42    int (*bt_compare_fcn)(DB *db, const DBT *dbt1, const DBT *dbt2));  </pre>
43      <p>
44         Set the Btree 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 tree.
47    </p>
48      <p>
49         If no comparison function is specified, the keys are compared
50         lexically, with shorter keys collating before longer keys.
51    </p>
52      <p>
53         The <code class="methodname">DB-&gt;set_bt_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_bt_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_bt_compare()</code> must be the same as
62         that historically used to create the database or corruption can occur.
63    </p>
64      <p>
65         The <code class="methodname">DB-&gt;set_bt_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="id1642390"></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="id1642898"></a>bt_compare_fcn</h4>
85              </div>
86            </div>
87          </div>
88          <p>
89                          The <span class="bold"><strong>bt_compare_fcn</strong></span> function is the
90                          application-specified Btree 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 
110                                 <a class="link" href="dbt.html" title="Chapter��4.�� The DBT Handle">DBT</a>  representing the application
111                                 supplied key.
112                            </p>
113              </li>
114              <li>
115                <p>
116                                <code class="literal">dbt2</code>
117                                </p>
118                <p>
119                                 The <span class="bold"><strong>dbt2</strong></span> parameter is the 
120                                 <a class="link" href="dbt.html" title="Chapter��4.�� The DBT Handle">DBT</a>  representing the current
121                                 tree's key.
122                            </p>
123              </li>
124            </ul>
125          </div>
126          <p>
127                    The <span class="bold"><strong>bt_compare_fcn</strong></span> function must return an
128                    integer value less than, equal to, or greater than zero if the first key
129                    parameter is considered to be respectively less than, equal to, or greater than
130                    the second key parameter. In addition, the comparison function must cause the
131                    keys in the database to be <span class="emphasis"><em>well-ordered</em></span>. The comparison
132                    function must correctly handle any key values used by the application (possibly
133                    including zero-length keys). In addition, when Btree key prefix comparison is
134                    being performed (see 
135                    <a class="xref" href="dbset_bt_prefix.html" title="DB-&gt;set_bt_prefix()">DB-&gt;set_bt_prefix()</a> 
136                    for more information), the comparison routine may be passed a prefix of any database 
137                    key. The <span class="bold"><strong>data</strong></span> and <span class="bold"><strong>size</strong></span>
138                    fields of the <a class="link" href="dbt.html" title="Chapter��4.�� The DBT Handle">DBT</a> are the only fields
139                    that may be used for the purposes of this comparison, and no particular
140                    alignment of the memory to which by the <span class="bold"><strong>data</strong></span>
141                    field refers may be assumed.
142            </p>
143        </div>
144      </div>
145      <div class="sect2" lang="en" xml:lang="en">
146        <div class="titlepage">
147          <div>
148            <div>
149              <h3 class="title"><a id="id1643163"></a>Errors</h3>
150            </div>
151          </div>
152        </div>
153        <p>
154                         The <code class="methodname">DB-&gt;set_bt_compare()</code> <span>
155            <span>
156                 method may fail and return one of the following non-zero errors:
157            </span>
158            
159        </span>
160                    </p>
161        <div class="sect3" lang="en" xml:lang="en">
162          <div class="titlepage">
163            <div>
164              <div>
165                <h4 class="title"><a id="id1643231"></a>EINVAL</h4>
166              </div>
167            </div>
168          </div>
169          <p>
170                If the method was called after <a class="xref" href="dbopen.html" title="DB-&gt;open()">DB-&gt;open()</a> 
171                was called; or if an invalid flag value or parameter was specified.
172            </p>
173        </div>
174      </div>
175      <div class="sect2" lang="en" xml:lang="en">
176        <div class="titlepage">
177          <div>
178            <div>
179              <h3 class="title"><a id="id1643232"></a>Class</h3>
180            </div>
181          </div>
182        </div>
183        <p>
184                <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a>  
185            </p>
186      </div>
187      <div class="sect2" lang="en" xml:lang="en">
188        <div class="titlepage">
189          <div>
190            <div>
191              <h3 class="title"><a id="id1643006"></a>See Also</h3>
192            </div>
193          </div>
194        </div>
195        <p>
196                     <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 
197                </p>
198      </div>
199    </div>
200    <div class="navfooter">
201      <hr />
202      <table width="100%" summary="Navigation footer">
203        <tr>
204          <td width="40%" align="left"><a accesskey="p" href="dbset_append_recno.html">Prev</a>��</td>
205          <td width="20%" align="center">
206            <a accesskey="u" href="db.html">Up</a>
207          </td>
208          <td width="40%" align="right">��<a accesskey="n" href="dbset_bt_compress.html">Next</a></td>
209        </tr>
210        <tr>
211          <td width="40%" align="left" valign="top">DB-&gt;set_append_recno()��</td>
212          <td width="20%" align="center">
213            <a accesskey="h" href="index.html">Home</a>
214          </td>
215          <td width="40%" align="right" valign="top">��DB-&gt;set_bt_compress()</td>
216        </tr>
217      </table>
218    </div>
219  </body>
220</html>
221