1<!--$Id: db_set_dup_compare.so,v 10.50 2004/08/13 03:38:56 bostic Exp $-->
2<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
3<!--See the file LICENSE for redistribution information.-->
4<html>
5<head>
6<title>Berkeley DB: DB-&gt;set_dup_compare</title>
7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
9</head>
10<body bgcolor=white>
11<table width="100%"><tr valign=top>
12<td>
13<b>DB-&gt;set_dup_compare</b>
14</td>
15<td align=right>
16<a href="/api_c/api_core.html"><img src="/images/api.gif" alt="API"></a>
17<a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a></td>
18</tr></table>
19<hr size=1 noshade>
20<tt>
21<b><pre>
22#include &lt;db.h&gt;
23<p>
24int
25DB-&gt;set_dup_compare(DB *db,
26    int (*dup_compare_fcn)(DB *, const DBT *, const DBT *));
27</pre></b>
28<hr size=1 noshade>
29<b>Description: DB-&gt;set_dup_compare</b>
30<p>Set the duplicate data item comparison function.  The comparison
31function is called whenever it is necessary to compare a data item
32specified by the application with a data item currently stored in the
33database.  Calling DB-&gt;set_dup_compare implies calling
34<a href="/api_c/db_set_flags.html">DB-&gt;set_flags</a> with the <a href="/api_c/db_set_flags.html#DB_DUPSORT">DB_DUPSORT</a> flag.</p>
35<p>If no comparison function is specified, the data items are compared
36lexically, with shorter data items collating before longer data items.</p>
37<p>The DB-&gt;set_dup_compare method may not be called after the <a href="/api_c/db_open.html">DB-&gt;open</a> method is called.
38If the database already exists when
39<a href="/api_c/db_open.html">DB-&gt;open</a> is called, the information specified to DB-&gt;set_dup_compare must
40be the same as that historically used to create the database or
41corruption can occur.</p>
42<p>The DB-&gt;set_dup_compare method
43returns a non-zero error value on failure
44and 0 on success.
45</p>
46<b>Parameters</b> <br>
47 <b>dup_compare_fcn</b><ul compact><li>The <b>dup_compare_fcn</b> function is the application-specified
48duplicate data item comparison function.  The function takes three
49arguments:
50<br>
51<b><b>db</b></b><ul compact><li>The <b>db</b> parameter is the enclosing database handle.</ul>
52<b><b>dbt1</b></b><ul compact><li>The <b>dbt1</b> parameter is a <a href="/api_c/dbt_class.html">DBT</a> representing the application
53supplied data item.</ul>
54<b><b>dbt2</b></b><ul compact><li>The <b>dbt2</b> parameter is a <a href="/api_c/dbt_class.html">DBT</a> representing the current
55tree's data item.</ul>
56<br>
57<p>The <b>dup_compare_fcn</b> function must return an integer value less
58than, equal to, or greater than zero if the first data item parameter
59is considered to be respectively less than, equal to, or greater than
60the second data item parameter.  In addition, the comparison function
61must cause the data items in the set to be <i>well-ordered</i>.  The
62comparison function must correctly handle any data item values used by
63the application (possibly including zero-length data items).  The
64<b>data</b> and <b>size</b> fields of the <a href="/api_c/dbt_class.html">DBT</a> are the only
65fields that may be used for the purposes of this comparison, and no
66particular alignment of the memory to which the <b>data</b> field
67refers may be assumed.</p></ul>
68<br>
69<br><b>Errors</b>
70<p>The DB-&gt;set_dup_compare method
71may fail and return one of the following non-zero errors:</p>
72<br>
73<b>EINVAL</b><ul compact><li>An
74invalid flag value or parameter was specified.</ul>
75<br>
76<hr size=1 noshade>
77<br><b>Class</b>
78<a href="/api_c/db_class.html">DB</a>
79<br><b>See Also</b>
80<a href="/api_c/db_list.html">Databases and Related Methods</a>
81</tt>
82<table width="100%"><tr><td><br></td><td align=right>
83<a href="/api_c/api_core.html"><img src="/images/api.gif" alt="API"></a><a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a>
84</td></tr></table>
85<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
86</body>
87</html>
88