• 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_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::set_append_recno()" />
12    <link rel="next" href="dbset_bt_compress.html" title="Db::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::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::set_bt_compare()</h2>
35          </div>
36        </div>
37      </div>
38      <pre class="programlisting">#include &lt;db_cxx.h&gt;
39 
40extern "C" {
41    typedef int (*bt_compare_fcn_type)(DB *db, const DBT *dbt1, const DBT *dbt2);
42};
43int
44Db::set_bt_compare(bt_compare_fcn_type bt_compare_fcn);</pre>
45      <p>
46         Set the Btree key comparison function.  The comparison function is
47         called whenever it is necessary to compare a key specified by the
48         application with a key currently stored in the tree.
49    </p>
50      <p>
51         If no comparison function is specified, the keys are compared
52         lexically, with shorter keys collating before longer keys.
53    </p>
54      <p>
55         The <code class="methodname">Db::set_bt_compare()</code> method configures operations performed using
56         the specified <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>  handle,
57         not all operations performed on the underlying database.
58    </p>
59      <p>
60         The <code class="methodname">Db::set_bt_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_bt_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_bt_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="id1643187"></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="id1643184"></a>bt_compare_fcn</h4>
89              </div>
90            </div>
91          </div>
92          <p>
93                          The <span class="bold"><strong>bt_compare_fcn</strong></span> function is the
94                          application-specified Btree comparison function.  The comparison
95                          function takes three parameters:
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 the 
114                                 <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>  representing the application
115                                 supplied key.
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 the 
124                                 <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a>  representing the current
125                                 tree's key.
126                            </p>
127              </li>
128            </ul>
129          </div>
130          <p>
131                    The <span class="bold"><strong>bt_compare_fcn</strong></span> function must return an
132                    integer value less than, equal to, or greater than zero if the first key
133                    parameter is considered to be respectively less than, equal to, or greater than
134                    the second key parameter. In addition, the comparison function must cause the
135                    keys in the database to be <span class="emphasis"><em>well-ordered</em></span>. The comparison
136                    function must correctly handle any key values used by the application (possibly
137                    including zero-length keys). In addition, when Btree key prefix comparison is
138                    being performed (see 
139                    <a class="xref" href="dbset_bt_prefix.html" title="Db::set_bt_prefix()">Db::set_bt_prefix()</a> 
140                    for more information), the comparison routine may be passed a prefix of any database 
141                    key. The <span class="bold"><strong>data</strong></span> and <span class="bold"><strong>size</strong></span>
142                    fields of the <a class="link" href="dbt.html" title="Chapter 4.  The Dbt Handle">Dbt</a> are the only fields
143                    that may be used for the purposes of this comparison, and no particular
144                    alignment of the memory to which by the <span class="bold"><strong>data</strong></span>
145                    field refers may be assumed.
146            </p>
147        </div>
148      </div>
149      <div class="sect2" lang="en" xml:lang="en">
150        <div class="titlepage">
151          <div>
152            <div>
153              <h3 class="title"><a id="id1643490"></a>Errors</h3>
154            </div>
155          </div>
156        </div>
157        <p>
158                         The <code class="methodname">Db::set_bt_compare()</code> <span>
159            
160            <span>
161                method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> 
162                exception, encapsulating one of the following non-zero errors, or return one
163                of the following non-zero errors:
164            </span>
165        </span>
166                    </p>
167        <div class="sect3" lang="en" xml:lang="en">
168          <div class="titlepage">
169            <div>
170              <div>
171                <h4 class="title"><a id="id1643517"></a>EINVAL</h4>
172              </div>
173            </div>
174          </div>
175          <p>
176                If the method was called after <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> 
177                was called; or if an invalid flag value or parameter was specified.
178            </p>
179        </div>
180      </div>
181      <div class="sect2" lang="en" xml:lang="en">
182        <div class="titlepage">
183          <div>
184            <div>
185              <h3 class="title"><a id="id1643518"></a>Class</h3>
186            </div>
187          </div>
188        </div>
189        <p>
190                <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>  
191            </p>
192      </div>
193      <div class="sect2" lang="en" xml:lang="en">
194        <div class="titlepage">
195          <div>
196            <div>
197              <h3 class="title"><a id="id1643182"></a>See Also</h3>
198            </div>
199          </div>
200        </div>
201        <p>
202                     <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 
203                </p>
204      </div>
205    </div>
206    <div class="navfooter">
207      <hr />
208      <table width="100%" summary="Navigation footer">
209        <tr>
210          <td width="40%" align="left"><a accesskey="p" href="dbset_append_recno.html">Prev</a> </td>
211          <td width="20%" align="center">
212            <a accesskey="u" href="db.html">Up</a>
213          </td>
214          <td width="40%" align="right"> <a accesskey="n" href="dbset_bt_compress.html">Next</a></td>
215        </tr>
216        <tr>
217          <td width="40%" align="left" valign="top">Db::set_append_recno() </td>
218          <td width="20%" align="center">
219            <a accesskey="h" href="index.html">Home</a>
220          </td>
221          <td width="40%" align="right" valign="top"> Db::set_bt_compress()</td>
222        </tr>
223      </table>
224    </div>
225  </body>
226</html>
227