1<!--$Id: open.so,v 11.11 2003/10/18 19:16:14 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 Reference Guide: Release 3.0: database open/close</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><b><dl><dt>Berkeley DB Reference Guide:<dd>Upgrading Berkeley DB Applications</dl></b></td>
13<td align=right><a href="/upgrade.3.0/dbenv.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/upgrade.3.0/xa.html"><img src="/images/next.gif" alt="Next"></a>
14</td></tr></table>
15<p align=center><b>Release 3.0: database open/close</b></p>
16<p>Database opens were changed in the Berkeley DB 3.0 release in a similar way to
17environment opens.</p>
18<p>To upgrade your application, first find each place your application opens
19a database, that is, calls the db_open function.  Each of these calls
20should be replaced with calls to <a href="/api_c/db_class.html">db_create</a> and <a href="/api_c/db_open.html">DB-&gt;open</a>.</p>
21<p>Here's an example creating a Berkeley DB database using the 2.X interface:</p>
22<blockquote><pre>DB *dbp;
23DB_ENV *dbenv;
24int ret;
25<p>
26if ((ret = db_open(DATABASE,
27    DB_BTREE, DB_CREATE, 0664, dbenv, NULL, &dbp)) != 0)
28	return (ret);</pre></blockquote>
29<p>In the Berkeley DB 3.0 release, this code would be written as:</p>
30<blockquote><pre>DB *dbp;
31DB_ENV *dbenv;
32int ret;
33<p>
34if ((ret = db_create(&dbp, dbenv, 0)) != 0)
35	return (ret);
36<p>
37if ((ret = dbp-&gt;open(dbp,
38    DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
39	(void)dbp-&gt;close(dbp, 0);
40	return (ret);
41}</pre></blockquote>
42<p>As you can see, the arguments to db_open and to <a href="/api_c/db_open.html">DB-&gt;open</a> are
43largely the same.  There is some re-organization, and note that the
44enclosing <a href="/api_c/env_class.html">DB_ENV</a> structure is specified when the <a href="/api_c/db_class.html">DB</a> object
45is created using the <a href="/api_c/db_class.html">db_create</a> function.  There is one
46additional argument to <a href="/api_c/db_open.html">DB-&gt;open</a>, argument #3.  For backward
47compatibility with the 2.X Berkeley DB releases, simply set that argument to
48NULL.</p>
49<p>There are two additional issues with the db_open call.</p>
50<p>First, it was possible in the 2.X releases for an application to provide
51an environment that did not contain a shared memory buffer pool as the
52database environment, and Berkeley DB would create a private one automatically.
53This functionality is no longer available, applications must specify the
54<a href="/api_c/env_open.html#DB_INIT_MPOOL">DB_INIT_MPOOL</a> flag if databases are going to be opened in the
55environment.</p>
56<p>The final issue with upgrading the db_open call is that the DB_INFO
57structure is no longer used, having been replaced by individual methods
58on the <a href="/api_c/db_class.html">DB</a> handle.  That change is discussed in detail later in
59this chapter.</p>
60<table width="100%"><tr><td><br></td><td align=right><a href="/upgrade.3.0/dbenv.html"><img src="/images/prev.gif" alt="Prev"></a><a href="/toc.html"><img src="/images/ref.gif" alt="Ref"></a><a href="/upgrade.3.0/xa.html"><img src="/images/next.gif" alt="Next"></a>
61</td></tr></table>
62<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
63</body>
64</html>
65