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 3.1: DB->put</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_3_1_toc.html" title="Chapter��34.��Upgrading Berkeley DB 3.0 applications to Berkeley DB 3.1" /> 11 <link rel="prev" href="upgrade_3_1_set_paniccall.html" title="Release 3.1: DB_ENV->set_paniccall, DB->set_paniccall" /> 12 <link rel="next" href="upgrade_3_1_dup.html" title="Release 3.1: identical duplicate data items" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Release 3.1: DB->put</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="upgrade_3_1_set_paniccall.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��34.��Upgrading Berkeley DB 3.0 applications to Berkeley DB 3.1</th> 23 <td width="20%" align="right">��<a accesskey="n" href="upgrade_3_1_dup.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_3_1_put"></a>Release 3.1: DB->put</h2> 33 </div> 34 </div> 35 </div> 36 <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 37is specified to the <a href="../api_reference/C/dbput.html" class="olink">DB->put()</a> method, the allocated record number is 38returned 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 39previous releases of Berkeley DB, this <a href="../api_reference/C/dbt.html" class="olink">DBT</a> structure did not follow 40the usual <a href="../api_reference/C/dbt.html" class="olink">DBT</a> conventions. For example, it was not possible to 41cause Berkeley DB to allocate space for the returned record number. Rather, 42it was always assumed that the <span class="bold"><strong>data</strong></span> field of the <span class="bold"><strong>key</strong></span> 43structure referred to memory that could be used as storage for a 44db_recno_t type.</p> 45 <p>As of the Berkeley DB 3.1.0 release, the <span class="bold"><strong>key</strong></span> structure behaves as 46described in the <a href="../api_reference/C/dbt.html" class="olink">DBT</a> C++/Java class or C structure documentation.</p> 47 <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 48Recno access method databases will require a change to upgrade to the 49Berkeley DB 3.1 releases. The simplest change is likely to be to add the 50<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, 51code that appears as follows:</p> 52 <pre class="programlisting">DBT key; 53db_recno_t recno; 54 55memset(&key, 0, sizeof(DBT)); 56key.data = &recno; 57key.size = sizeof(recno); 58DB->put(DB, NULL, &key, &data, DB_APPEND); 59printf("new record number is %lu\n", (u_long)recno);</pre> 60 <p>would be changed to:</p> 61 <pre class="programlisting">DBT key; 62db_recno_t recno; 63 64memset(&key, 0, sizeof(DBT)); 65key.data = &recno; 66key.ulen = sizeof(recno); 67key.flags = DB_DBT_USERMEM; 68DB->put(DB, NULL, &key, &data, DB_APPEND); 69printf("new record number is %lu\n", (u_long)recno);</pre> 70 <p>Note that the <span class="bold"><strong>ulen</strong></span> field is now set as well as the flag value. 71An alternative change would be:</p> 72 <pre class="programlisting">DBT key; 73db_recno_t recno; 74 75memset(&key, 0, sizeof(DBT)); 76DB->put(DB, NULL, &key, &data, DB_APPEND); 77recno = *(db_recno_t *)key->data; 78printf("new record number is %lu\n", (u_long)recno);</pre> 79 </div> 80 <div class="navfooter"> 81 <hr /> 82 <table width="100%" summary="Navigation footer"> 83 <tr> 84 <td width="40%" align="left"><a accesskey="p" href="upgrade_3_1_set_paniccall.html">Prev</a>��</td> 85 <td width="20%" align="center"> 86 <a accesskey="u" href="upgrade_3_1_toc.html">Up</a> 87 </td> 88 <td width="40%" align="right">��<a accesskey="n" href="upgrade_3_1_dup.html">Next</a></td> 89 </tr> 90 <tr> 91 <td width="40%" align="left" valign="top">Release 3.1: DB_ENV->set_paniccall, DB->set_paniccall��</td> 92 <td width="20%" align="center"> 93 <a accesskey="h" href="index.html">Home</a> 94 </td> 95 <td width="40%" align="right" valign="top">��Release 3.1: identical duplicate data items</td> 96 </tr> 97 </table> 98 </div> 99 </body> 100</html> 101