home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
gnu
/
man
/
cat3
/
db.0
< prev
next >
Wrap
Text File
|
1993-12-07
|
17KB
|
331 lines
btree_open, hash_open, recno_open - database access methods
##iinncclluuddee <<ssyyss//ttyyppeess..hh>>
##iinncclluuddee <<ddbb..hh>>
DDBB **
bbttrreeee__ooppeenn((ccoonnsstt cchhaarr **ffiillee,, iinntt ffllaaggss,, iinntt mmooddee,,
ccoonnsstt BBTTRREEEEIINNFFOO ** ooppeenniinnffoo));;
DDBB **
hhaasshh__ooppeenn((ccoonnsstt cchhaarr **ffiillee,, iinntt ffllaaggss,, iinntt mmooddee,,
ccoonnsstt HHAASSHHIINNFFOO ** ooppeenniinnffoo));;
DDBB **
rreeccnnoo__ooppeenn((ccoonnsstt cchhaarr **ffiillee,, iinntt ffllaaggss,, iinntt mmooddee,,
ccoonnsstt RREECCNNOOIINNFFOO ** ooppeenniinnffoo));;
and are access method interfaces to database files in btree,
hashed, and flatfile formats, respectively. The btree format is
a representation of a sorted, balanced tree structure. The
hashed format is an extensible, dynamic hashing scheme. The
flatfile format is a UNIX file with fixed or variable length
lines. These formats are described in more detail below. Access
to all file types is based on key/data pairs. Each routine opens
for reading and/or writing. Databases never intended to be pre
served on disk may be created by setting the file parameter to
NULL. The and are as specified to the routine, however, only the
O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC and O_WRONLY flags are
meaningful. The argument is a pointer to an access method spe
cific structure described below. The open routines return a
pointer to a DB structure on success and NULL on error. The DB
structure contains at least the following fields:
typedef struct {
int (*close)(const DB *db);
int (*sync)(const DB *db);
int (*del)(const DB *db, const DBT *key, u_int flags);
int (*get)(const DB *db, DBT *key, DBT *data, u_int flags);
int (*put)(const DB *db, const DBT *key, const DBT *data,
u_int flags);
int (*seq)(const DB *db, DBT *key, DBT *data, u_int flags);
int type;
void *openinfo;
} DB;
The elements of this structure consist of a pointer to an access
method specific structure and a set of routines which perform
various functions. All of these routines take a pointer to a
structure as returned by one of the open routines, one or more
pointers to key/data structures, and, optionally, a flag value.
openinfo A pointer to an internal structure specific to the ac
cess method. type The type of the underlying access method; ei
ther DB_BTREE, DB_HASH or DB_RECNO. close A pointer to a routine
to flush any cached information to disk, free any allocated re
sources, and close the database file. Since key/data pairs may
be cached in memory, failing to close the file with a routine may
result in inconsistent or lost information. routines return 1
on error (setting and 0 on success. del A pointer to a routine
to remove key/data pairs from the database. routines return 1
on error (setting 0 on success, and 1 if the specified was not in
the file. get A pointer to a routine which is the interface for
keyed retrieval from the database. The address and length of the
data associated with the specified are returned in the structure
referenced by routines return 1 on error (setting 0 on success,
and 1 if the was not in the file. put A pointer to a routine to
store key/data pairs in the database. The parameter must be set
to one of the following values: R_IAFTER Append the data immedi
ately after the data referenced by creating a new key/data pair.
(This implies that the access method is able to create new keys,
i.e. the keys are ordered and independent, for example, record
numbers. Applicable only to the access method.) R_IBEFORE In
sert the data immediately before the data referenced by creating
a new key/data pair. (This implies that the access method is
able to create new keys, i.e. the keys are ordered and indepen
dent, for example, record numbers. Applicable only to the access
method.) R_NOOVERWRITE Enter the new key/data pair only if the
key does not previously exist. R_PUT Enter the new key/data pair
and replace any previously existing key. routines return 1 on
error (setting 0 on success, and 1 if the R_NOOVERWRITE was set
and the key already exists in the file. seq A pointer to a rou
tine which is the interface for sequential retrieval from the
database. The address and length of the key are returned in the
structure referenced by and the address and length of the data
are returned in the structure referenced by Sequential key/data
pair retrieval may begin at any time, and the position of the
``cursor'' is not affected by calls to the or routines. Modifi
cations to the database during a sequential scan will be reflect
ed in the scan, i.e. records inserted behind the cursor will not
be returned while records inserted in front of the cursor will be
returned. The flag value must be set to one of the following
values: R_CURSOR The data associated with the specified key is
returned. This differs from the routines in that it sets the
``cursor'' to the location of the key as well. (This implies
that the access method has a implicit order which does not
change. Applicable only to the and access methods.) R_FIRST The
first key/data pair of the database is returned. R_LAST The last
key/data pair of the database is returned. (This implies that
the access method has a implicit order which does not change.
Applicable only to the and access methods.) R_NEXT Retrieve the
key/data pair immediately after the key/data pair most recently
retrieved using the routine. The cursor is moved to the returned
key/data pair. If is set to R_NEXT the first time the routine is
called, the first key/data pair of the database is returned.
R_PREV Retrieve the key/data pair immediately before the key/data
pair most recently retrieved using the routine. The cursor is
moved to the returned key/data pair. If is set to R_PREV the
first time the routine is called, the last key/data pair of the
database is returned. (This implies that the access method has a
implicit order which does not change. Applicable only to the and
access methods.) routines return 1 on error (setting 0 on suc
cess, 1 if there are no more key/data pairs available. If the
access method is being used, and if the database file is a char
acter special file and no complete key/data pairs are currently
available, the routines return 2. sync A pointer to a routine to
flush any cached information to disk. If the database is in mem
ory only, the routine has no effect and will always succeed.
routines return 1 on error (setting and 0 on success. Access to
all file types is based on key/data pairs. Both keys and data
are represented by the following data structure: typedef struct {
void *data;
size_t size; } DBT; The elements of the DBT structure are defined
as follows: data A pointer to a byte string. size The length of
the byte string. Key/data strings must fit into available memo
ry. One of the access methods is a btree: a sorted, balanced
tree structure with associated key/data pairs. The access method
specific data structure provided to is as follows: typedef struct
{ u_long flags;
u_int psize;
u_int cachesize;
int (*compare)(const void *, const void *);
int lorder; } BTREEINFO; The elements of this structure are de
fined as follows: flags The flag value is specified by any of the
following values: R_DUP On insertion, if the key to be inserted
already exists, permit insertion anyway. This flag permits du
plicate keys in the tree. By default, duplicates are not permit
ted, and attempts to insert them will fail. Note, the order of
retrieval of key/data pairs with duplicate keys is undefined.
cachesize A suggested maximum size, in bytes, of the memory
cache. Setting this value to zero specifies that an appropriate
amount of memory should be