2
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
3
<!--All rights reserved.-->
4
<!--See the file LICENSE for redistribution information.-->
7
<title>Berkeley DB: Db::set_re_source</title>
8
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
9
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
12
<a name="2"><!--meow--></a>
13
<table width="100%"><tr valign=top>
15
<h1>Db::set_re_source</h1>
18
<a href="../api_cxx/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
23
#include <db_cxx.h>
26
Db::set_re_source(char *re_source);
29
<p>Set the underlying source file for the Recno access method. The purpose
30
of the <b>re_source</b> value is to provide fast access and modification
31
to databases that are normally stored as flat text files.
32
<p>If the <b>re_source</b> field is set, it specifies an underlying flat
33
text database file that is read to initialize a transient record number
34
index. In the case of variable length records, the records are
35
separated, as specified by <a href="../api_cxx/db_set_re_delim.html">Db::set_re_delim</a>. For example,
36
standard UNIX byte stream files can be interpreted as a sequence of
37
variable length records separated by <newline> characters.
38
<p>In addition, when cached data would normally be written back to the
39
underlying database file (for example, the <a href="../api_cxx/db_close.html">Db::close</a> or
40
<a href="../api_cxx/db_sync.html">Db::sync</a> methods are called), the in-memory copy of the database
41
will be written back to the <b>re_source</b> file.
42
<p>By default, the backing source file is read lazily; that is, records
43
are not read from the file until they are requested by the application.
44
<b>If multiple processes (not threads) are accessing a Recno database
45
concurrently, and are either inserting or deleting records, the backing
46
source file must be read in its entirety before more than a single
47
process accesses the database, and only that process should specify the
48
backing source file as part of the <a href="../api_cxx/db_open.html">Db::open</a> call. See the
49
<a href="../api_cxx/db_set_flags.html#DB_SNAPSHOT">DB_SNAPSHOT</a> flag for more information.</b>
50
<p><b>Reading and writing the backing source file specified by <b>re_source</b>
51
cannot be transaction-protected because it involves filesystem
52
operations that are not part of the Db transaction methodology.</b> For
53
this reason, if a temporary database is used to hold the records, it is
54
possible to lose the contents of the <b>re_source</b> file, for
55
example, if the system crashes at the right instant. If a file is used
56
to hold the database, normal database recovery on that file can be used
57
to prevent information loss, although it is still possible that the
58
contents of <b>re_source</b> will be lost if the system crashes.
59
<p>The <b>re_source</b> file must already exist (but may be zero-length) when
60
<a href="../api_cxx/db_open.html">Db::open</a> is called.
61
<p>It is not an error to specify a read-only <b>re_source</b> file when
62
creating a database, nor is it an error to modify the resulting database.
63
However, any attempt to write the changes to the backing source file using
64
either 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.
65
Specify 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
66
from attempting to write the changes to the backing file; instead, they
67
will be silently discarded.
68
<p>For all of the previous reasons, the <b>re_source</b> field is generally
69
used to specify databases that are read-only for Berkeley DB applications;
70
and that are either generated on the fly by software tools or modified
71
using a different mechanism -- for example, a text editor.
72
<p>The Db::set_re_source method configures operations performed using the specified
73
<a href="../api_cxx/db_class.html">Db</a> handle, not all operations performed on the underlying
75
<p>The Db::set_re_source interface may not be called after the <a href="../api_cxx/db_open.html">Db::open</a>
77
If the database already exists when
78
<a href="../api_cxx/db_open.html">Db::open</a> is called, the information specified to Db::set_re_source must
79
be the same as that historically used to create the database or
81
<p>The Db::set_re_source method either returns a non-zero error value or throws an exception that
82
encapsulates a non-zero error value on failure, and returns 0 on success.
84
<p>The Db::set_re_source method may fail and throw an exception or return a non-zero error for the following conditions:
86
<p><dt>EINVAL<dd>An invalid flag value or parameter was specified.
87
<p>Called after <a href="../api_cxx/db_open.html">Db::open</a> was called.
89
<p>The Db::set_re_source method may fail and throw an exception or return a non-zero error for errors specified for other Berkeley DB and C library or system methods.
90
If a catastrophic error has occurred, the Db::set_re_source method may fail and
91
either return <a href="../ref/program/errorret.html#DB_RUNRECOVERY">DB_RUNRECOVERY</a> or throw a
92
<a href="../api_cxx/runrec_class.html">DbRunRecoveryException</a>,
93
in which case all subsequent Berkeley DB calls will fail in the same way.
95
<a href="../api_cxx/db_class.html">Db</a>
97
<a href="../api_cxx/db_list.html">Databases and Related Methods</a>
99
<table width="100%"><tr><td><br></td><td align=right>
100
<a href="../api_cxx/c_index.html"><img src="../images/api.gif" alt="API"></a><a href="../reftoc.html"><img src="../images/ref.gif" alt="Ref"></a>
102
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>