本文整理汇总了C++中DB_ENV::open方法的典型用法代码示例。如果您正苦于以下问题:C++ DB_ENV::open方法的具体用法?C++ DB_ENV::open怎么用?C++ DB_ENV::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB_ENV
的用法示例。
在下文中一共展示了DB_ENV::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestGetLockConflicts
int TestGetLockConflicts(CuTest *ct) {
DB_ENV *dbenv;
const u_int8_t *lk_conflicts;
int lk_modes, nmodes;
u_int8_t conflicts[40];
dbenv = NULL;
/* lk_get_lk_conflicts: NOT reset at run-time. */
ENV
memset(conflicts, 'a', sizeof(conflicts));
nmodes = 6;
CuAssertTrue(ct,
dbenv->set_lk_conflicts(dbenv, conflicts, nmodes) == 0);
CuAssertTrue(ct, dbenv->open(dbenv,
TEST_ENV, DB_CREATE | DB_INIT_LOCK, 0666) == 0);
CuAssertTrue(ct,
dbenv->get_lk_conflicts(dbenv, &lk_conflicts, &lk_modes) == 0);
CuAssertTrue(ct, lk_conflicts[0] == 'a');
CuAssertTrue(ct, lk_modes == 6);
ENV
memset(conflicts, 'b', sizeof(conflicts));
nmodes = 8;
CuAssertTrue(ct,
dbenv->set_lk_conflicts(dbenv, conflicts, nmodes) == 0);
CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0);
CuAssertTrue(ct,
dbenv->get_lk_conflicts(dbenv, &lk_conflicts, &lk_modes) == 0);
CuAssertTrue(ct, lk_conflicts[0] == 'a');
CuAssertTrue(ct, lk_modes == 6);
return (0);
}
示例2:
DB_ENV *ldbm_initialize_env(const char *home, int dbcachesize, int *envdirok)
{
DB_ENV *env = NULL;
int err;
u_int32_t envFlags;
err = db_env_create( &env, 0 );
if ( err ) {
#ifdef LDAP_SYSLOG
syslog( LOG_INFO, "ldbm_initialize_env(): "
"FATAL error in db_env_create() : %s (%d)\n",
db_strerror( err ), err );
#endif
return NULL;
}
#if DB_VERSION_X >= 0x030300
/* This interface appeared in 3.3 */
env->set_alloc( env, ldbm_malloc, NULL, NULL );
#endif
env->set_errcall( env, ldbm_db_errcall );
env->set_errpfx( env, "==>" );
if (dbcachesize) {
env->set_cachesize( env, 0, dbcachesize, 0 );
}
envFlags = DB_CREATE | DB_INIT_MPOOL | DB_USE_ENVIRON;
#ifdef DB_PRIVATE
envFlags |= DB_PRIVATE;
#endif
#ifdef DB_MPOOL_PRIVATE
envFlags |= DB_MPOOL_PRIVATE;
#endif
#ifdef HAVE_BERKELEY_DB_THREAD
envFlags |= DB_THREAD;
#endif
#if DB_VERSION_X >= 0x030100
err = env->open( env, home, envFlags, 0 );
#else
/* 3.0.x requires an extra argument */
err = env->open( env, home, NULL, envFlags, 0 );
#endif
if ( err != 0 ) {
#ifdef LDAP_SYSLOG
syslog( LOG_INFO, "ldbm_initialize_env(): "
"FATAL error in dbEnv->open() : %s (%d)\n",
db_strerror( err ), err );
#endif
env->close( env, 0 );
return NULL;
}
*envdirok = 1;
return env;
}
示例3: TestSetThreadCount
int TestSetThreadCount(CuTest *ct) { /* SKIP */
/* Run this test only when hash is supported. */
#ifdef HAVE_HASH
DB_ENV *dbenv;
DB *db;
CuAssert(ct, "db_env_create", db_env_create(&dbenv, 0) == 0);
dbenv->set_errpfx(dbenv, "TestSetThreadCount");
CuAssert(ct, "set_thread_count", dbenv->set_thread_count(dbenv, 2) == 0);
CuAssert(ct, "env->open", dbenv->open(dbenv, ".",
DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL |
DB_INIT_TXN | DB_PRIVATE | DB_THREAD, 0) == 0);
CuAssert(ct, "db_create", db_create(&db, dbenv, 0) == 0);
CuAssert(ct, "DB->open", db->open(
db, NULL, NULL, "TestSetThreadCount", DB_HASH, DB_CREATE, 0) == 0);
db->close(db, 0);
dbenv->close(dbenv, 0);
#else
printf("TestSetThreadCount is not supported by the build.\n");
#endif /* HAVE_HASH */
return (0);
}
示例4: nbsp_open_dbenv
int nbsp_open_dbenv(void){
DB_ENV *dbenv = NULL;
int status = 0;
uint32_t mb;
uint32_t dbenv_flags = DBENV_FLAGS;
mb = (1024 * 1024) * g.dbcache_mb;
status = db_env_create(&dbenv, 0);
if(status == 0)
status = dbenv->set_cachesize(dbenv, 0, mb, 0);
if(status == 0)
status = dbenv->open(dbenv, g.dbhome, dbenv_flags, g.dbfile_mode);
if(status != 0){
log_errx("Cannot initialize db environment. %s", db_strerror(status));
status = -1;
if(dbenv != NULL)
(void)dbenv->close(dbenv, 0);
}else
g.dbenv = dbenv;
return(status);
}
示例5: assert
/*
* Opens the database environment.
*
* ARGUMENTS:
* path Pathname of the database directory. Shall not be NULL.
* The client can free it upon return.
* dbEnv Pointer to a pointer to the database environment. Shall
* not be NULL. "*dbEnv" is set upon successful return.
* RETURNS:
* 0 Success. "*dbEnv" is set.
* ENOMEM System error. "log_start()" called.
* EIO Backend database error. "log_start()" called.
*/
static RegStatus
openEnvironment(
const char* const path,
DB_ENV** const dbEnv)
{
RegStatus status;
DB_ENV* env;
assert(NULL != path);
log_clear();
if (0 == (status = createEnvHandle(path, &env))) {
/*
* The database is configured for "concurrent data store"
* access rather than for transactional access because the
* former is faster and sufficient.
*/
status = env->open(env, path, DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL,
0);
if (status) {
log_add("Couldn't open environment for database \"%s\"", path);
status = EIO;
}
else {
*dbEnv = env;
}
if (status)
(void)env->close(env, 0);
} /* "env" allocated */
return status;
}
示例6:
void
bdb_open(void)
{
DB *db;
DBC *dbc;
DB_ENV *dbenv;
assert(db_env_create(&dbenv, 0) == 0);
dbenv->set_errpfx(dbenv, "bdb");
dbenv->set_errfile(dbenv, stderr);
assert(dbenv->mutex_set_max(dbenv, 10000) == 0);
assert(dbenv->set_cachesize(dbenv, 0, 50 * 1024 * 1024, 1) == 0);
assert(dbenv->open(dbenv, NULL,
DB_CREATE |
(g.c_delete_pct == 0 && g.c_insert_pct == 0 && g.c_write_pct == 0 ?
0 : DB_INIT_LOCK) |
DB_INIT_MPOOL | DB_PRIVATE, 0) == 0);
assert(db_create(&db, dbenv, 0) == 0);
if (g.c_file_type == ROW && g.c_reverse)
assert(db->set_bt_compare(db, bdb_compare_reverse) == 0);
assert(db->open(db, NULL, "__bdb", NULL, DB_BTREE, DB_CREATE, 0) == 0);
g.bdb = db;
assert(db->cursor(db, NULL, &dbc, 0) == 0);
g.dbc = dbc;
key_gen_setup(&keybuf);
}
示例7: return
static DB_ENV *dict_db_new_env(const char *db_path)
{
VSTRING *db_home_buf;
DB_ENV *dbenv;
u_int32_t cache_size_gbytes;
u_int32_t cache_size_bytes;
int ncache;
if ((errno = db_env_create(&dbenv, 0)) != 0)
msg_fatal("create DB environment: %m");
#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 7)
if ((errno = dbenv->get_cachesize(dbenv, &cache_size_gbytes,
&cache_size_bytes, &ncache)) != 0)
msg_fatal("get DB cache size: %m");
if (cache_size_gbytes == 0 && cache_size_bytes < dict_db_cache_size) {
if ((errno = dbenv->set_cache_max(dbenv, cache_size_gbytes,
dict_db_cache_size)) != 0)
msg_fatal("set DB max cache size %d: %m", dict_db_cache_size);
if ((errno = dbenv->set_cachesize(dbenv, cache_size_gbytes,
dict_db_cache_size, ncache)) != 0)
msg_fatal("set DB cache size %d: %m", dict_db_cache_size);
}
#endif
/* XXX db_home is also the default directory for the .db file. */
db_home_buf = vstring_alloc(100);
if ((errno = dbenv->open(dbenv, sane_dirname(db_home_buf, db_path),
DB_INIT_MPOOL | DB_CREATE | DB_PRIVATE, 0)) != 0)
msg_fatal("open DB environment: %m");
vstring_free(db_home_buf);
return (dbenv);
}
示例8: TestSetTransactionTimeout
int TestSetTransactionTimeout(CuTest *ct) {
DB_ENV *dbenv;
struct context *info;
FILE *msgfile;
char *path;
db_timeout_t timeout;
dbenv = NULL;
if ((path = calloc(100, sizeof(char))) == NULL)
return (ENOMEM);
snprintf(path, 100, "%s%c%s", TEST_ENV, PATH_SEPARATOR[0], "msgfile");
if ((msgfile = fopen(path, "w")) == NULL)
return (EINVAL);
info = ct->context;
info->fp = msgfile;
info->path = path;
/* txn timeout: reset at run-time. */
ENV
CuAssertTrue(ct,
dbenv->set_timeout(dbenv, 37, DB_SET_TXN_TIMEOUT) == 0);
CuAssertTrue(ct, dbenv->open(dbenv,
TEST_ENV, DB_CREATE | DB_INIT_LOCK, 0666) == 0);
CuAssertTrue(ct,
dbenv->get_timeout(dbenv, &timeout, DB_SET_TXN_TIMEOUT) == 0);
CuAssertTrue(ct, timeout == 37);
ENV
/* New transaction timeout is ignored when joining the environment. */
CuAssertTrue(ct,
dbenv->set_timeout(dbenv, 63, DB_SET_TXN_TIMEOUT) == 0);
/* Redirect the error message to suppress the warning. */
dbenv->set_msgfile(dbenv, msgfile);
CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0);
CuAssertTrue(ct,
dbenv->get_timeout(dbenv, &timeout, DB_SET_TXN_TIMEOUT) == 0);
CuAssertTrue(ct, timeout == 37);
/* Direct the error message back to the standard output. */
dbenv->set_msgfile(dbenv, NULL);
/* Re-config the transaction timeout after opening the environment. */
CuAssertTrue(ct,
dbenv->set_timeout(dbenv, 63, DB_SET_TXN_TIMEOUT) == 0);
CuAssertTrue(ct,
dbenv->get_timeout(dbenv, &timeout, DB_SET_TXN_TIMEOUT) == 0);
CuAssertTrue(ct, timeout == 63);
return (0);
}
示例9: bdblib_create_dbenv
int bdblib_create_dbenv(DB_ENV **_dbenv, char* _home)
{
DB_ENV *env;
char *progname;
int rc, flags;
progname = "kamailio";
/* Create an environment and initialize it for additional error * reporting. */
if ((rc = db_env_create(&env, 0)) != 0)
{
ERR("db_env_create failed! bdb error: %s.\n", db_strerror(rc));
return (rc);
}
env->set_errpfx(env, progname);
/* Specify the shared memory buffer pool cachesize */
if ((rc = env->set_cachesize(env, 0, _bdb_parms->cache_size, 0)) != 0)
{
ERR("dbenv set_cachsize failed! bdb error: %s.\n", db_strerror(rc));
env->err(env, rc, "set_cachesize");
goto err;
}
/* Concurrent Data Store flags */
flags = DB_CREATE |
DB_INIT_CDB |
DB_INIT_MPOOL |
DB_THREAD;
/* Transaction Data Store flags ; not supported yet */
/*
flags = DB_CREATE |
DB_RECOVER |
DB_INIT_LOG |
DB_INIT_LOCK |
DB_INIT_MPOOL |
DB_THREAD |
DB_INIT_TXN;
*/
/* Open the environment */
if ((rc = env->open(env, _home, flags, 0)) != 0)
{
ERR("dbenv is not initialized! bdb error: %s.\n",db_strerror(rc));
env->err(env, rc, "environment open: %s", _home);
goto err;
}
*_dbenv = env;
return (0);
err: (void)env->close(env, 0);
return (rc);
}
示例10: initialize_db
db* initialize_db(const char* db_name, uint32_t flag){
db* db_ptr = NULL;
DB* b_db;
DB_ENV* dbenv;
int ret;
char* full_path = NULL;
if((ret = mkdir(db_dir,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) != 0){
if(errno!=EEXIST){
err_log("DB : Dir Creation Failed\n");
goto db_init_return;
}
}
full_path = (char*)malloc(strlen(db_dir) + strlen(db_name) + 2);
mk_path(full_path, db_dir, db_name);
#ifdef ENV
if ((ret = db_env_create(&dbenv, 0)) != 0) {
dbenv->err(dbenv, ret, "Environment Created: %s", db_dir);
goto db_init_return;
}
if ((ret = dbenv->open(dbenv, db_dir, DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL|DB_THREAD, 0)) != 0) {
//dbenv->err(dbenv, ret, "Environment Open: %s", db_dir);
goto db_init_return;
}
/* Initialize the DB handle */
if((ret = db_create(&b_db,dbenv,flag)) != 0){
err_log("DB : %s.\n", db_strerror(ret));
goto db_init_return;
}
#else
/* Initialize the DB handle */
if((ret = db_create(&b_db,NULL,flag)) != 0){
err_log("DB : %s.\n", db_strerror(ret));
goto db_init_return;
}
#endif
if((ret = b_db->set_pagesize(b_db, pagesize)) != 0){
err_log("DB : %s.\n", db_strerror(ret));
goto db_init_return;
}
if((ret = b_db->open(b_db, NULL, db_name, NULL, DB_BTREE, DB_THREAD|DB_CREATE,0)) != 0){ // db_name is the on-disk file that holds the database
//b_db->err(b_db,ret,"%s","test.db");
goto db_init_return;
}
db_ptr = (db*)(malloc(sizeof(db)));
db_ptr->bdb_ptr = b_db;
db_init_return:
if(full_path != NULL){
free(full_path);
}
if(db_ptr != NULL){
;
}
return db_ptr;
}
示例11: TestSetLockMaxObjects
int TestSetLockMaxObjects(CuTest *ct) {
DB_ENV *dbenv;
u_int32_t v;
dbenv = NULL;
/* lk_max_objects: NOT reset at run-time. */
ENV
CuAssertTrue(ct, dbenv->set_lk_max_objects(dbenv, 1037) == 0);
CuAssertTrue(ct, dbenv->open(dbenv,
TEST_ENV, DB_CREATE | DB_INIT_LOCK, 0666) == 0);
CuAssertTrue(ct, dbenv->get_lk_max_objects(dbenv, &v) == 0);
CuAssertTrue(ct, v == 1037);
ENV
CuAssertTrue(ct, dbenv->set_lk_max_objects(dbenv, 1063) == 0);
CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0);
CuAssertTrue(ct, dbenv->get_lk_max_objects(dbenv, &v) == 0);
CuAssertTrue(ct, v == 1037);
return (0);
}
示例12: TestSetTxMax
int TestSetTxMax(CuTest *ct) {
DB_ENV *dbenv;
u_int32_t v;
dbenv = NULL;
/* tx_max: NOT reset at run-time. */
ENV
CuAssertTrue(ct, dbenv->set_tx_max(dbenv, 37) == 0);
CuAssertTrue(ct, dbenv->open(dbenv,
TEST_ENV, DB_CREATE | DB_INIT_TXN, 0666) == 0);
CuAssertTrue(ct, dbenv->get_tx_max(dbenv, &v) == 0);
CuAssertTrue(ct, v == 37);
ENV
CuAssertTrue(ct, dbenv->set_tx_max(dbenv, 63) == 0);
CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0);
CuAssertTrue(ct, dbenv->get_tx_max(dbenv, &v) == 0);
CuAssertTrue(ct, v == 37);
return (0);
}
示例13: TestSetLockDetect
int TestSetLockDetect(CuTest *ct) {
DB_ENV *dbenv;
u_int32_t v;
dbenv = NULL;
/* lk_detect: NOT reset at run-time. */
ENV
CuAssertTrue(ct, dbenv->set_lk_detect(dbenv, DB_LOCK_MAXLOCKS) == 0);
CuAssertTrue(ct, dbenv->open(dbenv,
TEST_ENV, DB_CREATE | DB_INIT_LOCK, 0666) == 0);
CuAssertTrue(ct, dbenv->get_lk_detect(dbenv, &v) == 0);
CuAssertTrue(ct, v == DB_LOCK_MAXLOCKS);
ENV
CuAssertTrue(ct, dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT) == 0);
CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0);
CuAssertTrue(ct, dbenv->get_lk_detect(dbenv, &v) == 0);
CuAssertTrue(ct, v == DB_LOCK_MAXLOCKS);
return (0);
}
示例14: TestSetLogRegionSize
int TestSetLogRegionSize(CuTest *ct) {
DB_ENV *dbenv;
u_int32_t v;
dbenv = NULL;
/* lg_regionmax: NOT reset at run-time. */
ENV
CuAssertTrue(ct, dbenv->set_lg_regionmax(dbenv, 137 * 1024) == 0);
CuAssertTrue(ct, dbenv->open(dbenv,
TEST_ENV, DB_CREATE | DB_INIT_LOG, 0666) == 0);
CuAssertTrue(ct, dbenv->get_lg_regionmax(dbenv, &v) == 0);
CuAssertTrue(ct, v == 137 * 1024);
ENV
CuAssertTrue(ct, dbenv->set_lg_regionmax(dbenv, 163 * 1024) == 0);
CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0);
CuAssertTrue(ct, dbenv->get_lg_regionmax(dbenv, &v) == 0);
CuAssertTrue(ct, v == 137 * 1024);
return (0);
}
示例15: TestSetCachesize
int TestSetCachesize(CuTest *ct) {
DB_ENV *dbenv;
int ncache;
u_int32_t a, b;
dbenv = NULL;
/* cache size: NOT reset at run-time. */
ENV
CuAssertTrue(ct, dbenv->set_cachesize(dbenv, 1, 131072, 3) == 0);
CuAssertTrue(ct, dbenv->open(dbenv,
TEST_ENV, DB_CREATE | DB_INIT_MPOOL, 0666) == 0);
CuAssertTrue(ct, dbenv->get_cachesize(dbenv, &a, &b, &ncache) == 0);
CuAssertTrue(ct, dbenv->get_cachesize(dbenv, &a, &b, &ncache) == 0);
CuAssertTrue(ct, a == 1 && b == 131072 && ncache == 3);
ENV
CuAssertTrue(ct, dbenv->set_cachesize(dbenv, 2, 262144, 1) == 0);
CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0);
CuAssertTrue(ct, dbenv->get_cachesize(dbenv, &a, &b, &ncache) == 0);
CuAssertTrue(ct, a == 1 && b == 131072 && ncache == 3);
return (0);
}