Debian Codegraph @

docs/api_reference/CXX/dbclose.html

raw symbols SCIP
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::close()</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="dbassociate_foreign.html" title="Db::associate_foreign()" />
12 <link rel="next" href="dbcompact.html" title="Db::compact()" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Db::close()</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="dbassociate_foreign.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 2. 
26 The Db Handle
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="dbcompact.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="dbclose"></a>Db::close()</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#include &lt;db_cxx.h&gt;
42
43 int
44 Db::close(u_int32_t flags);</pre>
45 <p>
46 The <code class="methodname">Db::close()</code> method flushes cached database information to
47 disk, closes any open cursors, frees allocated resources, and
48 closes underlying files. When the close operation for a cursor fails,
49 the method returns a non-zero error value for the first instance of such an error,
50 and continues to close the rest of the cursors and database handles.
51 </p>
52 <p>
53 Although closing a database handle will close any open cursors, it
54 is recommended that applications explicitly close all their
55 <a class="link" href="dbc.html" title="Chapter 3.  The Dbc Handle">Dbc</a> handles
56 before closing the database. The reason why is that when
57 the cursor is explicitly closed, the memory allocated for it is
58 reclaimed; however, this will <span class="emphasis"><em>not</em></span> happen if
59 you close a database while cursors are still opened.
60 </p>
61 <p>
62 The same rule, for the same reasons, hold true for
63 <a class="link" href="txn.html" title="Chapter 13.  The DbTxn Handle">DbTxn</a>
64 handles. Simply make sure you close all your transaction handles
65 before closing your database handle.
66 </p>
67 <p>
68 Because key/data pairs are cached in memory, applications should
69 make a point to always either close database handles or sync their
70 data to disk (using the <a class="xref" href="dbsync.html" title="Db::sync()">Db::sync()</a>
71 method) before exiting, to ensure that any data cached in main memory are
72 reflected in the underlying file system.
73 </p>
74 <p>
75 When called on a database that is the primary database for a secondary
76 index, the primary database should be closed only after all secondary
77 indices referencing it have been closed.
78 </p>
79 <p>
80 When multiple threads are using the <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>
81 concurrently, only a single thread may call the <code class="methodname">Db::close()</code> method.
82 </p>
83 <p>
84 The <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a> handle may not be
85 accessed again after <code class="methodname">Db::close()</code> is called, regardless of its return.
86 </p>
87 <p>
88 If you do not close the <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a> handle explicitly, it will be closed when
89 the environment handle that owns the <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a> handle is closed.
90 </p>
91 <p>
92 The <code class="methodname">Db::close()</code> <span>
93
94 <span>
95 method either returns a non-zero error value or throws an
96 exception that encapsulates a non-zero error value on
97 failure, and returns 0 on success.
98 </span>
99 </span>
100 The error values that <code class="methodname">Db::close()</code> method returns include the error values of <code class="methodname">Dbc::close()</code> and the following:
101 </p>
102 <div class="sect3" lang="en" xml:lang="en">
103 <div class="titlepage">
104 <div>
105 <div>
106 <h4 class="title"><a id="idp3734048"></a><span>DbDeadlockException or </span>DB_LOCK_DEADLOCK</h4>
107 </div>
108 </div>
109 </div>
110 <p>
111 A transactional database environment operation was selected to resolve
112 a deadlock.
113 </p>
114 <p>
115 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if
116 your Berkeley DB API is configured to throw exceptions.
117 Otherwise, <code class="literal">DB_LOCK_DEADLOCK</code> is returned.
118 </p>
119 </div>
120 <div class="sect3" lang="en" xml:lang="en">
121 <div class="titlepage">
122 <div>
123 <div>
124 <h4 class="title"><a id="idp2491512"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4>
125 </div>
126 </div>
127 </div>
128 <p>
129 A Berkeley DB Concurrent Data Store database environment configured
130 for lock timeouts was unable to grant a lock in the allowed time.
131 </p>
132 <p>
133 You attempted to open a database handle that is configured
134 for no waiting exclusive locking, but the exclusive lock could not be
135 immediately obtained. See
136 <a class="xref" href="dbset_lk_exclusive.html" title="Db::set_lk_exclusive()">Db::set_lk_exclusive()</a>
137 for more information.
138 </p>
139 <p>
140 <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if
141 your Berkeley DB API is configured to throw exceptions.
142 Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned.
143 </p>
144 </div>
145 <div class="sect3" lang="en" xml:lang="en">
146 <div class="titlepage">
147 <div>
148 <div>
149 <h4 class="title"><a id="idp2411120"></a>EINVAL</h4>
150 </div>
151 </div>
152 </div>
153 <p>
154 If the cursor is already closed; or if an invalid flag value or parameter was specified.
155 </p>
156 </div>
157 <div class="sect2" lang="en" xml:lang="en">
158 <div class="titlepage">
159 <div>
160 <div>
161 <h3 class="title"><a id="idp2080096"></a>Parameters</h3>
162 </div>
163 </div>
164 </div>
165 <div class="sect3" lang="en" xml:lang="en">
166 <div class="titlepage">
167 <div>
168 <div>
169 <h4 class="title"><a id="idp1872976"></a>flags</h4>
170 </div>
171 </div>
172 </div>
173 <p>
174 The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
175 or be set to the following value:
176 </p>
177 <div class="itemizedlist">
178 <ul type="disc">
179 <li>
180 <p><a id="dbclose_DB_NOSYNC"></a>
181 <code class="literal">DB_NOSYNC</code>
182 </p>
183 <p>
184 Do not flush cached information to disk. This flag is a
185 dangerous option. It should be set only if the application is doing
186 logging (with transactions) so that the database is recoverable after
187 a system or application crash, or if the database is always generated
188 from scratch after any system or application crash.
189 </p>
190 <p>
191 <span class="bold"><strong>It is important to understand that flushing
192 cached information to disk only minimizes the window of opportunity
193 for corrupted data.</strong></span> Although unlikely, it is possible for
194 database corruption to happen if a system or application crash occurs
195 while writing data to the database. To ensure that database
196 corruption never occurs, applications must either: use transactions
197 and logging with automatic recovery; use logging and
198 application-specific recovery; or edit a copy of the database, and
199 once all applications using the database have successfully called
200 <code class="methodname">Db::close()</code>, atomically replace the original database with the
201 updated copy.
202 </p>
203 <p>
204 Note that this flag only works when the database
205 has been opened using an environment.
206 </p>
207 </li>
208 </ul>
209 </div>
210 </div>
211 </div>
212 <div class="sect2" lang="en" xml:lang="en">
213 <div class="titlepage">
214 <div>
215 <div>
216 <h3 class="title"><a id="idp2046584"></a>Errors</h3>
217 </div>
218 </div>
219 </div>
220 <p>
221 The <code class="methodname">Db::close()</code> <span>
222
223 <span>
224 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a>
225 exception, encapsulating one of the following non-zero errors, or return one
226 of the following non-zero errors:
227 </span>
228 </span>
229 </p>
230 <div class="sect3" lang="en" xml:lang="en">
231 <div class="titlepage">
232 <div>
233 <div>
234 <h4 class="title"><a id="idp1982528"></a>EINVAL</h4>
235 </div>
236 </div>
237 </div>
238 <p>
239 An invalid flag value or parameter was specified.
240 </p>
241 </div>
242 <p>
243 The error messages returned for the first error encountered when <code class="methodname">Db::close()</code> method closes any open cursors include:
244 </p>
245 <div class="sect3" lang="en" xml:lang="en">
246 <div class="titlepage">
247 <div>
248 <div>
249 <h4 class="title"><a id="idp957072"></a><span>DbDeadlockException or </span>DB_LOCK_DEADLOCK</h4>
250 </div>
251 </div>
252 </div>
253 <p>
254 A transactional database environment operation was selected to resolve
255 a deadlock.
256 </p>
257 <p>
258 <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if
259 your Berkeley DB API is configured to throw exceptions.
260 Otherwise, <code class="literal">DB_LOCK_DEADLOCK</code> is returned.
261 </p>
262 </div>
263 <div class="sect3" lang="en" xml:lang="en">
264 <div class="titlepage">
265 <div>
266 <div>
267 <h4 class="title"><a id="idp1043208"></a><span>DbLockNotGrantedException or </span>DB_LOCK_NOTGRANTED</h4>
268 </div>
269 </div>
270 </div>
271 <p>
272 A Berkeley DB Concurrent Data Store database environment configured
273 for lock timeouts was unable to grant a lock in the allowed time.
274 </p>
275 <p>
276 You attempted to open a database handle that is configured
277 for no waiting exclusive locking, but the exclusive lock could not be
278 immediately obtained. See
279 <a class="xref" href="dbset_lk_exclusive.html" title="Db::set_lk_exclusive()">Db::set_lk_exclusive()</a>
280 for more information.
281 </p>
282 <p>
283 <a class="xref" href="dblocknotgranted.html" title="DbLockNotGrantedException">DbLockNotGrantedException</a> is thrown if
284 your Berkeley DB API is configured to throw exceptions.
285 Otherwise, <code class="literal">DB_LOCK_NOTGRANTED</code> is returned.
286 </p>
287 </div>
288 <div class="sect3" lang="en" xml:lang="en">
289 <div class="titlepage">
290 <div>
291 <div>
292 <h4 class="title"><a id="idp3690800"></a>EINVAL</h4>
293 </div>
294 </div>
295 </div>
296 <p>
297 If the cursor is already closed; or if an invalid flag value or parameter was specified.
298 </p>
299 </div>
300 </div>
301 <div class="sect2" lang="en" xml:lang="en">
302 <div class="titlepage">
303 <div>
304 <div>
305 <h3 class="title"><a id="idp1040496"></a>Class</h3>
306 </div>
307 </div>
308 </div>
309 <p>
310 <a class="link" href="db.html" title="Chapter 2.  The Db Handle">Db</a>
311 </p>
312 </div>
313 <div class="sect2" lang="en" xml:lang="en">
314 <div class="titlepage">
315 <div>
316 <div>
317 <h3 class="title"><a id="idp84192"></a>See Also</h3>
318 </div>
319 </div>
320 </div>
321 <p>
322 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a>
323 </p>
324 </div>
325 </div>
326 <div class="navfooter">
327 <hr />
328 <table width="100%" summary="Navigation footer">
329 <tr>
330 <td width="40%" align="left"><a accesskey="p" href="dbassociate_foreign.html">Prev</a> </td>
331 <td width="20%" align="center">
332 <a accesskey="u" href="db.html">Up</a>
333 </td>
334 <td width="40%" align="right"> <a accesskey="n" href="dbcompact.html">Next</a></td>
335 </tr>
336 <tr>
337 <td width="40%" align="left" valign="top">Db::associate_foreign() </td>
338 <td width="20%" align="center">
339 <a accesskey="h" href="index.html">Home</a>
340 </td>
341 <td width="40%" align="right" valign="top"> Db::compact()</td>
342 </tr>
343 </table>
344 </div>
345 </body>
346 </html>