berkeley db 保存到磁盘
berkeley db save into disk
我是berkeley db的新手,创建db的时候是这样的:
DB *dbp;
db_create(&dbp, NULL, 0);
dbp->put(dbp, NULL, &key, &data, 0);
是否将数据存储到磁盘中?如果是这样,数据库文件在哪里?据我所知,只有当我使用 DB_ENV->open()
创建数据库环境并指定参数 char *db_home
时,我才存储到真实文件中,对吗?非常感谢您的宝贵时间。
来自 Berkeley DB 规范;
To open a database, you must first use the db_create() function to initialize a DB handle. Once you have initialized the DB handle, you use its open() method to open the database.
Note that by default, DB does not create databases if they do not already exist. To override this behavior, specify the DB_CREATE flag on the open() method.
#include <db.h>
//...
DB *dbp; /* DB structure handle */
u_int32_t flags; /* database open flags */
int ret; /* function return value */
/* Initialize the structure. This
* database is not opened in an environment,
* so the environment pointer is NULL. */
ret = db_create(&dbp, NULL, 0);
if (ret != 0) {
/* Error handling goes here */
}
/* Database open flags */
flags = DB_CREATE; /* If the database does not exist,
* create it.*/
/* open the database */
ret = dbp->open(dbp, /* DB structure pointer */
NULL, /* Transaction pointer */
"my_db.db", /* On-disk file that holds the database. */
NULL, /* Optional logical database name */
DB_BTREE, /* Database access method */
flags, /* Open flags */
0); /* File mode (using defaults) */
if (ret != 0) {
/* Error handling goes here */
}
https://docs.oracle.com/cd/E17076_05/html/gsg/C/databases.html#DBOpen
我是berkeley db的新手,创建db的时候是这样的:
DB *dbp;
db_create(&dbp, NULL, 0);
dbp->put(dbp, NULL, &key, &data, 0);
是否将数据存储到磁盘中?如果是这样,数据库文件在哪里?据我所知,只有当我使用 DB_ENV->open()
创建数据库环境并指定参数 char *db_home
时,我才存储到真实文件中,对吗?非常感谢您的宝贵时间。
来自 Berkeley DB 规范;
To open a database, you must first use the db_create() function to initialize a DB handle. Once you have initialized the DB handle, you use its open() method to open the database. Note that by default, DB does not create databases if they do not already exist. To override this behavior, specify the DB_CREATE flag on the open() method.
#include <db.h>
//...
DB *dbp; /* DB structure handle */
u_int32_t flags; /* database open flags */
int ret; /* function return value */
/* Initialize the structure. This
* database is not opened in an environment,
* so the environment pointer is NULL. */
ret = db_create(&dbp, NULL, 0);
if (ret != 0) {
/* Error handling goes here */
}
/* Database open flags */
flags = DB_CREATE; /* If the database does not exist,
* create it.*/
/* open the database */
ret = dbp->open(dbp, /* DB structure pointer */
NULL, /* Transaction pointer */
"my_db.db", /* On-disk file that holds the database. */
NULL, /* Optional logical database name */
DB_BTREE, /* Database access method */
flags, /* Open flags */
0); /* File mode (using defaults) */
if (ret != 0) {
/* Error handling goes here */
}
https://docs.oracle.com/cd/E17076_05/html/gsg/C/databases.html#DBOpen