1<!--$Id: db_set_h_compare.so,v 1.1 2006/10/27 00:28:44 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::set_h_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::set_h_compare</b> 14</td> 15<td align=right> 16<a href="/api_cxx/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 <db_cxx.h> 23<p> 24extern "C" { 25 typedef int (*compare_fcn_type)(DB *db, const DBT *dbt1, const DBT *dbt2); 26}; 27int 28Db::set_h_compare(compare_fcn_type compare_fcn); 29</pre></b> 30<hr size=1 noshade> 31<b>Description: Db::set_h_compare</b> 32<p>Set the Hash key comparison function. The comparison function is called 33whenever it is necessary to compare a key specified by the application 34with a key currently stored in the database.</p> 35<p>If no comparison function is specified, a byte-by-byte comparison is 36performed.</p> 37<p>The Db::set_h_compare method configures operations performed using the specified 38<a href="/api_cxx/db_class.html">Db</a> handle, not all operations performed on the underlying 39database.</p> 40<p>The Db::set_h_compare method may not be called after the <a href="/api_cxx/db_open.html">Db::open</a> method is called. 41If the database already exists when 42<a href="/api_cxx/db_open.html">Db::open</a> is called, the information specified to Db::set_h_compare must 43be the same as that historically used to create the database or 44corruption can occur.</p> 45<p>The Db::set_h_compare method 46either returns a non-zero error value 47or throws an exception that encapsulates a non-zero error value on 48failure, and returns 0 on success. 49</p> 50<b>Parameters</b> <br> 51 <b>compare_fcn</b><ul compact><li>The <b>compare_fcn</b> function is the application-specified Hash 52comparison function. The comparison function takes three parameters: 53<br> 54<b><b>db</b></b><ul compact><li>The <b>db</b> parameter is the enclosing database handle.</ul> 55<b><b>dbt1</b></b><ul compact><li>The <b>dbt1</b> parameter is the <a href="/api_cxx/dbt_class.html">Dbt</a> representing the 56application supplied key.</ul> 57<b><b>dbt2</b></b><ul compact><li>The <b>dbt2</b> parameter is the <a href="/api_cxx/dbt_class.html">Dbt</a> representing the 58current database's key.</ul> 59<br></ul> 60<p>The <b>compare_fcn</b> function must return an integer value less 61than, equal to, or greater than zero if the first key parameter is 62considered to be respectively less than, equal to, or greater than the 63second key parameter. The comparison function must correctly handle any 64key values used by the application (possibly including zero-length 65keys). The <b>data</b> and <b>size</b> fields of the <a href="/api_cxx/dbt_class.html">Dbt</a> are 66the only fields that may be used for the purposes of this comparison, 67and no particular alignment of the memory to which by the <b>data</b> 68field refers may be assumed.</p> 69<br> 70<br><b>Errors</b> 71<p>The Db::set_h_compare method 72may fail and throw 73<a href="/api_cxx/except_class.html">DbException</a>, 74encapsulating one of the following non-zero errors, or return one of 75the following non-zero errors:</p> 76<br> 77<b>EINVAL</b><ul compact><li>If the method was called after <a href="/api_cxx/db_open.html">Db::open</a> was called; or if an 78invalid flag value or parameter was specified.</ul> 79<br> 80<hr size=1 noshade> 81<br><b>Class</b> 82<a href="/api_cxx/db_class.html">Db</a> 83<br><b>See Also</b> 84<a href="/api_cxx/db_list.html">Databases and Related Methods</a> 85</tt> 86<table width="100%"><tr><td><br></td><td align=right> 87<a href="/api_cxx/api_core.html"><img src="/images/api.gif" alt="API"></a><a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a> 88</td></tr></table> 89<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 90</body> 91</html> 92