libdb/docs/upgrading/upgrade_3_0_open.html

105 lines
5 KiB
HTML
Raw Normal View History

2011-09-13 17:44:24 +00:00
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>database open/close</title>
<link rel="stylesheet" href="gettingStarted.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
<link rel="start" href="index.html" title="Berkeley DB Upgrade Guide" />
<link rel="up" href="upgrade_3_0_toc.html" title="Chapter 14. Upgrading Berkeley DB 2.X applications to Berkeley DB 3.0" />
<link rel="prev" href="upgrade_3_0_dbenv.html" title="DB_ENV structure" />
<link rel="next" href="upgrade_3_0_xa.html" title="db_xa_open" />
</head>
<body>
<div xmlns="" class="navheader">
<div class="libver">
<p>Library Version 11.2.5.2</p>
</div>
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">database open/close</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="upgrade_3_0_dbenv.html">Prev</a> </td>
<th width="60%" align="center">Chapter 14. Upgrading Berkeley DB 2.X applications to Berkeley DB 3.0</th>
<td width="20%" align="right"> <a accesskey="n" href="upgrade_3_0_xa.html">Next</a></td>
</tr>
</table>
<hr />
</div>
<div class="sect1" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="upgrade_3_0_open"></a>database open/close</h2>
</div>
</div>
</div>
<p>Database opens were changed in the Berkeley DB 3.0 release in a similar way to
environment opens.</p>
<p>To upgrade your application, first find each place your application opens
a database, that is, calls the db_open function. Each of these calls
should be replaced with calls to <a href="../api_reference/C/dbcreate.html" class="olink">db_create()</a> and <a href="../api_reference/C/dbopen.html" class="olink">DB-&gt;open()</a>.</p>
<p>Here's an example creating a Berkeley DB database using the 2.X interface:</p>
<pre class="programlisting">DB *dbp;
DB_ENV *dbenv;
int ret;
if ((ret = db_open(DATABASE,
DB_BTREE, DB_CREATE, 0664, dbenv, NULL, &amp;dbp)) != 0)
return (ret);</pre>
<p>In the Berkeley DB 3.0 release, this code would be written as:</p>
<pre class="programlisting">DB *dbp;
DB_ENV *dbenv;
int ret;
if ((ret = db_create(&amp;dbp, dbenv, 0)) != 0)
return (ret);
if ((ret = dbp-&gt;open(dbp,
DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
(void)dbp-&gt;close(dbp, 0);
return (ret);
}</pre>
<p>As you can see, the arguments to db_open and to <a href="../api_reference/C/dbopen.html" class="olink">DB-&gt;open()</a> are
largely the same. There is some re-organization, and note that the
enclosing <a href="../api_reference/C/env.html" class="olink">DB_ENV</a> structure is specified when the <a href="../api_reference/C/db.html" class="olink">DB</a> object
is created using the <a href="../api_reference/C/dbcreate.html" class="olink">db_create()</a> function. There is one
additional argument to <a href="../api_reference/C/dbopen.html" class="olink">DB-&gt;open()</a>, argument #3. For backward
compatibility with the 2.X Berkeley DB releases, simply set that argument to
NULL.</p>
<p>There are two additional issues with the db_open call.</p>
<p>First, it was possible in the 2.X releases for an application to provide
an environment that did not contain a shared memory buffer pool as the
database environment, and Berkeley DB would create a private one automatically.
This functionality is no longer available, applications must specify the
<a href="../api_reference/C/envopen.html#envopen_DB_INIT_MPOOL" class="olink">DB_INIT_MPOOL</a> flag if databases are going to be opened in the
environment.</p>
<p>The final issue with upgrading the db_open call is that the DB_INFO
structure is no longer used, having been replaced by individual methods
on the <a href="../api_reference/C/db.html" class="olink">DB</a> handle. That change is discussed in detail later in
this chapter.</p>
</div>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="upgrade_3_0_dbenv.html">Prev</a> </td>
<td width="20%" align="center">
<a accesskey="u" href="upgrade_3_0_toc.html">Up</a>
</td>
<td width="40%" align="right"> <a accesskey="n" href="upgrade_3_0_xa.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">DB_ENV structure </td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top"> db_xa_open</td>
</tr>
</table>
</div>
</body>
</html>