glenda.party
term% ls -F
term% pwd
$home/manuals/unix_v8/3/DB
term% cat index.txt
DB(3X)                                                                  DB(3X)



NAME
       DBopen, DBclose, DBget, DBput, DBdel, DBkey0, DBkeyn, DBlock, DBunlock,
       DBsync, DBapp, DBins, DBcopy - database subroutines

SYNOPSIS
       #include <DB.h>

       typedef struct {
            char * dptr;
            int dsize;
       } datum;

       int DBdebug;

       DBFILE * DBopen(file, flags)
       char * file;
       int flags;

       datum DBget(dp, key)
       DBFILE * dp;
       datum key;

       int DBput(dp, key, content)
       DBFILE * dp;
       datum key, content;

       int DBdel(dp, key)
       DBFILE * dp;
       datum key;

       datum DBkey0(dp)
       DBFILE * dp;

       datum DBkeyn(dp, key)
       DBFILE * dp;
       datum key;

       void DBclose(dp)
       DBFILE * dp;

       int DBlock(dp)
       DBFILE * dp;

       int DBunlock(dp)
       DBFILE * dp;

       void DBsync(dp)
       DBFILE * dp;

       int DBapp(dp, key, content)
       DBFILE * dp;
       datum key, content;

       int DBins(dp, key, content)
       DBFILE * dp;
       datum key, content;

       int DBcopy(sdp, ddp)
       DBFILE * sdp, ddp;

DESCRIPTION
       These functions maintain key/content pairs in a data base.   The  func‐
       tions  will  handle databases as large as the filesystem can handle and
       will access a keyed item in one or two file system accesses.  The func‐
       tions are obtained with the loader option -lDB.

       Keys  and  contents are described by the datum typedef.  A datum speci‐
       fies a string of dsize bytes pointed  to  by  dptr.   Arbitrary  binary
       data,  as  well  as normal ASCII strings, are allowed as either keys or
       records.  The data base is stored in two files.  One file is  a  direc‐
       tory  containing  a  bit  map and has `.dir' as its suffix.  The second
       file contains all data and has `.pag' as its suffix.

       Before a database can be accessed, it must be opened by DBopen.  At the
       time  of  this  call, the files file.dir and file.pag must exist unless
       the DB_CREATE flag is set in the flags argument.  If this flag is spec‐
       ified and the files exist, they are truncated.  The only other meaning‐
       ful flag that may be specified is DB_RONLY, which indicates that the DB
       library  may  not  write  on  the  files.   If  the  files are both not
       writable, this flag need not be specified and the d_flags member of the
       returned  DBFILE pointer will have this bit set.  Note that these flags
       are mutually exclusive,  and  if  one  must  be  ignored,  it  will  be
       DB_RONLY.

       Once open, the data stored under a key is accessed by DBget and data is
       placed under a key or overwritten by DBput.  The data denoted by a  key
       may  be  appended  to,  or inserted before, by DBapp and DBins, respec‐
       tively.  A key (and its associated contents) is deleted  by  DBdel.   A
       linear  pass  through all keys in a database may be made, in an (appar‐
       ently) random order, by use of DBkey0 and DBkeyn.  DBkey0  will  return
       the  first key in the database.  With any key argument, DBkeyn will re‐
       turn the next key in the database.  This code will  traverse  the  data
       base:

              for (key = DBkey0(dp); key.dptr != NULL; key = DBkeyn(dp, key))

       DBcopy copies the data indicated by keys in the database referred to by
       its first argument to the database indicated by its second argument us‐
       ing the same traversal.

       DBlock  and DBunlock set and clear advisory locks (see ioctl(4)) on the
       database files.  DBlock returns when the lock is set  by  the  invoking
       process.

       DBsync  flushes any modified buffers, and is called by DBunlock and DB‐
       close.

DIAGNOSTICS
       All functions that return an int indicate errors with negative  values.
       A zero return indicates success.  Routines that return a datum indicate
       errors with a null (0) dptr.

       DBput will return an error in the event that a disk  block  fills  with
       inseparable data.

       Debugging  information  will be printed out on stderr if DBdebug is set
       to one of DBDBCORE, DBDBERR, DBDBWARN, or DBDBINFO.  These values  pro‐
       vide  increasing  amounts  of information, ranging from conditions that
       will cause abnormal termination  of  the  program  (DBDBCORE)  to  call
       traces of the user-accessible routines (DBDBINFO).

BUGS
       The  `.pag'  file will contain holes so that its apparent size is about
       four times its actual content.  Older UNIX systems may create real file
       blocks  for  these holes when touched.  These files cannot be copied by
       normal means (cp(1), cat(1), tp(1), tar(1), ar(1)) without  filling  in
       the  holes.  A command to permit copying of these files (with holes in‐
       tact) is provided (DBcp(1)).

       Dptr pointers returned by these subroutines point into  static  storage
       that is changed by subsequent calls.

       The sum of the sizes of a key/content pair must not exceed the internal
       block size (currently 65536 (64K) bytes).   Moreover,  all  key/content
       pairs that hash together must fit on a single block.

       DBdel  does not physically reclaim file space, although it does make it
       available for reuse.  Use DBcp(1) or DBcopy if file space must  be  re‐
       claimed.

       The  order  of keys presented by DBkey0 and DBkeyn depends on a hashing
       function, not on anything interesting.

       Since these routines use binary data for internal  housekeeping,  data‐
       bases created on a VAX cannot be directly manipulated on a 3B, and vice
       versa.  DBcvt(1) converts a database generated on either of  these  ma‐
       chines to a form palatable on the other.

SEE ALSO
       DB(1), DBcp(1), DBcvt(1).



                                                                        DB(3X)