APUE:NDBM database-related library functions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.