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->set_append_recno()</title> 7 <link rel="stylesheet" href="apiReference.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 C API Reference" /> 10 <link rel="up" href="db.html" title="Chapter��2.�� The DB Handle" /> 11 <link rel="prev" href="dbset_alloc.html" title="DB->set_alloc()" /> 12 <link rel="next" href="dbset_bt_compare.html" title="DB->set_bt_compare()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">DB->set_append_recno()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="dbset_alloc.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��2.�� 23 The DB Handle 24 </th> 25 <td width="20%" align="right">��<a accesskey="n" href="dbset_bt_compare.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="dbset_append_recno"></a>DB->set_append_recno()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db.h> 39 40int 41DB->set_append_recno(DB *, 42 int (*db_append_recno_fcn)(DB *dbp, DBT *data, db_recno_t recno)); </pre> 43 <p> 44 When using the <a class="link" href="dbput.html#dbput_DB_APPEND">DB_APPEND</a> 45 option of the <a class="xref" href="dbput.html" title="DB->put()">DB->put()</a> method, it may be 46 useful to modify the stored data based on the generated key. If a 47 callback function is specified using the 48 <code class="methodname">DB->set_append_recno()</code> 49 method, it will be called after the record number has been selected, 50 but before the data has been stored. 51 </p> 52 <p> 53 The <code class="methodname">DB->set_append_recno()</code> method configures operations performed 54 using the specified <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a> 55 handle, not all operations performed on the underlying database. 56 </p> 57 <p> 58 The <code class="methodname">DB->set_append_recno()</code> method may not be called after the 59 <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> method is called. 60 </p> 61 <p> 62 The <code class="methodname">DB->set_append_recno()</code> <span> 63 <span> 64 method returns a non-zero error value on failure and 0 on success. 65 </span> 66 67 </span> 68 </p> 69 <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"> 70 <h3 class="title">Note</h3> 71 <p> 72 Berkeley DB is not re-entrant. Callback functions should not attempt to make 73 library calls (for example, to release locks or close open handles). Re-entering 74 Berkeley DB is not guaranteed to work correctly, and the results are undefined. 75 </p> 76 </div> 77 <div class="sect2" lang="en" xml:lang="en"> 78 <div class="titlepage"> 79 <div> 80 <div> 81 <h3 class="title"><a id="id1642494"></a>Parameters</h3> 82 </div> 83 </div> 84 </div> 85 <div class="sect3" lang="en" xml:lang="en"> 86 <div class="titlepage"> 87 <div> 88 <div> 89 <h4 class="title"><a id="id1642450"></a>db_append_recno_fcn</h4> 90 </div> 91 </div> 92 </div> 93 <p> 94 The <span class="bold"><strong>db_append_recno_fcn</strong></span> parameter is 95 a function to call after the record number has been selected but 96 before the data has been stored into the database. The function takes 97 three parameters: 98 </p> 99 <div class="itemizedlist"> 100 <ul type="disc"> 101 <li> 102 <p> 103 <code class="literal">dbp</code> 104 </p> 105 <p> 106 The <span class="bold"><strong>dbp</strong></span> parameter is the enclosing 107 database handle. 108 </p> 109 </li> 110 <li> 111 <p> 112 <code class="literal">data</code> 113 </p> 114 <p> 115 The <span class="bold"><strong>data</strong></span> parameter is the data 116 <a class="link" href="dbt.html" title="Chapter��4.�� The DBT Handle">DBT</a> to be stored. 117 </p> 118 </li> 119 <li> 120 <p> 121 <code class="literal">recno</code> 122 </p> 123 <p> 124 The <span class="bold"><strong>recno</strong></span> parameter is the generated 125 record number. 126 </p> 127 </li> 128 </ul> 129 </div> 130 <p> 131 The called function may modify the data 132 <a class="link" href="dbt.html" title="Chapter��4.�� The DBT Handle">DBT</a>. If the function needs to allocate 133 memory for the <span class="bold"><strong>data</strong></span> field, the 134 <span class="bold"><strong>flags</strong></span> field of 135 the returned <a class="link" href="dbt.html" title="Chapter��4.�� The DBT Handle">DBT</a> 136 should be set to <code class="literal">DB_DBT_APPMALLOC</code>, which indicates that 137 Berkeley DB should free the memory when it is done with it. 138 </p> 139 <p> 140 The callback function must return 0 on success and 141 <span class="bold"><strong>errno</strong></span> or a value outside of 142 the Berkeley DB error name space on failure. 143 </p> 144 </div> 145 </div> 146 <div class="sect2" lang="en" xml:lang="en"> 147 <div class="titlepage"> 148 <div> 149 <div> 150 <h3 class="title"><a id="id1643074"></a>Errors</h3> 151 </div> 152 </div> 153 </div> 154 <p> 155 The <code class="methodname">DB->set_append_recno()</code> <span> 156 <span> 157 method may fail and return one of the following non-zero errors: 158 </span> 159 160 </span> 161 </p> 162 <div class="sect3" lang="en" xml:lang="en"> 163 <div class="titlepage"> 164 <div> 165 <div> 166 <h4 class="title"><a id="id1642794"></a>EINVAL</h4> 167 </div> 168 </div> 169 </div> 170 <p> 171 If the method was called after <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> 172 was called; or if an invalid flag value or parameter was specified. 173 </p> 174 </div> 175 </div> 176 <div class="sect2" lang="en" xml:lang="en"> 177 <div class="titlepage"> 178 <div> 179 <div> 180 <h3 class="title"><a id="id1642795"></a>Class</h3> 181 </div> 182 </div> 183 </div> 184 <p> 185 <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a> 186 </p> 187 </div> 188 <div class="sect2" lang="en" xml:lang="en"> 189 <div class="titlepage"> 190 <div> 191 <div> 192 <h3 class="title"><a id="id1642784"></a>See Also</h3> 193 </div> 194 </div> 195 </div> 196 <p> 197 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 198 </p> 199 </div> 200 </div> 201 <div class="navfooter"> 202 <hr /> 203 <table width="100%" summary="Navigation footer"> 204 <tr> 205 <td width="40%" align="left"><a accesskey="p" href="dbset_alloc.html">Prev</a>��</td> 206 <td width="20%" align="center"> 207 <a accesskey="u" href="db.html">Up</a> 208 </td> 209 <td width="40%" align="right">��<a accesskey="n" href="dbset_bt_compare.html">Next</a></td> 210 </tr> 211 <tr> 212 <td width="40%" align="left" valign="top">DB->set_alloc()��</td> 213 <td width="20%" align="center"> 214 <a accesskey="h" href="index.html">Home</a> 215 </td> 216 <td width="40%" align="right" valign="top">��DB->set_bt_compare()</td> 217 </tr> 218 </table> 219 </div> 220 </body> 221</html> 222