1 .\" Copyright (c) 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)dbopen.3 8.5 (Berkeley) 1/2/94
34 .TH DBOPEN 3 1994-01-02 "" "Linux Programmer's Manual"
37 dbopen \- database access methods
40 .B #include <sys/types.h>
41 .B #include <limits.h>
44 .BI "DB *dbopen(const char *" file ", int " flags ", int " mode \
46 .BI " const void *" openinfo );
50 is the library interface to database files.
51 The supported file formats are btree, hashed and UNIX file oriented.
52 The btree format is a representation of a sorted, balanced tree structure.
53 The hashed format is an extensible, dynamic hashing scheme.
54 The flat-file format is a byte stream file with fixed or variable length
56 The formats and file format specific information are described in detail
57 in their respective manual pages
66 for reading and/or writing.
67 Files never intended to be preserved on disk may be created by setting
68 the file parameter to NULL.
74 arguments are as specified to the
76 routine, however, only the
87 (Note, opening a database file
90 .\"Three additional options may be specified by
97 .\"Do the necessary locking in the database to support concurrent access.
98 .\"If concurrent access isn't needed or the database is read-only this
99 .\"flag should not be set, as it tends to have an associated performance
103 .\"Place the underlying memory pool used by the database in shared
105 .\"Necessary for concurrent access.
108 .\"Support transactions in the database.
109 .\"The DB_LOCK and DB_SHMEM flags must be set as well.
126 argument is a pointer to an access method specific structure described
127 in the access method's manual page.
130 is NULL, each access method will use defaults appropriate for the system
131 and the access method.
134 returns a pointer to a
136 structure on success and NULL on error.
139 structure is defined in the
141 include file, and contains at
142 least the following fields:
148 int (*close)(const DB *db);
149 int (*del)(const DB *db, const DBT *key, u_int flags);
150 int (*fd)(const DB *db);
151 int (*get)(const DB *db, DBT *key, DBT *data, u_int flags);
152 int (*put)(const DB *db, DBT *key, const DBT *data,
154 int (*sync)(const DB *db, u_int flags);
155 int (*seq)(const DB *db, DBT *key, DBT *data, u_int flags);
160 These elements describe a database type and a set of functions performing
162 These functions take a pointer to a structure as returned by
164 and sometimes one or more pointers to key/data structures and a flag value.
167 The type of the underlying access method (and file format).
170 A pointer to a routine to flush any cached information to disk, free any
171 allocated resources, and close the underlying file(s).
172 Since key/data pairs may be cached in memory, failing to sync the file
177 function may result in inconsistent or lost information.
179 routines return \-1 on error (setting
184 A pointer to a routine to remove key/data pairs from the database.
188 may be set to the following value:
192 Delete the record referenced by the cursor.
193 The cursor must have previously been initialized.
197 routines return \-1 on error (setting
199 0 on success, and 1 if the specified
204 A pointer to a routine which returns a file descriptor representative
205 of the underlying database.
206 A file descriptor referencing the same file will be returned to all
212 This file descriptor may be safely used as an argument to the
217 The file descriptor is not necessarily associated with any of the
218 underlying files used by the access method.
219 No file descriptor is available for in memory databases.
221 routines return \-1 on error (setting
223 and the file descriptor on success.
226 A pointer to a routine which is the interface for keyed retrieval from
228 The address and length of the data associated with the specified
230 are returned in the structure referenced by
233 routines return \-1 on error (setting
235 0 on success, and 1 if the
240 A pointer to a routine to store key/data pairs in the database.
244 may be set to one of the following values:
248 Replace the key/data pair referenced by the cursor.
249 The cursor must have previously been initialized.
252 Append the data immediately after the data referenced by
254 creating a new key/data pair.
255 The record number of the appended key/data pair is returned in the
258 (Applicable only to the
263 Insert the data immediately before the data referenced by
265 creating a new key/data pair.
266 The record number of the inserted key/data pair is returned in the
269 (Applicable only to the
274 Enter the new key/data pair only if the key does not previously exist.
277 Store the key/data pair, setting or initializing the position of the
278 cursor to reference it.
279 (Applicable only to the
287 is available only for the
292 methods because it implies that the keys have an inherent order
293 which does not change.
298 are available only for the
300 access method because they each imply that the access method is able to
302 This is only true if the keys are ordered and independent, record numbers
305 The default behavior of the
307 routines is to enter the new key/data pair, replacing any previously
311 routines return \-1 on error (setting
313 0 on success, and 1 if the
316 was set and the key already exists in the file.
319 A pointer to a routine which is the interface for sequential
320 retrieval from the database.
321 The address and length of the key are returned in the structure
324 and the address and length of the data are returned in the
329 Sequential key/data pair retrieval may begin at any time, and the
330 position of the ``cursor'' is not affected by calls to the
337 Modifications to the database during a sequential scan will be reflected
338 in the scan, that is,
339 records inserted behind the cursor will not be returned
340 while records inserted in front of the cursor will be returned.
344 be set to one of the following values:
348 The data associated with the specified key is returned.
349 This differs from the
351 routines in that it sets or initializes the cursor to the location of
355 access method, the returned key is not necessarily an
356 exact match for the specified key.
357 The returned key is the smallest key greater than or equal to the specified
358 key, permitting partial key matches and range searches.)
361 The first key/data pair of the database is returned, and the cursor
362 is set or initialized to reference it.
365 The last key/data pair of the database is returned, and the cursor
366 is set or initialized to reference it.
367 (Applicable only to the
374 Retrieve the key/data pair immediately after the cursor.
375 If the cursor is not yet set, this is the same as the
380 Retrieve the key/data pair immediately before the cursor.
381 If the cursor is not yet set, this is the same as the
384 (Applicable only to the
394 are available only for the
398 access methods because they each imply that the keys have an inherent
399 order which does not change.
402 routines return \-1 on error (setting
404 0 on success and 1 if there are no key/data pairs less than or greater
405 than the specified or current key.
408 access method is being used, and if the database file
409 is a character special file and no complete key/data pairs are currently
415 A pointer to a routine to flush any cached information to disk.
416 If the database is in memory only, the
418 routine has no effect and will always succeed.
420 The flag value may be set to the following value:
426 access method is being used, this flag causes
427 the sync routine to apply to the btree file which underlies the
428 recno file, not the recno file itself.
433 manual page for more information.)
437 routines return \-1 on error (setting
441 Access to all file types is based on key/data pairs.
442 Both keys and data are represented by the following data structure:
455 structure are defined as follows:
458 A pointer to a byte string.
461 The length of the byte string.
463 Key and data byte strings may reference strings of essentially unlimited
464 length although any two of them must fit into available memory at the same
466 It should be noted that the access methods provide no guarantees about
467 byte string alignment.
471 routine may fail and set
473 for any of the errors specified for the library routines
480 A file is incorrectly formatted.
483 A parameter has been specified (hash function, pad byte etc.) that is
484 incompatible with the current file specification or which is not
485 meaningful for the function (for example, use of the cursor without
486 prior initialization) or there is a mismatch between the version
487 number of file and the software.
491 routines may fail and set
493 for any of the errors specified for the library routines
507 routines may fail and set
509 for any of the errors specified for the library routines
518 routines will fail and set
522 for in memory databases.
526 routines may fail and set
528 for any of the errors specified for the library routine
533 is a mnemonic for ``data base thang'', and was used
534 because no-one could think of a reasonable name that wasn't already used.
536 The file descriptor interface is a kludge and will be deleted in a
537 future version of the interface.
539 None of the access methods provide any form of concurrent access,
540 locking, or transactions.
547 .IR "LIBTP: Portable, Modular Transactions for UNIX" ,
548 Margo Seltzer, Michael Olson, USENIX proceedings, Winter 1992.