| 1 |
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 6 |
<title>database open/close</title> |
| 7 |
<link rel="stylesheet" href="gettingStarted.css" type="text/css" /> |
| 8 |
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> |
| 9 |
<link rel="start" href="index.html" title="Berkeley DB Upgrade Guide" /> |
| 10 |
<link rel="up" href="upgrade_3_0_toc.html" title="Chapter 14. Upgrading Berkeley DB 2.X applications to Berkeley DB 3.0" /> |
| 11 |
<link rel="prev" href="upgrade_3_0_dbenv.html" title="DB_ENV structure" /> |
| 12 |
<link rel="next" href="upgrade_3_0_xa.html" title="db_xa_open" /> |
| 13 |
</head> |
| 14 |
<body> |
| 15 |
<div xmlns="" class="navheader"> |
| 16 |
<div class="libver"> |
| 17 |
<p>Library Version 11.2.5.3</p> |
| 18 |
</div> |
| 19 |
<table width="100%" summary="Navigation header"> |
| 20 |
<tr> |
| 21 |
<th colspan="3" align="center">database open/close</th> |
| 22 |
</tr> |
| 23 |
<tr> |
| 24 |
<td width="20%" align="left"><a accesskey="p" href="upgrade_3_0_dbenv.html">Prev</a> </td> |
| 25 |
<th width="60%" align="center">Chapter 14. Upgrading Berkeley DB 2.X applications to Berkeley DB 3.0</th> |
| 26 |
<td width="20%" align="right"> <a accesskey="n" href="upgrade_3_0_xa.html">Next</a></td> |
| 27 |
</tr> |
| 28 |
</table> |
| 29 |
<hr /> |
| 30 |
</div> |
| 31 |
<div class="sect1" lang="en" xml:lang="en"> |
| 32 |
<div class="titlepage"> |
| 33 |
<div> |
| 34 |
<div> |
| 35 |
<h2 class="title" style="clear: both"><a id="upgrade_3_0_open"></a>database open/close</h2> |
| 36 |
</div> |
| 37 |
</div> |
| 38 |
</div> |
| 39 |
<p>Database opens were changed in the Berkeley DB 3.0 release in a similar way to |
| 40 |
environment opens.</p> |
| 41 |
<p>To upgrade your application, first find each place your application opens |
| 42 |
a database, that is, calls the db_open function. Each of these calls |
| 43 |
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->open()</a>.</p> |
| 44 |
<p>Here's an example creating a Berkeley DB database using the 2.X interface:</p> |
| 45 |
<pre class="programlisting">DB *dbp; |
| 46 |
DB_ENV *dbenv; |
| 47 |
int ret; |
| 48 |
|
| 49 |
if ((ret = db_open(DATABASE, |
| 50 |
DB_BTREE, DB_CREATE, 0664, dbenv, NULL, &dbp)) != 0) |
| 51 |
return (ret);</pre> |
| 52 |
<p>In the Berkeley DB 3.0 release, this code would be written as:</p> |
| 53 |
<pre class="programlisting">DB *dbp; |
| 54 |
DB_ENV *dbenv; |
| 55 |
int ret; |
| 56 |
|
| 57 |
if ((ret = db_create(&dbp, dbenv, 0)) != 0) |
| 58 |
return (ret); |
| 59 |
|
| 60 |
if ((ret = dbp->open(dbp, |
| 61 |
DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) { |
| 62 |
(void)dbp->close(dbp, 0); |
| 63 |
return (ret); |
| 64 |
}</pre> |
| 65 |
<p>As you can see, the arguments to db_open and to <a href="../api_reference/C/dbopen.html" class="olink">DB->open()</a> are |
| 66 |
largely the same. There is some re-organization, and note that the |
| 67 |
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 |
| 68 |
is created using the <a href="../api_reference/C/dbcreate.html" class="olink">db_create()</a> function. There is one |
| 69 |
additional argument to <a href="../api_reference/C/dbopen.html" class="olink">DB->open()</a>, argument #3. For backward |
| 70 |
compatibility with the 2.X Berkeley DB releases, simply set that argument to |
| 71 |
NULL.</p> |
| 72 |
<p>There are two additional issues with the db_open call.</p> |
| 73 |
<p>First, it was possible in the 2.X releases for an application to provide |
| 74 |
an environment that did not contain a shared memory buffer pool as the |
| 75 |
database environment, and Berkeley DB would create a private one automatically. |
| 76 |
This functionality is no longer available, applications must specify the |
| 77 |
<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 |
| 78 |
environment.</p> |
| 79 |
<p>The final issue with upgrading the db_open call is that the DB_INFO |
| 80 |
structure is no longer used, having been replaced by individual methods |
| 81 |
on the <a href="../api_reference/C/db.html" class="olink">DB</a> handle. That change is discussed in detail later in |
| 82 |
this chapter.</p> |
| 83 |
</div> |
| 84 |
<div class="navfooter"> |
| 85 |
<hr /> |
| 86 |
<table width="100%" summary="Navigation footer"> |
| 87 |
<tr> |
| 88 |
<td width="40%" align="left"><a accesskey="p" href="upgrade_3_0_dbenv.html">Prev</a> </td> |
| 89 |
<td width="20%" align="center"> |
| 90 |
<a accesskey="u" href="upgrade_3_0_toc.html">Up</a> |
| 91 |
</td> |
| 92 |
<td width="40%" align="right"> <a accesskey="n" href="upgrade_3_0_xa.html">Next</a></td> |
| 93 |
</tr> |
| 94 |
<tr> |
| 95 |
<td width="40%" align="left" valign="top">DB_ENV structure </td> |
| 96 |
<td width="20%" align="center"> |
| 97 |
<a accesskey="h" href="index.html">Home</a> |
| 98 |
</td> |
| 99 |
<td width="40%" align="right" valign="top"> db_xa_open</td> |
| 100 |
</tr> |
| 101 |
</table> |
| 102 |
</div> |
| 103 |
</body> |
| 104 |
</html> |