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">
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()" />
15 <div xmlns="" class="navheader">
17 <p>Library Version 11.2.5.3</p>
19 <table width="100%" summary="Navigation header">
21 <th colspan="3" align="center">DB->set_bt_compare()</th>
24 <td width="20%" align="left"><a accesskey="p" href="dbset_append_recno.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 2.
28 <td width="20%" align="right"> <a accesskey="n" href="dbset_bt_compress.html">Next</a></td>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
37 <h2 class="title" style="clear: both"><a id="dbset_bt_compare"></a>DB->set_bt_compare()</h2>
41 <pre class="programlisting">#include <db.h>
44 DB->set_bt_compare(DB *db,
45 int (*bt_compare_fcn)(DB *db, const DBT *dbt1, const DBT *dbt2)); </pre>
47 Set the Btree key comparison function. The comparison function is
48 called whenever it is necessary to compare a key specified by the
49 application with a key currently stored in the tree.
52 If no comparison function is specified, the keys are compared
53 lexically, with shorter keys collating before longer keys.
56 The <code class="methodname">DB->set_bt_compare()</code> method configures operations performed using
57 the specified <a class="link" href="db.html" title="Chapter 2. The DB Handle">DB</a> handle,
58 not all operations performed on the underlying database.
61 The <code class="methodname">DB->set_bt_compare()</code> method may not be called after the
62 <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> method is called. If
63 the database already exists when <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a>
64 is called, the information specified to <code class="methodname">DB->set_bt_compare()</code> must be the same as
65 that historically used to create the database or corruption can occur.
68 The <code class="methodname">DB->set_bt_compare()</code> <span>
70 method returns a non-zero error value on failure and 0 on success.
75 <div class="sect2" lang="en" xml:lang="en">
76 <div class="titlepage">
79 <h3 class="title"><a id="idp58023488"></a>Parameters</h3>
83 <div class="sect3" lang="en" xml:lang="en">
84 <div class="titlepage">
87 <h4 class="title"><a id="idp58064680"></a>bt_compare_fcn</h4>
92 The <span class="bold"><strong>bt_compare_fcn</strong></span> function is the
93 application-specified Btree comparison function. The comparison
94 function takes three parameters:
96 <div class="itemizedlist">
100 <code class="literal">db</code>
103 The <span class="bold"><strong>db</strong></span> parameter is the enclosing
109 <code class="literal">dbt1</code>
112 The <span class="bold"><strong>dbt1</strong></span> parameter is the
113 <a class="link" href="dbt.html" title="Chapter 4. The DBT Handle">DBT</a> representing the application
119 <code class="literal">dbt2</code>
122 The <span class="bold"><strong>dbt2</strong></span> parameter is the
123 <a class="link" href="dbt.html" title="Chapter 4. The DBT Handle">DBT</a> representing the current
130 The <span class="bold"><strong>bt_compare_fcn</strong></span> function must return an
131 integer value less than, equal to, or greater than zero if the first key
132 parameter is considered to be respectively less than, equal to, or greater than
133 the second key parameter. In addition, the comparison function must cause the
134 keys in the database to be <span class="emphasis"><em>well-ordered</em></span>. The comparison
135 function must correctly handle any key values used by the application (possibly
136 including zero-length keys). In addition, when Btree key prefix comparison is
138 <a class="xref" href="dbset_bt_prefix.html" title="DB->set_bt_prefix()">DB->set_bt_prefix()</a>
139 for more information), the comparison routine may be passed a prefix of any database
140 key. The <span class="bold"><strong>data</strong></span> and <span class="bold"><strong>size</strong></span>
141 fields of the <a class="link" href="dbt.html" title="Chapter 4. The DBT Handle">DBT</a> are the only fields
142 that may be used for the purposes of this comparison, and no particular
143 alignment of the memory to which by the <span class="bold"><strong>data</strong></span>
144 field refers may be assumed.
148 <div class="sect2" lang="en" xml:lang="en">
149 <div class="titlepage">
152 <h3 class="title"><a id="idp58043144"></a>Errors</h3>
157 The <code class="methodname">DB->set_bt_compare()</code> <span>
159 method may fail and return one of the following non-zero errors:
164 <div class="sect3" lang="en" xml:lang="en">
165 <div class="titlepage">
168 <h4 class="title"><a id="idp58084576"></a>EINVAL</h4>
173 If the method was called after <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a>
174 was called; or if an invalid flag value or parameter was specified.
178 <div class="sect2" lang="en" xml:lang="en">
179 <div class="titlepage">
182 <h3 class="title"><a id="idp58085656"></a>Class</h3>
187 <a class="link" href="db.html" title="Chapter 2. The DB Handle">DB</a>
190 <div class="sect2" lang="en" xml:lang="en">
191 <div class="titlepage">
194 <h3 class="title"><a id="idp58081424"></a>See Also</h3>
199 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a>
203 <div class="navfooter">
205 <table width="100%" summary="Navigation footer">
207 <td width="40%" align="left"><a accesskey="p" href="dbset_append_recno.html">Prev</a> </td>
208 <td width="20%" align="center">
209 <a accesskey="u" href="db.html">Up</a>
211 <td width="40%" align="right"> <a accesskey="n" href="dbset_bt_compress.html">Next</a></td>
214 <td width="40%" align="left" valign="top">DB->set_append_recno() </td>
215 <td width="20%" align="center">
216 <a accesskey="h" href="index.html">Home</a>
218 <td width="40%" align="right" valign="top"> DB->set_bt_compress()</td>