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
33 .\" $FreeBSD: src/lib/libc/db/man/dbopen.3,v 1.5 2001/10/01 16:08:50 ru Exp $
40 .Nd "database access methods"
46 .Fn dbopen "const char *file" "int flags" "int mode" "DBTYPE type" "const void *openinfo"
49 is the library interface to database files.
50 The supported file formats are btree, hashed and UNIX file oriented.
51 The btree format is a representation of a sorted, balanced tree structure.
52 The hashed format is an extensible, dynamic hashing scheme.
53 The flat-file format is a byte stream file with fixed or variable length
55 The formats and file format specific information are described in detail
56 in their respective manual pages
65 for reading and/or writing.
66 Files never intended to be preserved on disk may be created by setting
75 are as specified to the
77 routine, however, only the
78 .Dv O_CREAT , O_EXCL , O_EXLOCK , O_NONBLOCK ,
79 .Dv O_RDONLY , O_RDWR , O_SHLOCK
83 (Note, opening a database file
86 .\"Three additional options may be specified by
91 .\".Bl -tag -width indent
93 .\"Do the necessary locking in the database to support concurrent access.
94 .\"If concurrent access isn't needed or the database is read-only this
95 .\"flag should not be set, as it tends to have an associated performance
98 .\"Place the underlying memory pool used by the database in shared
100 .\"Necessary for concurrent access.
102 .\"Support transactions in the database.
107 .\"flags must be set as well.
118 .Dv DB_BTREE , DB_HASH
124 argument is a pointer to an access method specific structure described
125 in the access method's manual page.
130 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
141 structure is defined in the
143 include file, and contains at
144 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);
159 These elements describe a database type and a set of functions performing
161 These functions take a pointer to a structure as returned by
163 and sometimes one or more pointers to key/data structures and a flag value.
164 .Bl -tag -width indent
166 The type of the underlying access method (and file format).
168 A pointer to a routine to flush any cached information to disk, free any
169 allocated resources, and close the underlying file(s).
170 Since key/data pairs may be cached in memory, failing to sync the file
175 function may result in inconsistent or lost information.
177 routines return -1 on error (setting
181 A pointer to a routine to remove key/data pairs from the database.
185 may be set to the following value:
186 .Bl -tag -width indent
188 Delete the record referenced by the cursor.
189 The cursor must have previously been initialized.
193 routines return -1 on error (setting
195 0 on success, and 1 if the specified
199 A pointer to a routine which returns a file descriptor representative
200 of the underlying database.
201 A file descriptor referencing the same file will be returned to all
207 This file descriptor may be safely used as an argument to the
212 The file descriptor is not necessarily associated with any of the
213 underlying files used by the access method.
214 No file descriptor is available for in memory databases.
216 routines return -1 on error (setting
218 and the file descriptor on success.
220 A pointer to a routine which is the interface for keyed retrieval from
222 The address and length of the data associated with the specified
224 are returned in the structure referenced by
227 routines return -1 on error (setting
229 0 on success, and 1 if the
233 A pointer to a routine to store key/data pairs in the database.
237 may be set to one of the following values:
238 .Bl -tag -width indent
240 Replace the key/data pair referenced by the cursor.
241 The cursor must have previously been initialized.
243 Append the data immediately after the data referenced by
245 creating a new key/data pair.
246 The record number of the appended key/data pair is returned in the
249 (Applicable only to the
253 Insert the data immediately before the data referenced by
255 creating a new key/data pair.
256 The record number of the inserted key/data pair is returned in the
259 (Applicable only to the
263 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 only true 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.
306 A pointer to a routine which is the interface for sequential
307 retrieval from the database.
308 The address and length of the key are returned in the structure
311 and the address and length of the data are returned in the
316 Sequential key/data pair retrieval may begin at any time, and the
319 is not affected by calls to the
326 Modifications to the database during a sequential scan will be reflected
327 in the scan, i.e. records inserted behind the cursor will not be returned
328 while records inserted in front of the cursor will be returned.
334 be set to one of the following values:
335 .Bl -tag -width indent
337 The data associated with the specified key is returned.
338 This differs from the
340 routines in that it sets or initializes the cursor to the location of
344 access method, the returned key is not necessarily an
345 exact match for the specified key.
346 The returned key is the smallest key greater than or equal to the specified
347 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.
352 The last key/data pair of the database is returned, and the cursor
353 is set or initialized to reference it.
354 (Applicable only to the
360 Retrieve the key/data pair immediately after the cursor.
361 If the cursor is not yet set, this is the same as the
365 Retrieve the key/data pair immediately before the cursor.
366 If the cursor is not yet set, this is the same as the
369 (Applicable only to the
379 are available only for the
383 access methods because they each imply that the keys have an inherent
384 order which does not change.
387 routines return -1 on error (setting
389 0 on success and 1 if there are no key/data pairs less than or greater
390 than the specified or current key.
393 access method is being used, and if the database file
394 is a character special file and no complete key/data pairs are currently
399 A pointer to a routine to flush any cached information to disk.
400 If the database is in memory only, the
402 routine has no effect and will always succeed.
406 value may be set to the following value:
407 .Bl -tag -width indent
411 access method is being used, this flag causes
414 routine to apply to the btree file which underlies the
415 recno file, not the recno file itself.
420 manual page for more information.)
424 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:
440 structure are defined as follows:
441 .Bl -tag -width "data"
443 A pointer to a byte string.
445 The length of the byte string.
448 Key and data byte strings may reference strings of essentially unlimited
449 length although any two of them must fit into available memory at the same
451 It should be noted that the access methods provide no guarantees about
452 byte string alignment.
456 routine may fail and set
458 for any of the errors specified for the library routines
465 A file is incorrectly formatted.
467 A parameter has been specified (hash function, pad byte etc.) that is
468 incompatible with the current file specification or which is not
469 meaningful for the function (for example, use of the cursor without
470 prior initialization) or there is a mismatch between the version
471 number of file and the software.
476 routines may fail and set
478 for any of the errors specified for the library routines
492 routines may fail and set
494 for any of the errors specified for the library routines
503 routines will fail and set
507 for in memory databases.
511 routines may fail and set
513 for any of the errors specified for the library routine
521 .%T "LIBTP: Portable, Modular Transactions for UNIX"
524 .%R "USENIX proceedings"
531 .Dq "data base thang" ,
533 because noone could think of a reasonable name that wasn't already used.
535 The file descriptor interface is a kluge and will be deleted in a
536 future version of the interface.
538 None of the access methods provide any form of concurrent access,
539 locking, or transactions.