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
|
<!--$Id: put.html,v 1.1.1.1 2003/11/20 22:14:22 toshok Exp $-->
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
<!--All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Release 3.1: DB->put</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,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><h3><dl><dt>Berkeley DB Reference Guide:<dd>Upgrading Berkeley DB Applications</dl></h3></td>
<td align=right><a href="../../ref/upgrade.3.1/set_paniccall.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/upgrade.3.1/dup.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p>
<h1 align=center>Release 3.1: DB->put</h1>
<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->put</a> interface, 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>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>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->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->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->put(DB, NULL, &key, &data, DB_APPEND);
recno = *(db_recno_t *)key->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="../../ref/upgrade.3.1/set_paniccall.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/upgrade.3.1/dup.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>
</body>
</html>
|