96 lines
4.4 KiB
HTML
96 lines
4.4 KiB
HTML
<!--$Id: db_close.html 63573 2008-05-23 21:43:21Z trent.nelson $-->
|
|
<!--Copyright (c) 1997,2008 Oracle. All rights reserved.-->
|
|
<!--See the file LICENSE for redistribution information.-->
|
|
<html>
|
|
<head>
|
|
<title>Berkeley DB: Db::close</title>
|
|
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
|
|
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
|
|
</head>
|
|
<body bgcolor=white>
|
|
<table width="100%"><tr valign=top>
|
|
<td>
|
|
<b>Db::close</b>
|
|
</td>
|
|
<td align=right>
|
|
<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></td>
|
|
</tr></table>
|
|
<hr size=1 noshade>
|
|
<tt>
|
|
<b><pre>
|
|
#include <db_cxx.h>
|
|
<p>
|
|
int
|
|
Db::close(u_int32_t flags);
|
|
</pre></b>
|
|
<hr size=1 noshade>
|
|
<b>Description: Db::close</b>
|
|
<p>The Db::close method flushes any cached database information to disk,
|
|
closes any open cursors, frees any allocated resources, and closes any
|
|
underlying files.</p>
|
|
<p>The <a href="../api_cxx/db_class.html">Db</a> handle should not be closed while any other handle that
|
|
refers to it is not yet closed; for example, database handles must not
|
|
be closed while cursor handles into the database remain open, or
|
|
transactions that include operations on the database have not yet been
|
|
committed or aborted. Specifically, this includes <a href="../api_cxx/dbc_class.html">Dbc</a> and
|
|
<a href="../api_cxx/txn_class.html">DbTxn</a> handles.</p>
|
|
<p>Because key/data pairs are cached in memory, failing to sync the file
|
|
with the Db::close or <a href="../api_cxx/db_sync.html">Db::sync</a> method may result in
|
|
inconsistent or lost information.</p>
|
|
<p>When called on a database that is the primary database for a secondary
|
|
index, the primary database should be closed only after all secondary
|
|
indices which reference it have been closed.</p>
|
|
<p>When multiple threads are using the <a href="../api_cxx/db_class.html">Db</a> concurrently, only a single
|
|
thread may call the Db::close method.</p>
|
|
<p>The <a href="../api_cxx/db_class.html">Db</a> handle may not be accessed again after Db::close is
|
|
called, regardless of its return.</p>
|
|
<p>The Db::close method
|
|
either returns a non-zero error value
|
|
or throws an exception that encapsulates a non-zero error value on
|
|
failure, and returns 0 on success.
|
|
</p>
|
|
<b>Parameters</b> <br>
|
|
<b>flags</b><ul compact><li>The <b>flags</b> parameter must be set to 0 or by bitwise inclusively <b>OR</b>'ing together one
|
|
or more of the following values:
|
|
<br>
|
|
<b><a name="DB_NOSYNC">DB_NOSYNC</a></b><ul compact><li>Do not flush cached information to disk. The <a href="../api_cxx/db_close.html#DB_NOSYNC">DB_NOSYNC</a> flag is
|
|
a dangerous option. It should be set only if the application is doing
|
|
logging (with transactions) so that the database is recoverable after
|
|
a system or application crash, or if the database is always generated
|
|
from scratch after any system or application crash.
|
|
<p><b>It is important to understand that flushing cached information to disk
|
|
only minimizes the window of opportunity for corrupted data.</b> Although
|
|
unlikely, it is possible for database corruption to happen if a system
|
|
or application crash occurs while writing data to the database. To
|
|
ensure that database corruption never occurs, applications must either:
|
|
use transactions and logging with automatic recovery; use logging and
|
|
application-specific recovery; or edit a copy of the database, and once
|
|
all applications using the database have successfully called
|
|
Db::close, atomically replace the original database with the
|
|
updated copy.</p></ul>
|
|
<br></ul>
|
|
<br>
|
|
<br><b>Errors</b>
|
|
<p>The Db::close method
|
|
may fail and throw
|
|
<a href="../api_cxx/except_class.html">DbException</a>,
|
|
encapsulating one of the following non-zero errors, or return one of
|
|
the following non-zero errors:</p>
|
|
<br>
|
|
<b>EINVAL</b><ul compact><li>An
|
|
invalid flag value or parameter was specified.</ul>
|
|
<br>
|
|
<hr size=1 noshade>
|
|
<br><b>Class</b>
|
|
<a href="../api_cxx/db_class.html">Db</a>
|
|
<br><b>See Also</b>
|
|
<a href="../api_cxx/db_list.html">Databases and Related Methods</a>
|
|
</tt>
|
|
<table width="100%"><tr><td><br></td><td align=right>
|
|
<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>
|
|
</td></tr></table>
|
|
<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font>
|
|
</body>
|
|
</html>
|