当前位置: 首页>>代码示例>>C++>>正文


C++ DB_ENV::set_data_dir方法代码示例

本文整理汇总了C++中DB_ENV::set_data_dir方法的典型用法代码示例。如果您正苦于以下问题:C++ DB_ENV::set_data_dir方法的具体用法?C++ DB_ENV::set_data_dir怎么用?C++ DB_ENV::set_data_dir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB_ENV的用法示例。


在下文中一共展示了DB_ENV::set_data_dir方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: return

DB_ENV *db_setup(char *home)
{
    DB_ENV *dbenv;
    int ret;

    /* * Create an environment and initialize it for additional error * reporting. */ 
    if ((ret = db_env_create(&dbenv, 0)) != 0) { 
	return (NULL); 
    } 
    ci_debug_printf(5,"Environment created OK.\n");


//	dbenv->set_data_dir(dbenv, "");
    dbenv->set_data_dir(dbenv, home);
    ci_debug_printf(5,"Data dir set to %s.\n", home);
    /*
      dbenv->set_shm_key(dbenv, 888888L);
      ci_debug_printf(5,"Shared memory set.\n");
    */
    /* * Specify the shared memory buffer pool cachesize: 5MB. * Databases are in a subdirectory of the environment home. */ 
    //     if ((ret = dbenv->set_cachesize(dbenv, 0, 5 * 1024 * 1024, 0)) != 0) { 
    //	  dbenv->err(dbenv, ret, "set_cachesize"); 
    //	  goto err; 
    //     } 

    /* Open the environment  */ 
    if ((ret = dbenv->open(dbenv, home, DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL|DB_THREAD /*| DB_SYSTEM_MEM*/, 0)) != 0){ 
	ci_debug_printf(1, "Environment open failed: %s\n", db_strerror(ret));
	dbenv->close(dbenv, 0); 
	return NULL; 
    }
    ci_debug_printf(5,"DB setup OK.\n");


    return (dbenv);
}
开发者ID:p1rate5s,项目名称:c-icap,代码行数:36,代码来源:sguardDB.c

示例2: sizeof

/*
 *  This should be done before the program is open for business.
 *  As such, it does not need to be reentrant.
 */
