| 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_re_source()</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_re_pad.html" title="DB->set_re_pad()" /> |
| 12 | <link rel="next" href="dbsort_multiple.html" title="DB->sort_multiple()" /> |
| 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->set_re_source()</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="dbset_re_pad.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 2. |
| 26 | The DB Handle |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="dbsort_multiple.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="dbset_re_source"></a>DB->set_re_source()</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db.h> |
| 42 | |
| 43 | int |
| 44 | DB->set_re_source(DB *db, char *source); </pre> |
| 45 | <p> |
| 46 | Set the underlying source file for the Recno access method. The |
| 47 | purpose of the <span class="bold"><strong>source</strong></span> value is to |
| 48 | provide fast access and modification to databases that are normally |
| 49 | stored as flat text files. |
| 50 | </p> |
| 51 | <p> |
| 52 | The <span class="bold"><strong>source</strong></span> parameter specifies an |
| 53 | underlying flat text database file that is read to initialize a |
| 54 | transient record number index. In the case of variable length |
| 55 | records, the records are separated, as specified by |
| 56 | <a class="xref" href="dbset_re_delim.html" title="DB->set_re_delim()">DB->set_re_delim()</a>. For |
| 57 | example, standard UNIX byte stream files can be interpreted as a |
| 58 | sequence of variable length records separated by <newline> |
| 59 | characters. |
| 60 | </p> |
| 61 | <p> |
| 62 | In addition, when cached data would normally be written back to the |
| 63 | underlying database file (for example, the |
| 64 | <a class="xref" href="dbclose.html" title="DB->close()">DB->close()</a> or |
| 65 | <a class="xref" href="dbsync.html" title="DB->sync()">DB->sync()</a> methods are called), |
| 66 | the in-memory copy of the database will be written back to the |
| 67 | <span class="bold"><strong>source</strong></span> file. |
| 68 | </p> |
| 69 | <p> |
| 70 | By default, the backing source file is read lazily; that is, records |
| 71 | are not read from the file until they are requested by the |
| 72 | application. <span class="bold"><strong>If multiple processes (not threads) |
| 73 | are accessing a Recno database concurrently, and are either inserting |
| 74 | or deleting records, the backing source file must be read in its |
| 75 | entirety before more than a single process accesses the database, and |
| 76 | only that process should specify the backing source file as part of |
| 77 | the <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> call. See the |
| 78 | <a class="link" href="dbset_flags.html#dbset_flags_DB_SNAPSHOT">DB_SNAPSHOT</a> flag |
| 79 | for more information.</strong></span> |
| 80 | </p> |
| 81 | <p> |
| 82 | <span class="bold"><strong>Reading and writing the backing source file |
| 83 | specified by <span class="bold"><strong>source</strong></span> cannot be |
| 84 | transaction-protected because it involves filesystem operations that |
| 85 | are not part of the Db transaction methodology.</strong></span> For this |
| 86 | reason, if a temporary database is used to hold the records, it is |
| 87 | possible to lose the contents of the <span class="bold"><strong>source</strong></span> file, for example, if the system crashes |
| 88 | at the right instant. If a file is used to hold the database, normal |
| 89 | database recovery on that file can be used to prevent information |
| 90 | loss, although it is still possible that the contents of <span class="bold"><strong>source</strong></span> will be lost if the system crashes. |
| 91 | </p> |
| 92 | <p> |
| 93 | The <span class="bold"><strong>source</strong></span> file must already exist |
| 94 | (but may be zero-length) when <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> is called. |
| 95 | </p> |
| 96 | <p> |
| 97 | It is not an error to specify a read-only <span class="bold"><strong>source</strong></span> file when creating a database, nor is it |
| 98 | an error to modify the resulting database. However, any attempt to |
| 99 | write the changes to the backing source file using either the |
| 100 | <a class="xref" href="dbsync.html" title="DB->sync()">DB->sync()</a> or |
| 101 | <a class="xref" href="dbclose.html" title="DB->close()">DB->close()</a> methods will fail, |
| 102 | of course. Specify the |
| 103 | <a class="link" href="dbclose.html#dbclose_DB_NOSYNC">DB_NOSYNC</a> flag to the |
| 104 | <a class="xref" href="dbclose.html" title="DB->close()">DB->close()</a> method to |
| 105 | stop it from attempting to write the changes to the backing file; |
| 106 | instead, they will be silently discarded. |
| 107 | </p> |
| 108 | <p> |
| 109 | For all of the previous reasons, the <span class="bold"><strong>source</strong></span> field is generally used to specify |
| 110 | databases that are read-only for Berkeley DB applications; and that |
| 111 | are either generated on the fly by software tools or modified using a |
| 112 | different mechanism — for example, a text editor. |
| 113 | </p> |
| 114 | <p> |
| 115 | The <code class="methodname">DB->set_re_source()</code> method configures operations performed using |
| 116 | the specified <a class="link" href="db.html" title="Chapter 2. The DB Handle">DB</a> handle, |
| 117 | not all operations performed on the underlying database. |
| 118 | </p> |
| 119 | <p> |
| 120 | The <code class="methodname">DB->set_re_source()</code> method may not be called after the |
| 121 | <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> method is called. If |
| 122 | the database already exists when |
| 123 | <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> is called, the |
| 124 | information specified to <code class="methodname">DB->set_re_source()</code> must be the same as that |
| 125 | historically used to create the database or corruption can occur. |
| 126 | </p> |
| 127 | <p> |
| 128 | The <code class="methodname">DB->set_re_source()</code> <span> |
| 129 | <span> |
| 130 | method returns a non-zero error value on failure and 0 on success. |
| 131 | </span> |
| 132 | |
| 133 | </span> |
| 134 | </p> |
| 135 | <div class="sect2" lang="en" xml:lang="en"> |
| 136 | <div class="titlepage"> |
| 137 | <div> |
| 138 | <div> |
| 139 | <h3 class="title"><a id="idp50581832"></a>Parameters</h3> |
| 140 | </div> |
| 141 | </div> |
| 142 | </div> |
| 143 | <div class="sect3" lang="en" xml:lang="en"> |
| 144 | <div class="titlepage"> |
| 145 | <div> |
| 146 | <div> |
| 147 | <h4 class="title"><a id="idp50582024"></a>source</h4> |
| 148 | </div> |
| 149 | </div> |
| 150 | </div> |
| 151 | <p> |
| 152 | The backing flat text database file for a Recno database. |
| 153 | </p> |
| 154 | <p> |
| 155 | When using a Unicode build on Windows (the default), the |
| 156 | <span class="bold"><strong>source</strong></span> |
| 157 | argument will be interpreted as a UTF-8 string, which is equivalent to |
| 158 | ASCII for Latin characters. |
| 159 | </p> |
| 160 | </div> |
| 161 | </div> |
| 162 | <div class="sect2" lang="en" xml:lang="en"> |
| 163 | <div class="titlepage"> |
| 164 | <div> |
| 165 | <div> |
| 166 | <h3 class="title"><a id="idp50584424"></a>Errors</h3> |
| 167 | </div> |
| 168 | </div> |
| 169 | </div> |
| 170 | <p> |
| 171 | The <code class="methodname">DB->set_re_source()</code> <span> |
| 172 | <span> |
| 173 | method may fail and return one of the following non-zero errors: |
| 174 | </span> |
| 175 | |
| 176 | </span> |
| 177 | </p> |
| 178 | <div class="sect3" lang="en" xml:lang="en"> |
| 179 | <div class="titlepage"> |
| 180 | <div> |
| 181 | <div> |
| 182 | <h4 class="title"><a id="idp50598120"></a>EINVAL</h4> |
| 183 | </div> |
| 184 | </div> |
| 185 | </div> |
| 186 | <p> |
| 187 | If the method was called after <a class="xref" href="dbopen.html" title="DB->open()">DB->open()</a> |
| 188 | was called; or if an invalid flag value or parameter was specified. |
| 189 | </p> |
| 190 | </div> |
| 191 | </div> |
| 192 | <div class="sect2" lang="en" xml:lang="en"> |
| 193 | <div class="titlepage"> |
| 194 | <div> |
| 195 | <div> |
| 196 | <h3 class="title"><a id="idp50589024"></a>Class</h3> |
| 197 | </div> |
| 198 | </div> |
| 199 | </div> |
| 200 | <p> |
| 201 | <a class="link" href="db.html" title="Chapter 2. The DB Handle">DB</a> |
| 202 | </p> |
| 203 | </div> |
| 204 | <div class="sect2" lang="en" xml:lang="en"> |
| 205 | <div class="titlepage"> |
| 206 | <div> |
| 207 | <div> |
| 208 | <h3 class="title"><a id="idp50600560"></a>See Also</h3> |
| 209 | </div> |
| 210 | </div> |
| 211 | </div> |
| 212 | <p> |
| 213 | <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> |
| 214 | </p> |
| 215 | </div> |
| 216 | </div> |
| 217 | <div class="navfooter"> |
| 218 | <hr /> |
| 219 | <table width="100%" summary="Navigation footer"> |
| 220 | <tr> |
| 221 | <td width="40%" align="left"><a accesskey="p" href="dbset_re_pad.html">Prev</a> </td> |
| 222 | <td width="20%" align="center"> |
| 223 | <a accesskey="u" href="db.html">Up</a> |
| 224 | </td> |
| 225 | <td width="40%" align="right"> <a accesskey="n" href="dbsort_multiple.html">Next</a></td> |
| 226 | </tr> |
| 227 | <tr> |
| 228 | <td width="40%" align="left" valign="top">DB->set_re_pad() </td> |
| 229 | <td width="20%" align="center"> |
| 230 | <a accesskey="h" href="index.html">Home</a> |
| 231 | </td> |
| 232 | <td width="40%" align="right" valign="top"> DB->sort_multiple()</td> |
| 233 | </tr> |
| 234 | </table> |
| 235 | </div> |
| 236 | </body> |
| 237 | </html> |