| 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>Converting Applications</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_2_0_toc.html" title="Chapter 15. Upgrading Berkeley DB 1.85 or 1.86 applications to Berkeley DB 2.0" /> |
| 11 |
<link rel="prev" href="upgrade_2_0_system.html" title="System Integration" /> |
| 12 |
<link rel="next" href="upgrade_2_0_disk.html" title="Upgrade Requirements" /> |
| 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">Converting Applications</th> |
| 22 |
</tr> |
| 23 |
<tr> |
| 24 |
<td width="20%" align="left"><a accesskey="p" href="upgrade_2_0_system.html">Prev</a> </td> |
| 25 |
<th width="60%" align="center">Chapter 15. Upgrading Berkeley DB 1.85 or 1.86 applications to Berkeley DB 2.0</th> |
| 26 |
<td width="20%" align="right"> <a accesskey="n" href="upgrade_2_0_disk.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_2_0_convert"></a>Converting Applications</h2> |
| 36 |
</div> |
| 37 |
</div> |
| 38 |
</div> |
| 39 |
<p>Mapping the Berkeley DB 1.85 functionality into Berkeley DB version 2 is almost always |
| 40 |
simple. The manual page <a href="../api_reference/C/dbopen.html" class="olink">DB->open()</a> replaces the Berkeley DB 1.85 manual |
| 41 |
pages <code class="literal">dbopen</code>(3), <code class="literal">btree</code>(3), <code class="literal">hash</code>(3) and |
| 42 |
<code class="literal">recno</code>(3). You should be able to convert each 1.85 function |
| 43 |
call into a Berkeley DB version 2 function call using just the <a href="../api_reference/C/dbopen.html" class="olink">DB->open()</a> |
| 44 |
documentation.</p> |
| 45 |
<p>Some guidelines and things to watch out for:</p> |
| 46 |
<div class="orderedlist"> |
| 47 |
<ol type="1"> |
| 48 |
<li>Most access method functions have exactly the same semantics as in Berkeley DB |
| 49 |
1.85, although the arguments to the functions have changed in some cases. |
| 50 |
To get your code to compile, the most common change is to add the |
| 51 |
transaction ID as an argument (NULL, since Berkeley DB 1.85 did not support |
| 52 |
transactions.)</li> |
| 53 |
<li>You must always initialize DBT structures to zero before using them with |
| 54 |
any Berkeley DB version 2 function. (They do not normally have to be |
| 55 |
reinitialized each time, only when they are first allocated. Do this by |
| 56 |
declaring the DBT structure external or static, or by calling the C |
| 57 |
library routine <code class="literal">bzero</code>(3) or <code class="literal">memset</code>(3).)</li> |
| 58 |
<li>The error returns are completely different in the two versions. In Berkeley DB |
| 59 |
1.85, < 0 meant an error, and > 0 meant a minor Berkeley DB exception. |
| 60 |
In Berkeley DB 2.0, > 0 means an error (the Berkeley DB version 2 functions |
| 61 |
return <code class="literal">errno</code> on error) and < 0 means a Berkeley DB exception. |
| 62 |
See <a href="../programmer_reference/program_errorret.html" class="olink">Program returns to applications</a> for more information.</li> |
| 63 |
<li>The Berkeley DB 1.85 DB->seq function has been replaced by cursors in Berkeley DB |
| 64 |
version 2. The semantics are approximately the same, but cursors require |
| 65 |
the creation of an extra object (the DBC object), which is then used to |
| 66 |
access the database. |
| 67 |
<p>Specifically, the partial key match and range search functionality of the |
| 68 |
R_CURSOR flag in DB->seq has been replaced by the <a href="../api_reference/C/dbcget.html#dbcget_DB_SET_RANGE" class="olink">DB_SET_RANGE</a> flag in |
| 69 |
<a href="../api_reference/C/dbcget.html" class="olink">DBC->get()</a>.</p></li> |
| 70 |
<li>In version 2 of the Berkeley DB library, additions or deletions into Recno |
| 71 |
(fixed and variable-length record) databases no longer automatically |
| 72 |
logically renumber all records after the add/delete point, by default. |
| 73 |
The default behavior is that deleting records does not cause subsequent |
| 74 |
records to be renumbered, and it is an error to attempt to add new records |
| 75 |
between records already in the database. Applications wanting the |
| 76 |
historic Recno access method semantics should call the |
| 77 |
<a href="../api_reference/C/dbset_flags.html" class="olink">DB->set_flags()</a> method with the <a href="../api_reference/C/dbset_flags.html#dbset_flags_DB_RENUMBER" class="olink">DB_RENUMBER</a> flag.</li> |
| 78 |
<li>Opening a database in Berkeley DB version 2 is a much heavier-weight operation |
| 79 |
than it was in Berkeley DB 1.85. Therefore, if your historic applications were |
| 80 |
written to open a database, perform a single operation, and close the |
| 81 |
database, you may observe performance degradation. In most cases, this |
| 82 |
is due to the expense of creating the environment upon each open. While |
| 83 |
we encourage restructuring your application to avoid repeated opens and |
| 84 |
closes, you can probably recover most of the lost performance by simply |
| 85 |
using a persistent environment across invocations.</li> |
| 86 |
</ol> |
| 87 |
</div> |
| 88 |
<p>While simply converting Berkeley DB 1.85 function calls to Berkeley DB version 2 |
| 89 |
function calls will work, we recommend that you eventually reconsider your |
| 90 |
application's interface to the Berkeley DB database library in light of the |
| 91 |
additional functionality supplied by Berkeley DB version 2, as it is likely to |
| 92 |
result in enhanced application performance.</p> |
| 93 |
</div> |
| 94 |
<div class="navfooter"> |
| 95 |
<hr /> |
| 96 |
<table width="100%" summary="Navigation footer"> |
| 97 |
<tr> |
| 98 |
<td width="40%" align="left"><a accesskey="p" href="upgrade_2_0_system.html">Prev</a> </td> |
| 99 |
<td width="20%" align="center"> |
| 100 |
<a accesskey="u" href="upgrade_2_0_toc.html">Up</a> |
| 101 |
</td> |
| 102 |
<td width="40%" align="right"> <a accesskey="n" href="upgrade_2_0_disk.html">Next</a></td> |
| 103 |
</tr> |
| 104 |
<tr> |
| 105 |
<td width="40%" align="left" valign="top">System Integration </td> |
| 106 |
<td width="20%" align="center"> |
| 107 |
<a accesskey="h" href="index.html">Home</a> |
| 108 |
</td> |
| 109 |
<td width="40%" align="right" valign="top"> Upgrade Requirements</td> |
| 110 |
</tr> |
| 111 |
</table> |
| 112 |
</div> |
| 113 |
</body> |
| 114 |
</html> |