Opening a database is done using the Berkeley DB db_open interface.
The db_open interface takes seven arguments:
Here's what the code to call db_open looks like:
#define DATABASE "access.db"
int
main()
{
extern int errno;
DB *dbp;
if ((errno = db_open(DATABASE,
DB_BTREE, DB_CREATE, 0664, NULL, NULL, &dbp)) != 0) {
fprintf(stderr, "db: %s: %s\n", DATABASE, strerror(errno));
exit (1);
}
As you can see, we're opening a database named access.db.
The underlying database is a B+tree, and since we've specified DB_CREATE,
we'll create it if it doesn't already exist. The mode of any files we
create is 0664 (i.e., readable and writeable by the owner and the group,
and readable by everyone else).
If the call to db_open is successful, the variable dbp
will contain a database handle that will be used to access the underlying
database.
#include <sys/types.h>
#include <stdio.h>
#include <db.h>