| 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 xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">DB->set_bt_compare()</th> |
| 22 | </tr> |
| 23 | <tr> |
| 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. |
| 26 | The DB Handle |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="dbset_bt_compress.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="dbset_bt_compare"></a>DB->set_bt_compare()</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db.h> |
| 42 | |
| 43 | int |
| 44 | DB->set_bt_compare(DB *db, |
| 45 | int (*bt_compare_fcn)(DB *db, const DBT *dbt1, const DBT *dbt2)); </pre> |
| 46 | <p> |
| 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. |
| 50 | </p> |
| 51 | <p> |
| 52 | If no comparison function is specified, the keys are compared |
| 53 | lexically, with shorter keys collating before longer keys. |
| 54 | </p> |
| 55 | <p> |
| 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. |
| 59 | </p> |
| 60 | <p> |
| 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. |
| 66 | </p> |
| 67 | <p> |
| 68 | The <code class="methodname">DB->set_bt_compare()</code> <span> |
| 69 | <span> |
| 70 | method returns a non-zero error value on failure and 0 on success. |
| 71 | </span> |
| 72 | |
| 73 | </span> |
| 74 | </p> |
| 75 | <div class="sect2" lang="en" xml:lang="en"> |
| 76 | <div class="titlepage"> |
| 77 | <div> |
| 78 | <div> |
| 79 | <h3 class="title"><a id="idp50077848"></a>Parameters</h3> |
| 80 | </div> |
| 81 | </div> |
| 82 | </div> |
| 83 | <div class="sect3" lang="en" xml:lang="en"> |
| 84 | <div class="titlepage"> |
| 85 | <div> |
| 86 | <div> |
| 87 | <h4 class="title"><a id="idp50078520"></a>bt_compare_fcn</h4> |
| 88 | </div> |
| 89 | </div> |
| 90 | </div> |
| 91 | <p> |
| 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: |
| 95 | </p> |
| 96 | <div class="itemizedlist"> |
| 97 | <ul type="disc"> |
| 98 | <li> |
| 99 | <p> |
| 100 | <code class="literal">db</code> |
| 101 | </p> |
| 102 | <p> |
| 103 | The <span class="bold"><strong>db</strong></span> parameter is the enclosing |
| 104 | database handle. |
| 105 | </p> |
| 106 | </li> |
| 107 | <li> |
| 108 | <p> |
| 109 | <code class="literal">dbt1</code> |
| 110 | </p> |
| 111 | <p> |
| 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 |
| 114 | supplied key. |
| 115 | </p> |
| 116 | </li> |
| 117 | <li> |
| 118 | <p> |
| 119 | <code class="literal">dbt2</code> |
| 120 | </p> |
| 121 | <p> |
| 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 |
| 124 | tree's key. |
| 125 | </p> |
| 126 | </li> |
| 127 | </ul> |
| 128 | </div> |
| 129 | <p> |
| 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 |
| 137 | being performed (see |
| 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. |
| 145 | </p> |
| 146 | </div> |
| 147 | </div> |
| 148 | <div class="sect2" lang="en" xml:lang="en"> |
| 149 | <div class="titlepage"> |
| 150 | <div> |
| 151 | <div> |
| 152 | <h3 class="title"><a id="idp50085896"></a>Errors</h3> |
| 153 | </div> |
| 154 | </div> |
| 155 | </div> |
| 156 | <p> |
| 157 | The <code class="methodname">DB->set_bt_compare()</code> <span> |
| 158 | <span> |
| 159 | method may fail and return one of the following non-zero errors: |
| 160 | </span> |
| 161 | |
| 162 | </span> |
| 163 | </p> |
| 164 | <div class="sect3" lang="en" xml:lang="en"> |
| 165 | <div class="titlepage"> |
| 166 | <div> |
| 167 | <div> |
| 168 | <h4 class="title"><a id="idp50097928"></a>EINVAL</h4> |
| 169 | </div> |
| 170 | </div> |
| 171 | </div> |
| 172 | <p> |
| 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. |
| 175 | </p> |
| 176 | </div> |
| 177 | </div> |
| 178 | <div class="sect2" lang="en" xml:lang="en"> |
| 179 | <div class="titlepage"> |
| 180 | <div> |
| 181 | <div> |
| 182 | <h3 class="title"><a id="idp50099008"></a>Class</h3> |
| 183 | </div> |
| 184 | </div> |
| 185 | </div> |
| 186 | <p> |
| 187 | <a class="link" href="db.html" title="Chapter 2. The DB Handle">DB</a> |
| 188 | </p> |
| 189 | </div> |
| 190 | <div class="sect2" lang="en" xml:lang="en"> |
| 191 | <div class="titlepage"> |
| 192 | <div> |
| 193 | <div> |
| 194 | <h3 class="title"><a id="idp50094776"></a>See Also</h3> |
| 195 | </div> |
| 196 | </div> |
| 197 | </div> |
| 198 | <p> |
| 199 | <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> |
| 200 | </p> |
| 201 | </div> |
| 202 | </div> |
| 203 | <div class="navfooter"> |
| 204 | <hr /> |
| 205 | <table width="100%" summary="Navigation footer"> |
| 206 | <tr> |
| 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> |
| 210 | </td> |
| 211 | <td width="40%" align="right"> <a accesskey="n" href="dbset_bt_compress.html">Next</a></td> |
| 212 | </tr> |
| 213 | <tr> |
| 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> |
| 217 | </td> |
| 218 | <td width="40%" align="right" valign="top"> DB->set_bt_compress()</td> |
| 219 | </tr> |
| 220 | </table> |
| 221 | </div> |
| 222 | </body> |
| 223 | </html> |