int
open_db_env(char *topdir)
{
	DB_ENV		*tmpenv = NULL;
	int		st;
	struct stat64	sbuf;
	char		logdir[MAXPATHLEN+1];
	char		tmpdir[MAXPATHLEN+1];
	char		*dirarr[3];
	int		i;

	if (topdir == NULL) {
		return (-1);
	}

	snprintf(logdir, sizeof (tmpdir), "%s/.logs", topdir);
	snprintf(tmpdir, sizeof (tmpdir), "%s/.tmp", topdir);

	dirarr[0] = topdir;
	dirarr[1] = logdir;
	dirarr[2] = tmpdir;

	/* first, set up the environment */
	st = db_env_create(&tmpenv, 0);

	if (st != 0) {
		return (st);
	}

	/* make sure the directories exist */
	for (i = 0; i < 3; i++) {
		st = stat64(dirarr[i], &sbuf);
		if ((st != 0) && (errno == ENOENT)) {
			st = mkdirp(dirarr[i], 0744);
			if (st == 0) {
				st = stat64(dirarr[i], &sbuf);
			}
		}
		if ((st == 0) && (!S_ISDIR(sbuf.st_mode))) {
			st = -1;
			break;
		}
	}

	if (st != 0) {
		return (st);
	}

	st = tmpenv->set_data_dir(tmpenv, topdir);
	if (st != 0) {
		return (st);
	}
	st = tmpenv->set_lg_dir(tmpenv, logdir);
	if (st != 0) {
		return (st);
	}

	st = tmpenv->set_tmp_dir(tmpenv, tmpdir);
	if (st != 0) {
		return (st);
	}

	st = tmpenv->set_flags(tmpenv, env_fl, 1);
	if (st != 0) {
		return (st);
	}

	/* overall database cache size */
	st = tmpenv->set_cachesize(tmpenv, 0, (60 * MEGA), 1);

	st = tmpenv->set_shm_key(tmpenv, FSM_SHM_MASTER_KEY);
	if (st != 0) {
		return (st);
	}

	/* log buffer in memory */
	st = tmpenv->set_lg_bsize(tmpenv, (30 * MEGA));
	if (st != 0) {
		return (st);
	}

	/* set up additional error logging */
	tmpenv->set_errcall(tmpenv, fsmdb_log_err);

	/* Increase the number of locks available */
	tmpenv->set_lk_max_locks(tmpenv, 10000);
	tmpenv->set_lk_max_lockers(tmpenv, 10000);
	tmpenv->set_lk_max_objects(tmpenv, 10000);

	/* Increase the number of concurrent transactions available */
	/* Note:  Default in 4.4-20 is '20'.  In later versions it's 100 */
	tmpenv->set_tx_max(tmpenv, 100);

	st = tmpenv->open(tmpenv, topdir, env_ofl, 0644);
	if (st != 0) {
		/* check for a major failure */
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:samqfs,代码行数:101,代码来源:mkdb.c

示例3: main

///////////////////
//               //
// Main Function //
//               //
///////////////////
int main(int argc, char *argv[]) {

   /* Declare local vars */			/***********************************/
      DB_ENV *dbenv;				/* pointer to database environment */
      DB *dbp1;					/* pointer to 1st database         */
      DB *dbp2;					/* pointer to 2nd database         */
      DBT key1, data1;				/* Database key and data variables */
      DBT key2, data2;				/* Database key and data variables */
      int ret;					/* return code/message             */

   /* Creates the DB environment */
      if ((ret = db_env_create(&dbenv, 0)) != 0) {
         fprintf(stderr, "%s: %s\n", argv[0], db_strerror(ret));
         return(1);
      };
      dbenv->set_errfile(dbenv, stderr);
      dbenv->set_errpfx(dbenv, argv[0]);

   /* Set shared memory buffer pool cachesize: 5MB.            */
   /* Databases are in a subdirectory of the environment home. */
      if ((ret = dbenv->set_cachesize(dbenv, 0, 5 * 1024 * 1024, 0)) != 0) {
         dbenv->err(dbenv, ret, "set_cachesize");
         dbenv->close(dbenv, 0);
         return(1);
      };
      if ((ret = dbenv->set_data_dir(dbenv, MY_DBENV_DIR_DATA)) != 0) {
         dbenv->err(dbenv, ret, "set_data_dir: %s", MY_DBENV_DIR_DATA);
         dbenv->close(dbenv, 0);
         return(1);
      };

   /* Open the environment with full transactional support. */
      dbenv->open(
         dbenv, 
         MY_DBENV_DIR_HOME, 
         DB_CREATE 
         | DB_INIT_LOG 
         | DB_INIT_LOCK 
         | DB_INIT_MPOOL 
         | DB_INIT_TXN, 
         0
      );
      if (ret != 0) {
         dbenv->err(dbenv, ret, "environment open: %s", MY_DBENV_DIR_HOME);
         dbenv->close(dbenv, 0);
         return(1);
      };
      

   /* Create first Database handle */
      if ((ret = db_create(&dbp1, dbenv, 0)) != 0) {
         dbenv->err(dbenv, ret, "database create");
         dbenv->close(dbenv, 0);
         return(1);
      };

   /* Opens first database */
      if ((ret = dbp1->open(dbp1, NULL, MY_DB1_FILE, NULL, DB_BTREE, DB_CREATE, 0640)) != 0) {
         dbenv->err(dbenv, ret, "DB->open: %s", MY_DB1_FILE);
         dbp1->close(dbp1, 0);
         dbenv->close(dbenv, 0);
         return (ret);
      };

   /* Create second Database handle */
      if ((ret = db_create(&dbp2, dbenv, 0)) != 0) {
         dbenv->err(dbenv, ret, "database create");
         dbp1->close(dbp1, 0);
         dbenv->close(dbenv, 0);
         return(1);
      };

   /* Opens second database */
      if ((ret = dbp2->open(dbp2, NULL, MY_DB2_FILE, NULL, DB_BTREE, DB_CREATE, 0640)) != 0) {
         dbenv->err(dbenv, ret, "DB->open: %s", MY_DB2_FILE);
         dbp1->close(dbp1, 0);
         dbp2->close(dbp1, 0);
         dbenv->close(dbenv, 0);
         return (ret);
      };

   /* Clears variables to avoid garbage */
      memset(&key1, 0, sizeof(key1));
      memset(&data1, 0, sizeof(data1));
      memset(&key2, 0, sizeof(key2));
      memset(&data2, 0, sizeof(data2));

   /* Preps data to be added to first database */
      key1.data = "fruit";
      key1.size = sizeof("fruit");
      data1.data = "apple";
      data1.size = sizeof("apple");

   /* pushes data into first database */
      if ((ret = dbp1->put(dbp1, NULL, &key1, &data1, 0)) == 0) {
//.........这里部分代码省略.........
开发者ID:syzdek,项目名称:spear,代码行数:101,代码来源:simple-bdbenv.c


注:本文中的DB_ENV::set_data_dir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。