[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Communications Programming Concepts

Chapter 3. New Database Manager

The New Database Manager (NDBM) subroutines maintain key and content pairs in a database. The NDBM subroutines handle large databases and access keyed items in one or two file system accesses. Keyed items are consecutive characters, taken from a data record, that identify the record and establish its order with respect to other records.

NDBM databases are stored in two files. One file is a directory containing a bit map and it has the extension .dir. The second file contains only data and has the extension .pag.

For example, Network Information Service (NIS) maps maintain database information in NDBM format. NIS maps are created using the makedbm command. The makedbm command converts input into NDBM format files. An NIS map consists of two files: map.key.pag and map.key.dir. The file with the .dir extension serves as an index for the .pag files. The file with the .pag extension contains the key and value pairs.

Note: The NDBM library replaces the earlier Database Manager (DBM) library, which managed a single database.

Using NDBM Subroutines

To access a database, issue the dbm_open subroutine. The dbm_open subroutine opens or creates the file.dir and file.pag files, depending on the flags parameter. To close a database, issue the dbm_close subroutine. Close one database before opening another database.

Other NDBM subroutines include:

dbm_delete Deletes a key and its associated contents.
dbm_fetch Accesses data stored under a key.
dbm_firstkey Returns the first key in the database.
dbm_nextkey Returns the next key in the database.
dbm_store Stores data under a key.

Diagnosing NDBM Problems

A return value of 0 indicates no error. Subroutines that return a negative value indicate an error has occurred. A positive integer return indicates the status of the return. For example, if the dbm_store subroutine, issued with an insert flag, finds an existing entry with the same key, it returns a 1.

The dbm_fetch, dbm_firstkey, and dbm_nextkey subroutines return a datum structure containing the value returned for the specified key. If the subroutine is unsuccessful, a null value is indicated in the dptr field of the datum structure.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]