1 .\" Copyright (c) 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\" must display the following acknowledgement:
15 .\" This product includes software developed by the University of
16 .\" California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)dbopen.3 8.5 (Berkeley) 1/2/94
36 .TH DBOPEN 3 2017-09-15 "" "Linux Programmer's Manual"
39 dbopen \- database access methods
42 .B #include <sys/types.h>
43 .B #include <limits.h>
47 .BI "DB *dbopen(const char *" file ", int " flags ", int " mode \
49 .BI " const void *" openinfo );
53 This page documents interfaces provided in glibc up until version 2.1.
54 Since version 2.2, glibc no longer provides these interfaces.
55 Probably, you are looking for the APIs provided by the
60 is the library interface to database files.
61 The supported file formats are btree, hashed, and UNIX file oriented.
62 The btree format is a representation of a sorted, balanced tree structure.
63 The hashed format is an extensible, dynamic hashing scheme.
64 The flat-file format is a byte stream file with fixed or variable length
66 The formats and file-format-specific information are described in detail
67 in their respective manual pages
76 for reading and/or writing.
77 Files never intended to be preserved on disk may be created by setting
86 arguments are as specified to the
88 routine, however, only the
99 (Note, opening a database file
102 .\"Three additional options may be specified by ORing
108 .\"Do the necessary locking in the database to support concurrent access.
109 .\"If concurrent access isn't needed or the database is read-only this
110 .\"flag should not be set, as it tends to have an associated performance
114 .\"Place the underlying memory pool used by the database in shared
116 .\"Necessary for concurrent access.
119 .\"Support transactions in the database.
120 .\"The DB_LOCK and DB_SHMEM flags must be set as well.
137 argument is a pointer to an access-method-specific structure described
138 in the access method's manual page.
141 is NULL, each access method will use defaults appropriate for the system
142 and the access method.
145 returns a pointer to a
147 structure on success and NULL on error.
150 structure is defined in the
152 include file, and contains at
153 least the following fields:
159 int (*close)(const DB *db);
160 int (*del)(const DB *db, const DBT *key, unsigned int flags);
161 int (*fd)(const DB *db);
162 int (*get)(const DB *db, DBT *key, DBT *data,
164 int (*put)(const DB *db, DBT *key, const DBT *data,
166 int (*sync)(const DB *db, unsigned int flags);
167 int (*seq)(const DB *db, DBT *key, DBT *data,
173 These elements describe a database type and a set of functions performing
175 These functions take a pointer to a structure as returned by
177 and sometimes one or more pointers to key/data structures and a flag value.
180 The type of the underlying access method (and file format).
183 A pointer to a routine to flush any cached information to disk, free any
184 allocated resources, and close the underlying file(s).
185 Since key/data pairs may be cached in memory, failing to sync the file
190 function may result in inconsistent or lost information.
192 routines return \-1 on error (setting
197 A pointer to a routine to remove key/data pairs from the database.
201 may be set to the following value:
205 Delete the record referenced by the cursor.
206 The cursor must have previously been initialized.
210 routines return \-1 on error (setting
212 0 on success, and 1 if the specified
217 A pointer to a routine which returns a file descriptor representative
218 of the underlying database.
219 A file descriptor referencing the same file will be returned to all
225 This file descriptor may be safely used as an argument to the
230 The file descriptor is not necessarily associated with any of the
231 underlying files used by the access method.
232 No file descriptor is available for in memory databases.
234 routines return \-1 on error (setting
236 and the file descriptor on success.
239 A pointer to a routine which is the interface for keyed retrieval from
241 The address and length of the data associated with the specified
243 are returned in the structure referenced by
246 routines return \-1 on error (setting
248 0 on success, and 1 if the
253 A pointer to a routine to store key/data pairs in the database.
257 may be set to one of the following values:
261 Replace the key/data pair referenced by the cursor.
262 The cursor must have previously been initialized.
265 Append the data immediately after the data referenced by
267 creating a new key/data pair.
268 The record number of the appended key/data pair is returned in the
271 (Applicable only to the
276 Insert the data immediately before the data referenced by
278 creating a new key/data pair.
279 The record number of the inserted key/data pair is returned in the
282 (Applicable only to the
287 Enter the new key/data pair only if the key does not previously exist.
290 Store the key/data pair, setting or initializing the position of the
291 cursor to reference it.
292 (Applicable only to the
300 is available only for the
305 methods because it implies that the keys have an inherent order
306 which does not change.
311 are available only for the
313 access method because they each imply that the access method is able to
315 This is true only if the keys are ordered and independent, record numbers
318 The default behavior of the
320 routines is to enter the new key/data pair, replacing any previously
324 routines return \-1 on error (setting
326 0 on success, and 1 if the
329 was set and the key already exists in the file.
332 A pointer to a routine which is the interface for sequential
333 retrieval from the database.
334 The address and length of the key are returned in the structure
337 and the address and length of the data are returned in the
342 Sequential key/data pair retrieval may begin at any time, and the
343 position of the "cursor" is not affected by calls to the
350 Modifications to the database during a sequential scan will be reflected
351 in the scan, that is,
352 records inserted behind the cursor will not be returned
353 while records inserted in front of the cursor will be returned.
357 be set to one of the following values:
361 The data associated with the specified key is returned.
362 This differs from the
364 routines in that it sets or initializes the cursor to the location of
368 access method, the returned key is not necessarily an
369 exact match for the specified key.
370 The returned key is the smallest key greater than or equal to the specified
371 key, permitting partial key matches and range searches.)
374 The first key/data pair of the database is returned, and the cursor
375 is set or initialized to reference it.
378 The last key/data pair of the database is returned, and the cursor
379 is set or initialized to reference it.
380 (Applicable only to the
387 Retrieve the key/data pair immediately after the cursor.
388 If the cursor is not yet set, this is the same as the
393 Retrieve the key/data pair immediately before the cursor.
394 If the cursor is not yet set, this is the same as the
397 (Applicable only to the
407 are available only for the
411 access methods because they each imply that the keys have an inherent
412 order which does not change.
415 routines return \-1 on error (setting
417 0 on success and 1 if there are no key/data pairs less than or greater
418 than the specified or current key.
421 access method is being used, and if the database file
422 is a character special file and no complete key/data pairs are currently
428 A pointer to a routine to flush any cached information to disk.
429 If the database is in memory only, the
431 routine has no effect and will always succeed.
433 The flag value may be set to the following value:
439 access method is being used, this flag causes
440 the sync routine to apply to the btree file which underlies the
441 recno file, not the recno file itself.
446 manual page for more information.)
450 routines return \-1 on error (setting
454 Access to all file types is based on key/data pairs.
455 Both keys and data are represented by the following data structure:
468 structure are defined as follows:
471 A pointer to a byte string.
474 The length of the byte string.
476 Key and data byte strings may reference strings of essentially unlimited
477 length although any two of them must fit into available memory at the same
479 It should be noted that the access methods provide no guarantees about
480 byte string alignment.
484 routine may fail and set
486 for any of the errors specified for the library routines
493 A file is incorrectly formatted.
496 A parameter has been specified (hash function, pad byte, etc.) that is
497 incompatible with the current file specification or which is not
498 meaningful for the function (for example, use of the cursor without
499 prior initialization) or there is a mismatch between the version
500 number of file and the software.
504 routines may fail and set
506 for any of the errors specified for the library routines
520 routines may fail and set
522 for any of the errors specified for the library routines
531 routines will fail and set
535 for in memory databases.
539 routines may fail and set
541 for any of the errors specified for the library routine
546 is a mnemonic for "data base thang", and was used
547 because no one could think of a reasonable name that wasn't already used.
549 The file descriptor interface is a kludge and will be deleted in a
550 future version of the interface.
552 None of the access methods provide any form of concurrent access,
553 locking, or transactions.
560 .IR "LIBTP: Portable, Modular Transactions for UNIX" ,
561 Margo Seltzer, Michael Olson, USENIX proceedings, Winter 1992.