Debian Codegraph @

docs/api_reference/C/dbopen.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;open()</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="dbkey_range.html" title="DB-&gt;key_range()" />
12 <link rel="next" href="dbput.html" title="DB-&gt;put()" />
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;open()</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="dbkey_range.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="dbput.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="dbopen"></a>DB-&gt;open()</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#include &lt;db.h&gt;
42
43 int
44 DB-&gt;open(DB *db, DB_TXN *txnid, const char *file,
45 const char *database, DBTYPE type, u_int32_t flags, int mode); </pre>
46 <p>
47 The <code class="methodname">DB-&gt;open()</code> method opens the database represented by the
48 <span class="bold"><strong>file</strong></span> and <span class="bold"><strong>database</strong></span>.
49 </p>
50 <p>
51 The currently supported Berkeley DB file formats (or <span class="emphasis"><em>access
52 methods</em></span>) are Btree, Hash, Heap, Queue, and Recno. The Btree
53 format is a representation of a sorted, balanced tree structure. The
54 Hash format is an extensible, dynamic hashing scheme. The Queue
55 format supports fast access to fixed-length records accessed
56 sequentially or by logical record number. The Recno format supports
57 fixed- or variable-length records, accessed sequentially or by logical
58 record number, and optionally backed by a flat text file.
59 </p>
60 <p>
61 Storage and retrieval for the Berkeley DB access methods are based on
62 key/data pairs; see <a class="link" href="dbt.html" title="Chapter 4.  The DBT Handle">DBT</a>
63 for more information.
64 </p>
65 <p>
66 Calling <code class="methodname">DB-&gt;open()</code> is a relatively expensive operation, and
67 maintaining a set of open databases will normally be preferable to
68 repeatedly opening and closing the database for each new query.
69 </p>
70 <p>
71 The <code class="methodname">DB-&gt;open()</code> <span>
72 <span>
73 method returns a non-zero error value on failure and 0 on success.
74 </span>
75
76 </span>
77 If <code class="methodname">DB-&gt;open()</code> fails, the
78 <a class="xref" href="dbclose.html" title="DB-&gt;close()">DB-&gt;close()</a> method must be
79 called to discard the <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a>
80 handle.
81 </p>
82 <div class="sect2" lang="en" xml:lang="en">
83 <div class="titlepage">
84 <div>
85 <div>
86 <h3 class="title"><a id="idp49854872"></a>Parameters</h3>
87 </div>
88 </div>
89 </div>
90 <div class="sect3" lang="en" xml:lang="en">
91 <div class="titlepage">
92 <div>
93 <div>
94 <h4 class="title"><a id="idp49885248"></a>txnid</h4>
95 </div>
96 </div>
97 </div>
98 <p>
99 If the operation is part of an application-specified
100 transaction, the <span class="bold"><strong>txnid</strong></span>
101 parameter is a transaction handle returned from
102 <a class="xref" href="txnbegin.html" title="DB_ENV-&gt;txn_begin()">DB_ENV-&gt;txn_begin()</a>; if
103 the operation is part of a Berkeley DB Concurrent Data
104 Store group, the
105 <span class="bold"><strong>txnid</strong></span> parameter is a
106 handle returned from
107 <a class="xref" href="envcdsgroup_begin.html" title="DB_ENV-&gt;cdsgroup_begin()">DB_ENV-&gt;cdsgroup_begin()</a>;
108 otherwise NULL. If no transaction handle is specified,
109 but the DB_AUTO_COMMIT flag is specified, the operation
110 will be implicitly transaction protected. Note that
111 transactionally protected operations on a
112 <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a> handle requires the
113 <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a> handle itself be
114 transactionally protected during its open. Also note
115 that the transaction must be committed before the handle
116 is closed; see
117 <a href="../../programmer_reference/program_scope.html" class="olink">Berkeley DB handles</a>
118 for more information.
119 </p>
120 </div>
121 <div class="sect3" lang="en" xml:lang="en">
122 <div class="titlepage">
123 <div>
124 <div>
125 <h4 class="title"><a id="idp49895336"></a>file</h4>
126 </div>
127 </div>
128 </div>
129 <p>
130 The <span class="bold"><strong>file</strong></span> parameter is used as the
131 name of an underlying file that will be used to back the database; see
132 <a href="../../programmer_reference/env_naming.html" class="olink">File naming</a> for more
133 information.
134 </p>
135 <p>
136 In-memory databases never intended to be preserved on disk may be
137 created by setting the <span class="bold"><strong>file</strong></span> parameter
138 to NULL. Whether other threads of control can access this database is
139 driven entirely by whether the <span class="bold"><strong>database</strong></span>
140 parameter is set to NULL.
141 </p>
142 <p>
143 When using a Unicode build on Windows (the default), the <span class="bold"><strong>file</strong></span> argument will be interpreted as a UTF-8
144 string, which is equivalent to ASCII for Latin characters.
145 </p>
146 </div>
147 <div class="sect3" lang="en" xml:lang="en">
148 <div class="titlepage">
149 <div>
150 <div>
151 <h4 class="title"><a id="idp49851072"></a>database</h4>
152 </div>
153 </div>
154 </div>
155 <p>
156 The <span class="bold"><strong>database</strong></span> parameter is optional,
157 and allows applications to have multiple databases in a single file.
158 Although no <span class="bold"><strong>database</strong></span> parameter needs
159 to be specified, it is an error to attempt to open a second database
160 in a <span class="bold"><strong>file</strong></span> that was not initially
161 created using a <span class="bold"><strong>database</strong></span> name.
162 Further, the <span class="bold"><strong>database</strong></span> parameter is
163 not supported by the Queue format. Finally, when opening multiple
164 databases in the same physical file, it is important to consider
165 locking and memory cache issues; see
166 <a href="../../programmer_reference/am_opensub.html" class="olink">Opening multiple databases in a single file</a>
167 for more information.
168 </p>
169 <p>
170 If both the <span class="bold"><strong>database</strong></span> and
171 <span class="bold"><strong>file</strong></span> parameters are NULL,
172 the database is strictly temporary and cannot be opened
173 by any other thread of control. Thus the database can only be accessed
174 by sharing the single database handle that created it, in
175 circumstances where doing so is safe.
176 </p>
177 <p>
178 If the <span class="bold"><strong>database</strong></span> parameter is not
179 set to NULL, the database can be opened by other threads of control
180 and will be replicated to client sites in any replication group, regardless
181 of whether the <span class="bold"><strong>file</strong></span> parameter is set to
182 NULL.
183 </p>
184 </div>
185 <div class="sect3" lang="en" xml:lang="en">
186 <div class="titlepage">
187 <div>
188 <div>
189 <h4 class="title"><a id="idp49891112"></a>type</h4>
190 </div>
191 </div>
192 </div>
193 <p>
194 The <span class="bold"><strong>type</strong></span> parameter is of
195 type DBTYPE, and must be set to one of
196 <code class="literal">DB_BTREE</code>, <code class="literal">DB_HASH</code>,
197 <code class="literal">DB_HEAP</code>, <code class="literal">DB_QUEUE</code>,
198 <code class="literal">DB_RECNO</code>, or <code class="literal">DB_UNKNOWN</code>.
199 If <span class="bold"><strong>type</strong></span> is DB_UNKNOWN, the
200 database must already exist and
201 <code class="methodname">DB-&gt;open()</code> will automatically
202 determine its type. The
203 <a class="xref" href="dbget_type.html" title="DB-&gt;get_type()">DB-&gt;get_type()</a> method
204 may be used to determine the underlying type of databases opened using
205 DB_UNKNOWN.
206 </p>
207 <p>
208 It is an error to specify the incorrect <span class="bold"><strong>type</strong></span>
209 for a database that already exists.
210 </p>
211 </div>
212 <div class="sect3" lang="en" xml:lang="en">
213 <div class="titlepage">
214 <div>
215 <div>
216 <h4 class="title"><a id="idp49892184"></a>flags</h4>
217 </div>
218 </div>
219 </div>
220 <p>
221 The <span class="bold"><strong>flags</strong></span> parameter must be set to zero or
222 by bitwise inclusively <span class="bold"><strong>OR</strong></span>'ing together one
223 or more of the following values:
224 </p>
225 <div class="itemizedlist">
226 <ul type="disc">
227 <li>
228 <p><a id="open_DB_AUTO_COMMIT"></a>
229 <code class="literal">DB_AUTO_COMMIT</code>
230 </p>
231 <p>
232 Enclose the <code class="methodname">DB-&gt;open()</code>
233 call within a transaction. If the call succeeds,
234 the open operation will be recoverable and all
235 subsequent database modification operations based
236 on this handle will be transactionally protected.
237 If the call fails, no database will have been
238 created.
239 </p>
240 </li>
241 <li>
242 <p><a id="open_DB_CREATE"></a>
243 <code class="literal">DB_CREATE</code>
244 </p>
245 <p>
246 Create the database. If the database does not
247 already exist and the <code class="literal">DB_CREATE</code>
248 flag is not specified, the
249 <code class="methodname">DB-&gt;open()</code> will fail.
250 </p>
251 </li>
252 <li>
253 <p><a id="open_DB_EXCL"></a>
254 <code class="literal">DB_EXCL</code>
255 </p>
256 <p>
257 Return an error if the database already exists. The
258 <code class="literal">DB_EXCL</code> flag is only meaningful
259 when specified with the <code class="literal">DB_CREATE</code>.
260 flag.
261 </p>
262 </li>
263 <li>
264 <p><a id="dbopen_DB_MULTIVERSION"></a>
265 <code class="literal">DB_MULTIVERSION</code>
266 </p>
267 <p>
268 Open the database with support for
269 <a href="../../programmer_reference/transapp_read.html" class="olink">
270 multiversion concurrency control</a>.
271 This will cause updates to the database to follow a
272 copy-on-write protocol, which is required to
273 support snapshot isolation. The
274 <code class="literal">DB_MULTIVERSION</code> flag requires
275 that the database be transactionally protected
276 during its open and is not supported by the queue
277 format.
278 </p>
279 </li>
280 <li>
281 <p><a id="open_DB_NOMMAP"></a>
282 <code class="literal">DB_NOMMAP</code>
283 </p>
284 <p>
285 Do not map this database into process memory (see the
286 <a class="xref" href="envset_mp_mmapsize.html" title="DB_ENV-&gt;set_mp_mmapsize()">DB_ENV-&gt;set_mp_mmapsize()</a>
287 method for further information).
288 </p>
289 </li>
290 <li>
291 <p><a id="dbopen_DB_RDONLY"></a>
292 <code class="literal">DB_RDONLY</code>
293 </p>
294 <p>
295 Open the database for reading only. Any attempt to modify
296 items in the database will fail, regardless of the actual
297 permissions of any underlying files.
298 </p>
299 </li>
300 <li>
301 <p><a id="dbopen_DB_READ_UNCOMMITTED"></a>
302 <code class="literal">DB_READ_UNCOMMITTED</code>
303 </p>
304 <p>
305 Support transactional read operations with degree 1
306 isolation. Read operations on the database may request the
307 return of modified but not yet committed data. This flag
308 must be specified on all
309 <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a>
310 handles used to perform dirty
311 reads or database updates, otherwise requests for dirty
312 reads may not be honored and the read may block.
313 </p>
314 </li>
315 <li>
316 <p><a id="open_DB_THREAD"></a>
317 <code class="literal">DB_THREAD</code>
318 </p>
319 <p>
320 Cause the <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a>
321 handle returned by
322 <code class="methodname">DB-&gt;open()</code> to be
323 <span class="emphasis"><em>free-threaded</em></span>; that is,
324 concurrently usable by multiple threads in the
325 address space.
326 </p>
327 <p>
328 Note that this flag is incompatible with the
329 <a class="link" href="dbset_lk_exclusive.html" title="DB-&gt;set_lk_exclusive()">DB-&gt;set_lk_exclusive()</a>
330 method.
331 </p>
332 </li>
333 <li>
334 <p><a id="open_DB_TRUNCATE"></a>
335 <code class="literal">DB_TRUNCATE</code>
336 </p>
337 <p>
338 Physically truncate the underlying file, discarding all
339 previous databases it might have held. Underlying filesystem
340 primitives are used to implement this flag. For this reason,
341 it is applicable only to the file and cannot be used to
342 discard databases within a file.
343 </p>
344 <p>
345 The <code class="literal">DB_TRUNCATE</code> flag cannot be lock or
346 transaction-protected, and it is an error to specify it in a
347 locking or transaction-protected environment.
348 </p>
349 </li>
350 </ul>
351 </div>
352 </div>
353 <div class="sect3" lang="en" xml:lang="en">
354 <div class="titlepage">
355 <div>
356 <div>
357 <h4 class="title"><a id="idp49923776"></a>mode</h4>
358 </div>
359 </div>
360 </div>
361 <p>
362 On Windows systems, the mode parameter is ignored.
363 </p>
364 <p>
365 On UNIX systems or in IEEE/ANSI Std 1003.1 (POSIX) environments, files
366 created by the database open are created with mode <span class="bold"><strong>mode</strong></span> (as described in <span class="bold"><strong>chmod</strong></span>(2)) and modified by the process' umask
367 value at the time of creation (see <span class="bold"><strong>umask</strong></span>(2)). Created files are owned by the
368 process owner; the group ownership of created files is based on the
369 system and directory defaults, and is not further specified by
370 Berkeley DB. System shared memory segments created by the database
371 open are created with mode <span class="bold"><strong>mode</strong></span>,
372 unmodified by the process' umask value. If <span class="bold"><strong>mode</strong></span> is 0, the database open will use a default
373 mode of readable and writable by both owner and group.
374 </p>
375 </div>
376 </div>
377 <div class="sect2" lang="en" xml:lang="en">
378 <div class="titlepage">
379 <div>
380 <div>
381 <h3 class="title"><a id="idp49898440"></a>Environment Variables</h3>
382 </div>
383 </div>
384 </div>
385 <p>
386 If the database was opened within a database environment, the
387 environment variable <span class="bold"><strong>DB_HOME</strong></span>
388 may be used as the path of the database environment home.
389 </p>
390 <p>
391 <code class="methodname">DB-&gt;open()</code> is affected by any
392 database directory specified using the
393 <a class="xref" href="envset_data_dir.html" title="DB_ENV-&gt;set_data_dir()">DB_ENV-&gt;set_data_dir()</a>
394 method, or by setting the "set_data_dir" string in the
395 environment's <a href="../../programmer_reference/env_db_config.html#env_db_config.DB_CONFIG" class="olink">DB_CONFIG</a> file.
396 </p>
397 <div class="itemizedlist">
398 <ul type="disc">
399 <li>
400 <p>
401 <span class="bold"><strong>TMPDIR</strong></span>
402 </p>
403 <p>
404 If the <span class="bold"><strong>file</strong></span> and
405 <span class="bold"><strong>dbenv</strong></span> parameters to
406 <code class="methodname">DB-&gt;open()</code> are
407 <code class="literal">NULL</code>, the environment variable
408 <span class="bold"><strong>TMPDIR</strong></span> may be used as
409 a directory in which to create temporary backing files
410 </p>
411 </li>
412 </ul>
413 </div>
414 </div>
415 <div class="sect2" lang="en" xml:lang="en">
416 <div class="titlepage">
417 <div>
418 <div>
419 <h3 class="title"><a id="idp49943400"></a>Errors</h3>
420 </div>
421 </div>
422 </div>
423 <p>
424 The <code class="methodname">DB-&gt;open()</code> <span>
425 <span>
426 method may fail and return one of the following non-zero errors:
427 </span>
428
429 </span>
430 </p>
431 <div class="sect3" lang="en" xml:lang="en">
432 <div class="titlepage">
433 <div>
434 <div>
435 <h4 class="title"><a id="idp49888936"></a>DB_LOCK_DEADLOCK</h4>
436 </div>
437 </div>
438 </div>
439 <p>
440 A transactional database environment operation was selected to resolve
441 a deadlock.
442 </p>
443 </div>
444 <div class="sect3" lang="en" xml:lang="en">
445 <div class="titlepage">
446 <div>
447 <div>
448 <h4 class="title"><a id="idp49925152"></a>DB_LOCK_NOTGRANTED</h4>
449 </div>
450 </div>
451 </div>
452 <p>
453 A Berkeley DB Concurrent Data Store database environment configured
454 for lock timeouts was unable to grant a lock in the allowed time.
455 </p>
456 <p>
457 You attempted to open a database handle that is configured
458 for no waiting exclusive locking, but the exclusive lock could not be
459 immediately obtained. See
460 <a class="xref" href="dbset_lk_exclusive.html" title="DB-&gt;set_lk_exclusive()">DB-&gt;set_lk_exclusive()</a>
461 for more information.
462 </p>
463 </div>
464 <div class="sect3" lang="en" xml:lang="en">
465 <div class="titlepage">
466 <div>
467 <div>
468 <h4 class="title"><a id="idp49896304"></a>ENOENT</h4>
469 </div>
470 </div>
471 </div>
472 <p>
473 The file or directory does not exist.
474 </p>
475 </div>
476 <div class="sect3" lang="en" xml:lang="en">
477 <div class="titlepage">
478 <div>
479 <div>
480 <h4 class="title"><a id="idp49946368"></a>ENOENT</h4>
481 </div>
482 </div>
483 </div>
484 <p>
485 A nonexistent <span class="bold"><strong>re_source</strong></span> file was specified.
486 </p>
487 </div>
488 <div class="sect3" lang="en" xml:lang="en">
489 <div class="titlepage">
490 <div>
491 <div>
492 <h4 class="title"><a id="idp49940616"></a>DB_OLD_VERSION</h4>
493 </div>
494 </div>
495 </div>
496 <p>
497 The database cannot be opened without being first upgraded.
498 </p>
499 </div>
500 <div class="sect3" lang="en" xml:lang="en">
501 <div class="titlepage">
502 <div>
503 <div>
504 <h4 class="title"><a id="idp49947592"></a>EEXIST</h4>
505 </div>
506 </div>
507 </div>
508 <p>
509 <code class="literal">DB_CREATE</code> and <code class="literal">DB_EXCL</code>
510 were specified and the database exists.
511 </p>
512 </div>
513 <div class="sect3" lang="en" xml:lang="en">
514 <div class="titlepage">
515 <div>
516 <div>
517 <h4 class="title"><a id="idp49941952"></a>EINVAL</h4>
518 </div>
519 </div>
520 </div>
521 <p>
522 If an unknown database type, page size, hash function, pad
523 byte, byte order, or a flag value or parameter that is
524 incompatible with the specified database was specified; the
525 <a class="link" href="envopen.html#envopen_DB_THREAD">DB_THREAD</a>
526 flag was specified and fast mutexes are not available for
527 this architecture; the
528 <a class="link" href="envopen.html#envopen_DB_THREAD">DB_THREAD</a>
529 flag was specified to <code class="methodname">DB-&gt;open()</code>,
530 but was not specified to the
531 <code class="methodname">DB_ENV-&gt;open()</code> call for the
532 environment in which the
533 <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a> handle was created; a
534 backing flat text file was specified with either the
535 <a class="link" href="envopen.html#envopen_DB_THREAD">DB_THREAD</a>
536 flag or the provided database environment supports
537 transaction processing; a Heap database is in use and
538 <a class="xref" href="dbset_heapsize.html" title="DB-&gt;set_heapsize()">DB-&gt;set_heapsize()</a>
539 was used to set a heap size that is different from the value
540 used to create the database or an invalid heap region size was
541 set using <a class="xref" href="dbset_heap_regionsize.html" title="DB-&gt;set_heap_regionsize()">DB-&gt;set_heap_regionsize()</a>;
542 or if an invalid flag value or parameter was specified.
543 </p>
544 </div>
545 <div class="sect3" lang="en" xml:lang="en">
546 <div class="titlepage">
547 <div>
548 <div>
549 <h4 class="title"><a id="idp49940832"></a> DB_REP_HANDLE_DEAD</h4>
550 </div>
551 </div>
552 </div>
553 <p>
554 When a client synchronizes with the master, it is possible for committed
555 transactions to be rolled back. This invalidates all the database and cursor
556 handles opened in the replication environment. Once this occurs, an attempt to use
557 such a handle will
558
559 return <code class="literal">DB_REP_HANDLE_DEAD</code>.
560 The application will need to discard the handle and open a new one in order to
561 continue processing.
562 </p>
563 </div>
564 <div class="sect3" lang="en" xml:lang="en">
565 <div class="titlepage">
566 <div>
567 <div>
568 <h4 class="title"><a id="idp49921784"></a>DB_REP_LOCKOUT</h4>
569 </div>
570 </div>
571 </div>
572 <p>
573 The operation was blocked by client/master synchronization.
574 </p>
575 </div>
576 </div>
577 <div class="sect2" lang="en" xml:lang="en">
578 <div class="titlepage">
579 <div>
580 <div>
581 <h3 class="title"><a id="idp49920752"></a>Class</h3>
582 </div>
583 </div>
584 </div>
585 <p>
586 <a class="link" href="db.html" title="Chapter 2.  The DB Handle">DB</a>
587 </p>
588 </div>
589 <div class="sect2" lang="en" xml:lang="en">
590 <div class="titlepage">
591 <div>
592 <div>
593 <h3 class="title"><a id="idp49935408"></a>See Also</h3>
594 </div>
595 </div>
596 </div>
597 <p>
598 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a>
599 </p>
600 </div>
601 </div>
602 <div class="navfooter">
603 <hr />
604 <table width="100%" summary="Navigation footer">
605 <tr>
606 <td width="40%" align="left"><a accesskey="p" href="dbkey_range.html">Prev</a> </td>
607 <td width="20%" align="center">
608 <a accesskey="u" href="db.html">Up</a>
609 </td>
610 <td width="40%" align="right"> <a accesskey="n" href="dbput.html">Next</a></td>
611 </tr>
612 <tr>
613 <td width="40%" align="left" valign="top">DB-&gt;key_range() </td>
614 <td width="20%" align="center">
615 <a accesskey="h" href="index.html">Home</a>
616 </td>
617 <td width="40%" align="right" valign="top"> DB-&gt;put()</td>
618 </tr>
619 </table>
620 </div>
621 </body>
622 </html>