| 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_dup_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_create_dir.html" title="Db::set_create_dir()" /> |
| 12 |
<link rel="next" href="dbset_encrypt.html" title="Db::set_encrypt()" /> |
| 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_dup_compare()</th> |
| 22 |
</tr> |
| 23 |
<tr> |
| 24 |
<td width="20%" align="left"><a accesskey="p" href="dbset_create_dir.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_encrypt.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_dup_compare"></a>Db::set_dup_compare()</h2> |
| 38 |
</div> |
| 39 |
</div> |
| 40 |
</div> |
| 41 |
<pre class="programlisting">#include <db_cxx.h> |
| 42 |
|
| 43 |
extern "C" { |
| 44 |
typedef int (*dup_compare_fcn_type)(DB *db, const DBT *dbt1, |
| 45 |
const DBT *dbt2); |
| 46 |
}; |
| 47 |
int |
| 48 |
Db::set_dup_compare(dup_compare_fcn_type dup_compare_fcn);</pre> |
| 49 |
<p> |
| 50 |
Set the duplicate data item comparison function. The comparison |
| 51 |
function is called whenever it is necessary to compare a data item |
| 52 |
specified by the application with a data item currently stored in the |
| 53 |
database. Calling <code class="methodname">Db::set_dup_compare()</code> implies calling |
| 54 |
<a class="xref" href="dbset_flags.html" title="Db::set_flags()">Db::set_flags()</a> with the |
| 55 |
<a class="link" href="dbset_flags.html#dbset_flags_DB_DUPSORT">DB_DUPSORT</a> |
| 56 |
flag. |
| 57 |
</p> |
| 58 |
<p> |
| 59 |
If no comparison function is specified, the data items are compared |
| 60 |
lexically, with shorter data items collating before longer data items. |
| 61 |
</p> |
| 62 |
<p> |
| 63 |
The <code class="methodname">Db::set_dup_compare()</code> method may not be called after the |
| 64 |
<a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> method is called. If |
| 65 |
the database already exists when <a class="xref" href="dbopen.html" title="Db::open()">Db::open()</a> |
| 66 |
is called, the information specified to <code class="methodname">Db::set_dup_compare()</code> must be the same as |
| 67 |
that historically used to create the database or corruption can occur. |
| 68 |
</p> |
| 69 |
<p> |
| 70 |
The <code class="methodname">Db::set_dup_compare()</code> <span> |
| 71 |
|
| 72 |
<span> |
| 73 |
method either returns a non-zero error value or throws an |
| 74 |
exception that encapsulates a non-zero error value on |
| 75 |
failure, and returns 0 on success. |
| 76 |
</span> |
| 77 |
</span> |
| 78 |
</p> |
| 79 |
<div class="sect2" lang="en" xml:lang="en"> |
| 80 |
<div class="titlepage"> |
| 81 |
<div> |
| 82 |
<div> |
| 83 |
<h3 class="title"><a id="idp391656"></a>Parameters</h3> |
| 84 |
</div> |
| 85 |
</div> |
| 86 |
</div> |
| 87 |
<div class="sect3" lang="en" xml:lang="en"> |
| 88 |
<div class="titlepage"> |
| 89 |
<div> |
| 90 |
<div> |
| 91 |
<h4 class="title"><a id="idp419736"></a>dup_compare_fcn</h4> |
| 92 |
</div> |
| 93 |
</div> |
| 94 |
</div> |
| 95 |
<p> |
| 96 |
The <span class="bold"><strong>dup_compare_fcn</strong></span> function is the |
| 97 |
application-specified duplicate data item comparison function. The |
| 98 |
function takes three arguments: |
| 99 |
</p> |
| 100 |
<div class="itemizedlist"> |
| 101 |
<ul type="disc"> |
| 102 |
<li> |
| 103 |
<p> |
| 104 |
<code class="literal">db</code> |
| 105 |
</p> |
| 106 |
<p> |
| 107 |
The <span class="bold"><strong>db</strong></span> parameter is the enclosing |
| 108 |
database handle. |
| 109 |
</p> |
| 110 |
</li> |
| 111 |
<li> |
| 112 |
<p> |
| 113 |
<code class="literal">dbt1</code> |
| 114 |
</p> |
| 115 |
<p> |
| 116 |
The <span class="bold"><strong>dbt1</strong></span> parameter is a |
| 117 |
<a class="link" href="dbt.html" title="Chapter 4. The Dbt Handle">Dbt</a> representing the application |
| 118 |
supplied data item. |
| 119 |
</p> |
| 120 |
</li> |
| 121 |
<li> |
| 122 |
<p> |
| 123 |
<code class="literal">dbt2</code> |
| 124 |
</p> |
| 125 |
<p> |
| 126 |
The <span class="bold"><strong>dbt2</strong></span> parameter is a |
| 127 |
<a class="link" href="dbt.html" title="Chapter 4. The Dbt Handle">Dbt</a> representing the current |
| 128 |
tree's data item. |
| 129 |
</p> |
| 130 |
</li> |
| 131 |
</ul> |
| 132 |
</div> |
| 133 |
<p> |
| 134 |
The <span class="bold"><strong>dup_compare_fcn</strong></span> function must return an |
| 135 |
integer value less than, equal to, or greater than zero if the first data item |
| 136 |
parameter is considered to be respectively less than, equal to, or greater than |
| 137 |
the second data item parameter. In addition, the comparison function must cause |
| 138 |
the data items in the set to be <span class="emphasis"><em>well-ordered</em></span>. The |
| 139 |
comparison function must correctly handle any data item values used by the |
| 140 |
application (possibly including zero-length data items). The |
| 141 |
<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 the <span class="bold"><strong>data</strong></span> field |
| 145 |
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="idp1764696"></a>Errors</h3> |
| 154 |
</div> |
| 155 |
</div> |
| 156 |
</div> |
| 157 |
<p> |
| 158 |
The <code class="methodname">Db::set_dup_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="idm367568"></a>EINVAL</h4> |
| 172 |
</div> |
| 173 |
</div> |
| 174 |
</div> |
| 175 |
<p> |
| 176 |
An invalid flag value or parameter was specified. |
| 177 |
</p> |
| 178 |
</div> |
| 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="idm1267864"></a>Class</h3> |
| 185 |
</div> |
| 186 |
</div> |
| 187 |
</div> |
| 188 |
<p> |
| 189 |
<a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> |
| 190 |
</p> |
| 191 |
</div> |
| 192 |
<div class="sect2" lang="en" xml:lang="en"> |
| 193 |
<div class="titlepage"> |
| 194 |
<div> |
| 195 |
<div> |
| 196 |
<h3 class="title"><a id="idm993464"></a>See Also</h3> |
| 197 |
</div> |
| 198 |
</div> |
| 199 |
</div> |
| 200 |
<p> |
| 201 |
<a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> |
| 202 |
</p> |
| 203 |
</div> |
| 204 |
</div> |
| 205 |
<div class="navfooter"> |
| 206 |
<hr /> |
| 207 |
<table width="100%" summary="Navigation footer"> |
| 208 |
<tr> |
| 209 |
<td width="40%" align="left"><a accesskey="p" href="dbset_create_dir.html">Prev</a> </td> |
| 210 |
<td width="20%" align="center"> |
| 211 |
<a accesskey="u" href="db.html">Up</a> |
| 212 |
</td> |
| 213 |
<td width="40%" align="right"> <a accesskey="n" href="dbset_encrypt.html">Next</a></td> |
| 214 |
</tr> |
| 215 |
<tr> |
| 216 |
<td width="40%" align="left" valign="top">Db::set_create_dir() </td> |
| 217 |
<td width="20%" align="center"> |
| 218 |
<a accesskey="h" href="index.html">Home</a> |
| 219 |
</td> |
| 220 |
<td width="40%" align="right" valign="top"> Db::set_encrypt()</td> |
| 221 |
</tr> |
| 222 |
</table> |
| 223 |
</div> |
| 224 |
</body> |
| 225 |
</html> |