summaryrefslogtreecommitdiff
path: root/docs/upgrading/upgrade_3_1_put.html
blob: 41dc322f5e18c7d2a8e525834f34ce019f762792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?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>DB-&gt;put</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_1_toc.html" title="Chapter 13. Upgrading Berkeley DB 3.0 applications to Berkeley DB 3.1" />
    <link rel="prev" href="upgrade_3_1_set_paniccall.html" title="DB_ENV-&gt;set_paniccall, DB-&gt;set_paniccall" />
    <link rel="next" href="upgrade_3_1_dup.html" title="identical duplicate data items" />
  </head>
  <body>
    <div xmlns="" class="navheader">
      <div class="libver">
        <p>Library Version 12.1.6.1</p>
      </div>
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">DB-&gt;put</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="upgrade_3_1_set_paniccall.html">Prev</a> </td>
          <th width="60%" align="center">Chapter 13. Upgrading Berkeley DB 3.0 applications to Berkeley DB 3.1</th>
          <td width="20%" align="right"> <a accesskey="n" href="upgrade_3_1_dup.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_1_put"></a>DB-&gt;put</h2>
          </div>
        </div>
      </div>
      <p>For the Queue and Recno access methods, when the <a href="../api_reference/C/dbput.html#dbput_DB_APPEND" class="olink">DB_APPEND</a> flag
is specified to the <a href="../api_reference/C/dbput.html" class="olink">DB-&gt;put()</a> method, the allocated record number is
returned to the application in the <span class="bold"><strong>key</strong></span> <a href="../api_reference/C/dbt.html" class="olink">DBT</a> argument.  In
previous releases of Berkeley DB, this <a href="../api_reference/C/dbt.html" class="olink">DBT</a> structure did not follow
the usual <a href="../api_reference/C/dbt.html" class="olink">DBT</a> conventions.  For example, it was not possible to
cause Berkeley DB to allocate space for the returned record number.  Rather,
it was always assumed that the <span class="bold"><strong>data</strong></span> field of the <span class="bold"><strong>key</strong></span>
structure referred to memory that could be used as storage for a
db_recno_t type.</p>
      <p>As of the Berkeley DB 3.1.0 release, the <span class="bold"><strong>key</strong></span> structure behaves as
described in the <a href="../api_reference/C/dbt.html" class="olink">DBT</a> C++/Java class or C structure documentation.</p>
      <p>Applications which are using the <a href="../api_reference/C/dbput.html#dbput_DB_APPEND" class="olink">DB_APPEND</a> flag for Queue and
Recno access method databases will require a change to upgrade to the
Berkeley DB 3.1 releases.  The simplest change is likely to be to add the
<a href="../api_reference/C/dbt.html#dbt_DB_DBT_USERMEM" class="olink">DB_DBT_USERMEM</a> flag to the <span class="bold"><strong>key</strong></span> structure.  For example,
code that appears as follows:</p>
      <pre class="programlisting">DBT key;
db_recno_t recno;

memset(&amp;key, 0, sizeof(DBT));
key.data = &amp;recno;
key.size = sizeof(recno);
DB-&gt;put(DB, NULL, &amp;key, &amp;data, DB_APPEND);
printf("new record number is %lu\n", (u_long)recno);</pre>
      <p>would be changed to:</p>
      <pre class="programlisting">DBT key;
db_recno_t recno;

memset(&amp;key, 0, sizeof(DBT));
key.data = &amp;recno;
key.ulen = sizeof(recno);
key.flags = DB_DBT_USERMEM;
DB-&gt;put(DB, NULL, &amp;key, &amp;data, DB_APPEND);
printf("new record number is %lu\n", (u_long)recno);</pre>
      <p>Note that the <span class="bold"><strong>ulen</strong></span> field is now set as well as the flag value.
An alternative change would be:</p>
      <pre class="programlisting">DBT key;
db_recno_t recno;

memset(&amp;key, 0, sizeof(DBT));
DB-&gt;put(DB, NULL, &amp;key, &amp;data, DB_APPEND);
recno = *(db_recno_t *)key-&gt;data;
printf("new record number is %lu\n", (u_long)recno);</pre>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="upgrade_3_1_set_paniccall.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="upgrade_3_1_toc.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="upgrade_3_1_dup.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">DB_ENV-&gt;set_paniccall, DB-&gt;set_paniccall </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> identical duplicate data items</td>
        </tr>
      </table>
    </div>
  </body>
</html>