Debian Codegraph @

docs/api_reference/C/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-&gt;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-&gt;associate_foreign()" />
12 <link rel="next" href="dbcompact.html" title="DB-&gt;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-&gt;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-&gt;close()</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#include &lt;db.h&gt;
42
43 int
44 DB-&gt;close(DB *db, u_int32_t flags); </pre>
45 <p>
46 The <code class="methodname">DB-&gt;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 DBcursor Handle">DBcursor</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 12.  The DB_TXN Handle">DB_TXN</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-&gt;sync()">DB-&gt;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-&gt;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-&gt;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-&gt;close()</code> <span>
93 <span>
94 method returns a non-zero error value on failure and 0 on success.
95 </span>
96
97 </span>
98 The error values that <code class="methodname">DB-&gt;close()</code> method returns include the error values of <code class="methodname">DBcursor-&gt;close()</code> and the following:
99 </p>
100 <div class="sect3" lang="en" xml:lang="en">
101 <div class="titlepage">
102 <div>
103 <div>
104 <h4 class="title"><a id="idp49255952"></a>DB_LOCK_DEADLOCK</h4>
105 </div>
106 </div>
107 </div>
108 <p>
109 A transactional database environment operation was selected to resolve
110 a deadlock.
111 </p>
112 </div>
113 <div class="sect3" lang="en" xml:lang="en">
114 <div class="titlepage">
115 <div>
116 <div>
117 <h4 class="title"><a id="idp49273128"></a>DB_LOCK_NOTGRANTED</h4>
118 </div>
119 </div>
120 </div>
121 <p>
122 A Berkeley DB Concurrent Data Store database environment configured
123 for lock timeouts was unable to grant a lock in the allowed time.
124 </p>
125 <p>
126 You attempted to open a database handle that is configured
127 for no waiting exclusive locking, but the exclusive lock could not be
128 immediately obtained. See
129 <a class="xref" href="dbset_lk_exclusive.html" title="DB-&gt;set_lk_exclusive()">DB-&gt;set_lk_exclusive()</a>
130 for more information.
131 </p>
132 </div>
133 <div class="sect3" lang="en" xml:lang="en">
134 <div class="titlepage">
135 <div>
136 <div>
137 <h4 class="title"><a id="idp49252240"></a>EINVAL</h4>
138 </div>
139 </div>
140 </div>
141 <p>
142 If the cursor is already closed; or if an invalid flag value or parameter was specified.
143 </p>
144 </div>
145 <div class="sect2" lang="en" xml:lang="en">
146 <div class="titlepage">
147 <div>
148 <div>
149 <h3 class="title"><a id="idp49378640"></a>Parameters</h3>
150 </div>
151 </div>
152 </div>
153 <div class="sect3" lang="en" xml:lang="en">
154 <div class="titlepage">
155 <div>
156 <div>
157 <h4 class="title"><a id="idp49378832"></a>flags</h4>
158 </div>
159 </div>
160 </div>
161 <p>
162 The <span class="bold"><strong>flags</strong></span> parameter must be set to 0
163 or be set to the following value:
164 </p>
165 <div class="itemizedlist">
166 <ul type="disc">
167 <li>
168 <p><a id="dbclose_DB_NOSYNC"></a>
169 <code class="literal">DB_NOSYNC</code>
170 </p>
171 <p>
172 Do not flush cached information to disk. This flag is a
173 dangerous option. It should be set only if the application is doing
174 logging (with transactions) so that the database is recoverable after
175 a system or application crash, or if the database is always generated
176 from scratch after any system or application crash.
177 </p>
178 <p>
179 <span class="bold"><strong>It is important to understand that flushing
180 cached information to disk only minimizes the window of opportunity
181 for corrupted data.</strong></span> Although unlikely, it is possible for
182 database corruption to happen if a system or application crash occurs
183 while writing data to the database. To ensure that database
184 corruption never occurs, applications must either: use transactions
185 and logging with automatic recovery; use logging and
186 application-specific recovery; or edit a copy of the database, and
187 once all applications using the database have successfully called
188 <code class="methodname">DB-&gt;close()</code>, atomically replace the original database with the
189 updated copy.
190 </p>
191 <p>
192 Note that this flag only works when the database
193 has been opened using an environment.
194 </p>
195 </li>
196 </ul>
197 </div>
198 </div>
199 </div>
200 <div class="sect2" lang="en" xml:lang="en">
201 <div class="titlepage">
202 <div>
203 <div>
204 <h3 class="title"><a id="idp49382496"></a>Errors</h3>
205 </div>
206 </div>
207 </div>
208 <p>
209 The <code class="methodname">DB-&gt;close()</code> <span>
210 <span>
211 method may fail and return one of the following non-zero errors:
212 </span>
213
214 </span>
215 </p>
216 <div class="sect3" lang="en" xml:lang="en">
217 <div class="titlepage">
218 <div>
219 <div>
220 <h4 class="title"><a id="idp49387736"></a>EINVAL</h4>
221 </div>
222 </div>
223 </div>
224 <p>
225 An invalid flag value or parameter was specified.
226 </p>
227 </div>
228 <p>
229 The error messages returned for the first error encountered when <code class="methodname">DB-&gt;close()</code> method closes any open cursors include:
230 </p>
231 <div class="sect3" lang="en" xml:lang="en">
232 <div class="titlepage">
233 <div>
234 <div>
235 <h4 class="title"><a id="idp49360320"></a>DB_LOCK_DEADLOCK</h4>
236 </div>
237 </div>
238 </div>
239 <p>
240 A transactional database environment operation was selected to resolve
241 a deadlock.
242 </p>
243 </div>
244 <div class="sect3" lang="en" xml:lang="en">
245 <div class="titlepage">
246 <div>
247 <div>
248 <h4 class="title"><a id="idp49385048"></a>DB_LOCK_NOTGRANTED</h4>
249 </div>
250 </div>
251 </div>
252 <p>
253 A Berkeley DB Concurrent Data Store database environment configured
254 for lock timeouts was unable to grant a lock in the allowed time.
255 </p>
256 <p>
257 You attempted to open a database handle that is configured
258 for no waiting exclusive locking, but the exclusive lock could not be
259 immediately obtained. See
260 <a class="xref" href="dbset_lk_exclusive.html" title="DB-&gt;set_lk_exclusive()">DB-&gt;set_lk_exclusive()</a>
261 for more information.
262 </p>
263 </div>
264 <div class="sect3" lang="en" xml:lang="en">
265 <div class="titlepage">
266 <div>
267 <div>
268 <h4 class="title"><a id="idp49390696"></a>EINVAL</h4>
269 </div>
270 </div>
271 </div>
272 <p>
273 If the cursor is already closed; or if an invalid flag value or parameter was specified.
274 </p>
275 </div>
276 </div>
277 <div class="sect2" lang="en" xml:lang="en">
278 <div class="titlepage">
279 <div>
280 <div>
281 <h3 class="title"><a id="idp49390400"></a>Class</h3>
282 </div>
283 </div>
284 </div>
285 <p>
286 <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a>
287 </p>
288 </div>
289 <div class="sect2" lang="en" xml:lang="en">
290 <div class="titlepage">
291 <div>
292 <div>
293 <h3 class="title"><a id="idp49392336"></a>See Also</h3>
294 </div>
295 </div>
296 </div>
297 <p>
298 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a>
299 </p>
300 </div>
301 </div>
302 <div class="navfooter">
303 <hr />
304 <table width="100%" summary="Navigation footer">
305 <tr>
306 <td width="40%" align="left"><a accesskey="p" href="dbassociate_foreign.html">Prev</a> </td>
307 <td width="20%" align="center">
308 <a accesskey="u" href="db.html">Up</a>
309 </td>
310 <td width="40%" align="right"> <a accesskey="n" href="dbcompact.html">Next</a></td>
311 </tr>
312 <tr>
313 <td width="40%" align="left" valign="top">DB-&gt;associate_foreign() </td>
314 <td width="20%" align="center">
315 <a accesskey="h" href="index.html">Home</a>
316 </td>
317 <td width="40%" align="right" valign="top"> DB-&gt;compact()</td>
318 </tr>
319 </table>
320 </div>
321 </body>
322 </html>