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