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