ndbm : Linux/unix the database
< Span style= "Font-family:ar PL UKai cn,serif" >dbm/ndbm:dbm is the old version, ndbm is the new version
gdbm : GNU version
DB : Latest Version
ndbm is a SUS Standard, we take ndbm as an example.
Use ndbm need to install gdbm :
Sudoapt-get Install Libgdbm-dev
include header files: <gdbm-ndbm.h> .
link library: -lgdbm-lgdbm_compat
Use gdbm :
include header files: <gdbm.h>
link library: -lgdbm
#####################################################
#include <gdbm-ndbm.h>
typedefstruct {
Char*dptr;
Intdsize;
}datum;
dbm* Dbm_open (Constchar *filename, int file_open_flags, mode_t file_mode);
database handle returned successfully, error returned NULL .
Open the database, create Filename.pag index files and Filename.dir data files.
void Dbm_close (dbm*database_descriptor);
Close the database and release the resources.
< Span style= "Font-family:ar PL UKai cn,serif" >int dbm_store
store data, return successfully 0 , Failure returns non- 0 .
Store_mode:
Dbm_insert : Add a new record
Dbm_replace : Replace an existing record
Datum Dbm_fetch (Dbm*database_descriptor, Datum key);
gets a record from the database, returns data successfully, fails back NULL .
< Span style= "Font-family:ar PL UKai cn,serif" >int dbm_delete
Delete a record and return successfully 0 , Failure returns non- 0.
Datum Dbm_firstkey (dbm*database_descriptor);
Returns the first record of a database.
Datum Dbm_nextkey (dbm*database_descriptor);
in the call Firstkey after the call, the next record is returned.
int Dbm_error (dbm*database_descriptor);
Returns the error value.
int Dbm_clearerr (dbm*database_descriptor);
Clears the error value.
To be Continued ...
APUE:NDBM database-related library functions