1<!--$Id: put.so,v 1.11 2003/10/18 19:16:15 bostic Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB Reference Guide: Release 3.1: DB->put</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<table width="100%"><tr valign=top> 12<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Upgrading Berkeley DB Applications</dl></b></td> 13<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> 14</td></tr></table> 15<p align=center><b>Release 3.1: DB->put</b></p> 16<p>For the Queue and Recno access methods, when the <a href="../../api_c/db_put.html#DB_APPEND">DB_APPEND</a> flag 17is specified to the <a href="../../api_c/db_put.html">DB->put</a> method, the allocated record number is 18returned to the application in the <b>key</b> <a href="../../api_c/dbt_class.html">DBT</a> argument. In 19previous releases of Berkeley DB, this <a href="../../api_c/dbt_class.html">DBT</a> structure did not follow 20the usual <a href="../../api_c/dbt_class.html">DBT</a> conventions. For example, it was not possible to 21cause Berkeley DB to allocate space for the returned record number. Rather, 22it was always assumed that the <b>data</b> field of the <b>key</b> 23structure referred to memory that could be used as storage for a 24db_recno_t type.</p> 25<p>As of the Berkeley DB 3.1.0 release, the <b>key</b> structure behaves as 26described in the <a href="../../api_c/dbt_class.html">DBT</a> C++/Java class or C structure documentation.</p> 27<p>Applications which are using the <a href="../../api_c/db_put.html#DB_APPEND">DB_APPEND</a> flag for Queue and 28Recno access method databases will require a change to upgrade to the 29Berkeley DB 3.1 releases. The simplest change is likely to be to add the 30<a href="../../api_c/dbt_class.html#DB_DBT_USERMEM">DB_DBT_USERMEM</a> flag to the <b>key</b> structure. For example, 31code that appears as follows:</p> 32<blockquote><pre>DBT key; 33db_recno_t recno; 34<p> 35memset(&key, 0, sizeof(DBT)); 36key.data = &recno; 37key.size = sizeof(recno); 38DB->put(DB, NULL, &key, &data, DB_APPEND); 39printf("new record number is %lu\n", (u_long)recno);</pre></blockquote> 40<p>would be changed to:</p> 41<blockquote><pre>DBT key; 42db_recno_t recno; 43<p> 44memset(&key, 0, sizeof(DBT)); 45key.data = &recno; 46key.ulen = sizeof(recno); 47key.flags = DB_DBT_USERMEM; 48DB->put(DB, NULL, &key, &data, DB_APPEND); 49printf("new record number is %lu\n", (u_long)recno);</pre></blockquote> 50<p>Note that the <b>ulen</b> field is now set as well as the flag value. 51An alternative change would be:</p> 52<blockquote><pre>DBT key; 53db_recno_t recno; 54<p> 55memset(&key, 0, sizeof(DBT)); 56DB->put(DB, NULL, &key, &data, DB_APPEND); 57recno = *(db_recno_t *)key->data; 58printf("new record number is %lu\n", (u_long)recno);</pre></blockquote> 59<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> 60</td></tr></table> 61<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 62</body> 63</html> 64