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_cxx/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 &lt;db_cxx.h&gt;
23<p>
24int
25Db::set_re_source(char *source);
26<p>
27int
28Db::get_re_source(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_cxx/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 &lt;newline&gt; 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_cxx/db_close.html">Db::close</a> or
43<a href="/api_cxx/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_cxx/db_open.html">Db::open</a> call.  See the
52<a href="/api_cxx/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_cxx/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_cxx/db_sync.html">Db::sync</a> or <a href="/api_cxx/db_close.html">Db::close</a> methods will fail, of course.
68Specify the <a href="/api_cxx/db_close.html#DB_NOSYNC">DB_NOSYNC</a> flag to the <a href="/api_cxx/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_cxx/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_cxx/db_open.html">Db::open</a> method is called.
79If the database already exists when
80<a href="/api_cxx/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
84either returns a non-zero error value
85or throws an exception that encapsulates a non-zero error value on
86failure, and returns 0 on success.
87</p>
88<b>Parameters</b> <br>
89 <b>source</b><ul compact><li>The backing flat text database file for a Recno database.</ul>
90<p>When using a Unicode build on Windows (the default), the <b>source</b>
91argument will be interpreted as a UTF-8 string, which is equivalent to
92ASCII for Latin characters.</p>
93<br>
94<br><b>Errors</b>
95<p>The Db::set_re_source method
96may fail and throw
97<a href="/api_cxx/except_class.html">DbException</a>,
98encapsulating one of the following non-zero errors, or return one of
99the following non-zero errors:</p>
100<br>
101<b>EINVAL</b><ul compact><li>If the method was called after <a href="/api_cxx/db_open.html">Db::open</a> was called; or if an
102invalid flag value or parameter was specified.</ul>
103<br>
104<hr size=1 noshade>
105<b>Description: Db::get_re_source</b>
106<p>The Db::get_re_source method returns the source file.</p>
107<p>The Db::get_re_source method may be called at any time during the life of the
108application.</p>
109<hr size=1 noshade>
110<br><b>Class</b>
111<a href="/api_cxx/db_class.html">Db</a>
112<br><b>See Also</b>
113<a href="/api_cxx/db_list.html">Databases and Related Methods</a>
114</tt>
115<table width="100%"><tr><td><br></td><td align=right>
116<a href="/api_cxx/api_core.html"><img src="/images/api.gif" alt="API"></a><a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a>
117</td></tr></table>
118<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
119</body>
120</html>
121