put.html   [plain text]


<!--$Id: put.so,v 1.11 2003/10/18 19:16:15 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Release 3.1: DB-&gt;put</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<table width="100%"><tr valign=top>
<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Upgrading Berkeley DB Applications</dl></b></td>
<td align=right><a href="../upgrade.3.1/set_paniccall.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../upgrade.3.1/dup.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p align=center><b>Release 3.1: DB-&gt;put</b></p>
<p>For the Queue and Recno access methods, when the <a href="../../api_c/db_put.html#DB_APPEND">DB_APPEND</a> flag
is specified to the <a href="../../api_c/db_put.html">DB-&gt;put</a> method, the allocated record number is
returned to the application in the <b>key</b> <a href="../../api_c/dbt_class.html">DBT</a> argument.  In
previous releases of Berkeley DB, this <a href="../../api_c/dbt_class.html">DBT</a> structure did not follow
the usual <a href="../../api_c/dbt_class.html">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 <b>data</b> field of the <b>key</b>
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 <b>key</b> structure behaves as
described in the <a href="../../api_c/dbt_class.html">DBT</a> C++/Java class or C structure documentation.</p>
<p>Applications which are using the <a href="../../api_c/db_put.html#DB_APPEND">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_c/dbt_class.html#DB_DBT_USERMEM">DB_DBT_USERMEM</a> flag to the <b>key</b> structure.  For example,
code that appears as follows:</p>
<blockquote><pre>DBT key;
db_recno_t recno;
<p>
memset(&key, 0, sizeof(DBT));
key.data = &recno;
key.size = sizeof(recno);
DB-&gt;put(DB, NULL, &key, &data, DB_APPEND);
printf("new record number is %lu\n", (u_long)recno);</pre></blockquote>
<p>would be changed to:</p>
<blockquote><pre>DBT key;
db_recno_t recno;
<p>
memset(&key, 0, sizeof(DBT));
key.data = &recno;
key.ulen = sizeof(recno);
key.flags = DB_DBT_USERMEM;
DB-&gt;put(DB, NULL, &key, &data, DB_APPEND);
printf("new record number is %lu\n", (u_long)recno);</pre></blockquote>
<p>Note that the <b>ulen</b> field is now set as well as the flag value.
An alternative change would be:</p>
<blockquote><pre>DBT key;
db_recno_t recno;
<p>
memset(&key, 0, sizeof(DBT));
DB-&gt;put(DB, NULL, &key, &data, DB_APPEND);
recno = *(db_recno_t *)key-&gt;data;
printf("new record number is %lu\n", (u_long)recno);</pre></blockquote>
<table width="100%"><tr><td><br></td><td align=right><a href="../upgrade.3.1/set_paniccall.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../upgrade.3.1/dup.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</body>
</html>