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