1<!--$Id: db_set_bt_prefix.so,v 10.48 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::set_bt_prefix</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_bt_prefix</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 &lt;db_cxx.h&gt;
23<p>
24extern "C" {
25    typedef size_t (*bt_prefix_fcn_type)(DB *, const DBT *, const DBT *);
26};
27int
28Db::set_bt_prefix(bt_prefix_fcn_type bt_prefix_fcn);
29</pre></b>
30<hr size=1 noshade>
31<b>Description: Db::set_bt_prefix</b>
32<p>Set the Btree prefix function.  The prefix function is used to determine
33the amount by which keys stored on the Btree internal pages can be
34safely truncated without losing their uniqueness.  See the
35<a href="../ref/am_conf/bt_prefix.html">Btree prefix comparison</a> section
36of the Berkeley DB Reference Guide for more details about how this works.  The
37usefulness of this is data-dependent, but can produce significantly
38reduced tree sizes and search times in some data sets.</p>
39<p>If no prefix function or key comparison function is specified by the
40application, a default lexical comparison function is used as the prefix
41function.  If no prefix function is specified and a key comparison
42function is specified, no prefix function is used.  It is an error to
43specify a prefix function without also specifying a Btree key comparison
44function.</p>
45<p>The Db::set_bt_prefix method configures operations performed using the specified
46<a href="../api_cxx/db_class.html">Db</a> handle, not all operations performed on the underlying
47database.</p>
48<p>The Db::set_bt_prefix method may not be called after the <a href="../api_cxx/db_open.html">Db::open</a> method is called.
49If the database already exists when
50<a href="../api_cxx/db_open.html">Db::open</a> is called, the information specified to Db::set_bt_prefix must
51be the same as that historically used to create the database or
52corruption can occur.</p>
53<p>The Db::set_bt_prefix method
54either returns a non-zero error value
55or throws an exception that encapsulates a non-zero error value on
56failure, and returns 0 on success.
57</p>
58<b>Parameters</b> <br>
59 <b>bt_prefix_fcn</b><ul compact><li>The <b>bt_prefix_fcn</b> function is the application-specific Btree
60prefix function.  The prefix function takes three parameters:
61<br>
62<b><b>db</b></b><ul compact><li>The <b>db</b> parameter is the enclosing database handle.</ul>
63<b><b>dbt1</b></b><ul compact><li>The <b>dbt1</b> parameter is a <a href="../api_cxx/dbt_class.html">Dbt</a> representing a database key.</ul>
64<b><b>dbt2</b></b><ul compact><li>The <b>dbt2</b> parameter is a <a href="../api_cxx/dbt_class.html">Dbt</a> representing a database key.</ul>
65<br>
66<p>The <b>bt_prefix_fcn</b> function must return the number of bytes of
67the second key parameter that would be required by the Btree key
68comparison function to determine the second key parameter's ordering
69relationship with respect to the first key parameter.  If the two keys
70are equal, the key length should be returned.  The prefix function must
71correctly handle any key values used by the application (possibly
72including zero-length keys).  The <b>data</b> and <b>size</b> fields
73of the <a href="../api_cxx/dbt_class.html">Dbt</a> are the only fields that may be used for the purposes
74of this determination, and no particular alignment of the memory to
75which the <b>data</b> field refers may be assumed.</p></ul>
76<br>
77<br><b>Errors</b>
78<p>The Db::set_bt_prefix method
79may fail and throw
80<a href="../api_cxx/except_class.html">DbException</a>,
81encapsulating one of the following non-zero errors, or return one of
82the following non-zero errors:</p>
83<br>
84<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
85invalid flag value or parameter was specified.</ul>
86<br>
87<hr size=1 noshade>
88<br><b>Class</b>
89<a href="../api_cxx/db_class.html">Db</a>
90<br><b>See Also</b>
91<a href="../api_cxx/db_list.html">Databases and Related Methods</a>
92</tt>
93<table width="100%"><tr><td><br></td><td align=right>
94<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>
95</td></tr></table>
96<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
97</body>
98</html>
99