gpt4 book ai didi

c - berkeley db 保存到磁盘

转载 作者:太空宇宙 更新时间:2023-11-04 02:36:13 24 4
gpt4 key购买 nike

我是 berkeley db 的新手,当我以这种方式创建数据库时:

DB *dbp;

db_create(&dbp, NULL, 0);


dbp->put(dbp, NULL, &key, &data, 0);

我是否将数据存储到磁盘中?如果是这样,数据库文件在哪里?据我所知,只有当我使用 DB_EN​​V->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

关于c - berkeley db 保存到磁盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36947325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com