1<!--$Id: db_set_re_source.so,v 10.42 2004/09/28 15:04:19 bostic Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB: DB->set_re_source</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<table width="100%"><tr valign=top> 12<td> 13<b>DB->set_re_source</b> 14</td> 15<td align=right> 16<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a> 17<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td> 18</tr></table> 19<hr size=1 noshade> 20<tt> 21<b><pre> 22#include <db.h> 23<p> 24int 25DB->set_re_source(DB *db, char *source); 26<p> 27int 28DB->get_re_source(DB *db, const char **sourcep); 29</pre></b> 30<hr size=1 noshade> 31<b>Description: DB->set_re_source</b> 32<p>Set the underlying source file for the Recno access method. The purpose 33of the <b>source</b> value is to provide fast access and modification 34to databases that are normally stored as flat text files.</p> 35<p>The <b>source</b> parameter specifies an underlying flat text database 36file that is read to initialize a transient record number index. In 37the case of variable length records, the records are separated, as 38specified by <a href="../api_c/db_set_re_delim.html">DB->set_re_delim</a>. For example, standard UNIX byte 39stream files can be interpreted as a sequence of variable length records 40separated by <newline> characters.</p> 41<p>In addition, when cached data would normally be written back to the 42underlying database file (for example, the <a href="../api_c/db_close.html">DB->close</a> or 43<a href="../api_c/db_sync.html">DB->sync</a> methods are called), the in-memory copy of the database 44will be written back to the <b>source</b> file.</p> 45<p>By default, the backing source file is read lazily; that is, records 46are not read from the file until they are requested by the application. 47<b>If multiple processes (not threads) are accessing a Recno database 48concurrently, and are either inserting or deleting records, the backing 49source file must be read in its entirety before more than a single 50process accesses the database, and only that process should specify the 51backing source file as part of the <a href="../api_c/db_open.html">DB->open</a> call. See the 52<a href="../api_c/db_set_flags.html#DB_SNAPSHOT">DB_SNAPSHOT</a> flag for more information.</b></p> 53<p><b>Reading and writing the backing source file specified by <b>source</b> 54cannot be transaction-protected because it involves filesystem 55operations that are not part of the Db transaction methodology.</b> For 56this reason, if a temporary database is used to hold the records, it is 57possible to lose the contents of the <b>source</b> file, for 58example, if the system crashes at the right instant. If a file is used 59to hold the database, normal database recovery on that file can be used 60to prevent information loss, although it is still possible that the 61contents of <b>source</b> will be lost if the system crashes.</p> 62<p>The <b>source</b> file must already exist (but may be zero-length) when 63<a href="../api_c/db_open.html">DB->open</a> is called.</p> 64<p>It is not an error to specify a read-only <b>source</b> file when 65creating a database, nor is it an error to modify the resulting database. 66However, any attempt to write the changes to the backing source file using 67either the <a href="../api_c/db_sync.html">DB->sync</a> or <a href="../api_c/db_close.html">DB->close</a> methods will fail, of course. 68Specify the <a href="../api_c/db_close.html#DB_NOSYNC">DB_NOSYNC</a> flag to the <a href="../api_c/db_close.html">DB->close</a> method to stop it 69from attempting to write the changes to the backing file; instead, they 70will be silently discarded.</p> 71<p>For all of the previous reasons, the <b>source</b> field is generally 72used to specify databases that are read-only for Berkeley DB applications; 73and that are either generated on the fly by software tools or modified 74using a different mechanism -- for example, a text editor.</p> 75<p>The DB->set_re_source method configures operations performed using the specified 76<a href="../api_c/db_class.html">DB</a> handle, not all operations performed on the underlying 77database.</p> 78<p>The DB->set_re_source method may not be called after the <a href="../api_c/db_open.html">DB->open</a> method is called. 79If the database already exists when 80<a href="../api_c/db_open.html">DB->open</a> is called, the information specified to DB->set_re_source must 81be the same as that historically used to create the database or 82corruption can occur.</p> 83<p>The DB->set_re_source method 84returns a non-zero error value on failure 85and 0 on success. 86</p> 87<b>Parameters</b> <br> 88 <b>source</b><ul compact><li>The backing flat text database file for a Recno database.</ul> 89<p>When using a Unicode build on Windows (the default), the <b>source</b> 90argument will be interpreted as a UTF-8 string, which is equivalent to 91ASCII for Latin characters.</p> 92<br> 93<br><b>Errors</b> 94<p>The DB->set_re_source method 95may fail and return one of the following non-zero errors:</p> 96<br> 97<b>EINVAL</b><ul compact><li>If the method was called after <a href="../api_c/db_open.html">DB->open</a> was called; or if an 98invalid flag value or parameter was specified.</ul> 99<br> 100<hr size=1 noshade> 101<b>Description: DB->get_re_source</b> 102<p>The DB->get_re_source method returns the source file.</p> 103<p>The DB->get_re_source method may be called at any time during the life of the 104application.</p> 105<hr size=1 noshade> 106<br><b>Class</b> 107<a href="../api_c/db_class.html">DB</a> 108<br><b>See Also</b> 109<a href="../api_c/db_list.html">Databases and Related Methods</a> 110</tt> 111<table width="100%"><tr><td><br></td><td align=right> 112<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a> 113</td></tr></table> 114<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 115</body> 116</html> 117