1 .\" Copyright (c) 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" SPDX-License-Identifier: BSD-4-Clause-UC
6 .\" @(#)dbopen.3 8.5 (Berkeley) 1/2/94
8 .TH DBOPEN 3 2017-09-15 "Linux man-pages (unreleased)"
11 dbopen \- database access methods
14 .RI ( libc ", " \-lc )
17 .B #include <sys/types.h>
18 .B #include <limits.h>
22 .BI "DB *dbopen(const char *" file ", int " flags ", int " mode \
24 .BI " const void *" openinfo );
28 This page documents interfaces provided in glibc up until version 2.1.
29 Since version 2.2, glibc no longer provides these interfaces.
30 Probably, you are looking for the APIs provided by the
35 is the library interface to database files.
36 The supported file formats are btree, hashed, and UNIX file oriented.
37 The btree format is a representation of a sorted, balanced tree structure.
38 The hashed format is an extensible, dynamic hashing scheme.
39 The flat-file format is a byte stream file with fixed or variable length
41 The formats and file-format-specific information are described in detail
42 in their respective manual pages
51 for reading and/or writing.
52 Files never intended to be preserved on disk may be created by setting
61 arguments are as specified to the
63 routine, however, only the
74 (Note, opening a database file
77 .\"Three additional options may be specified by ORing
83 .\"Do the necessary locking in the database to support concurrent access.
84 .\"If concurrent access isn't needed or the database is read-only this
85 .\"flag should not be set, as it tends to have an associated performance
89 .\"Place the underlying memory pool used by the database in shared
91 .\"Necessary for concurrent access.
94 .\"Support transactions in the database.
95 .\"The DB_LOCK and DB_SHMEM flags must be set as well.
112 argument is a pointer to an access-method-specific structure described
113 in the access method's manual page.
116 is NULL, each access method will use defaults appropriate for the system
117 and the access method.
120 returns a pointer to a
122 structure on success and NULL on error.
125 structure is defined in the
127 include file, and contains at
128 least the following fields:
134 int (*close)(const DB *db);
135 int (*del)(const DB *db, const DBT *key, unsigned int flags);
136 int (*fd)(const DB *db);
137 int (*get)(const DB *db, DBT *key, DBT *data,
139 int (*put)(const DB *db, DBT *key, const DBT *data,
141 int (*sync)(const DB *db, unsigned int flags);
142 int (*seq)(const DB *db, DBT *key, DBT *data,
148 These elements describe a database type and a set of functions performing
150 These functions take a pointer to a structure as returned by
152 and sometimes one or more pointers to key/data structures and a flag value.
155 The type of the underlying access method (and file format).
158 A pointer to a routine to flush any cached information to disk, free any
159 allocated resources, and close the underlying file(s).
160 Since key/data pairs may be cached in memory, failing to sync the file
165 function may result in inconsistent or lost information.
167 routines return \-1 on error (setting
172 A pointer to a routine to remove key/data pairs from the database.
176 may be set to the following value:
180 Delete the record referenced by the cursor.
181 The cursor must have previously been initialized.
185 routines return \-1 on error (setting
187 0 on success, and 1 if the specified
192 A pointer to a routine which returns a file descriptor representative
193 of the underlying database.
194 A file descriptor referencing the same file will be returned to all
200 This file descriptor may be safely used as an argument to the
205 The file descriptor is not necessarily associated with any of the
206 underlying files used by the access method.
207 No file descriptor is available for in memory databases.
209 routines return \-1 on error (setting
211 and the file descriptor on success.
214 A pointer to a routine which is the interface for keyed retrieval from
216 The address and length of the data associated with the specified
218 are returned in the structure referenced by
221 routines return \-1 on error (setting
223 0 on success, and 1 if the
228 A pointer to a routine to store key/data pairs in the database.
232 may be set to one of the following values:
236 Replace the key/data pair referenced by the cursor.
237 The cursor must have previously been initialized.
240 Append the data immediately after the data referenced by
242 creating a new key/data pair.
243 The record number of the appended key/data pair is returned in the
246 (Applicable only to the
251 Insert the data immediately before the data referenced by
253 creating a new key/data pair.
254 The record number of the inserted key/data pair is returned in the
257 (Applicable only to the
262 Enter the new key/data pair only if the key does not previously exist.
265 Store the key/data pair, setting or initializing the position of the
266 cursor to reference it.
267 (Applicable only to the
275 is available only for the
280 methods because it implies that the keys have an inherent order
281 which does not change.
286 are available only for the
288 access method because they each imply that the access method is able to
290 This is true only if the keys are ordered and independent, record numbers
293 The default behavior of the
295 routines is to enter the new key/data pair, replacing any previously
299 routines return \-1 on error (setting
301 0 on success, and 1 if the
304 was set and the key already exists in the file.
307 A pointer to a routine which is the interface for sequential
308 retrieval from the database.
309 The address and length of the key are returned in the structure
312 and the address and length of the data are returned in the
317 Sequential key/data pair retrieval may begin at any time, and the
318 position of the "cursor" is not affected by calls to the
325 Modifications to the database during a sequential scan will be reflected
326 in the scan, that is,
327 records inserted behind the cursor will not be returned
328 while records inserted in front of the cursor will be returned.
332 be set to one of the following values:
336 The data associated with the specified key is returned.
337 This differs from the
339 routines in that it sets or initializes the cursor to the location of
343 access method, the returned key is not necessarily an
344 exact match for the specified key.
345 The returned key is the smallest key greater than or equal to the specified
346 key, permitting partial key matches and range searches.)
349 The first key/data pair of the database is returned, and the cursor
350 is set or initialized to reference it.
353 The last key/data pair of the database is returned, and the cursor
354 is set or initialized to reference it.
355 (Applicable only to the
362 Retrieve the key/data pair immediately after the cursor.
363 If the cursor is not yet set, this is the same as the
368 Retrieve the key/data pair immediately before the cursor.
369 If the cursor is not yet set, this is the same as the
372 (Applicable only to the
382 are available only for the
386 access methods because they each imply that the keys have an inherent
387 order which does not change.
390 routines return \-1 on error (setting
392 0 on success and 1 if there are no key/data pairs less than or greater
393 than the specified or current key.
396 access method is being used, and if the database file
397 is a character special file and no complete key/data pairs are currently
403 A pointer to a routine to flush any cached information to disk.
404 If the database is in memory only, the
406 routine has no effect and will always succeed.
408 The flag value may be set to the following value:
414 access method is being used, this flag causes
415 the sync routine to apply to the btree file which underlies the
416 recno file, not the recno file itself.
421 manual page for more information.)
425 routines return \-1 on error (setting
429 Access to all file types is based on key/data pairs.
430 Both keys and data are represented by the following data structure:
443 structure are defined as follows:
446 A pointer to a byte string.
449 The length of the byte string.
451 Key and data byte strings may reference strings of essentially unlimited
452 length although any two of them must fit into available memory at the same
454 It should be noted that the access methods provide no guarantees about
455 byte string alignment.
459 routine may fail and set
461 for any of the errors specified for the library routines
468 A file is incorrectly formatted.
471 A parameter has been specified (hash function, pad byte, etc.) that is
472 incompatible with the current file specification or which is not
473 meaningful for the function (for example, use of the cursor without
474 prior initialization) or there is a mismatch between the version
475 number of file and the software.
479 routines may fail and set
481 for any of the errors specified for the library routines
495 routines may fail and set
497 for any of the errors specified for the library routines
506 routines will fail and set
510 for in memory databases.
514 routines may fail and set
516 for any of the errors specified for the library routine
521 is a mnemonic for "data base thang", and was used
522 because no one could think of a reasonable name that wasn't already used.
524 The file descriptor interface is a kludge and will be deleted in a
525 future version of the interface.
527 None of the access methods provide any form of concurrent access,
528 locking, or transactions.
535 .IR "LIBTP: Portable, Modular Transactions for UNIX" ,
536 Margo Seltzer, Michael Olson, USENIX proceedings, Winter 1992.