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


C++ DB::open方法代码示例

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


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

示例1: spoolbdb_open_rdonly

static int spoolbdb_open_rdonly(DB **db, DB_ENV *dbenv, char *dbfname,
				int f_mpool_nofile){
  /*
   * If f_mpool_nofile is set, we are opening a shared memory db, otherwise
   * it is a normal db.
   */
  DB *dbp = NULL;
  int status = 0;
  uint32_t dbflags = SPOOLBDB_FLAGS_RDONLY;

  if((dbenv == NULL) || (dbfname == NULL))
      return(EINVAL);

  status = db_create(&dbp, dbenv, 0);
  if(status != 0)
    return(status);

  if(f_mpool_nofile != 0)
    status = dbp->open(dbp, NULL, NULL, dbfname, DB_BTREE, dbflags, 0);
  else
    status = dbp->open(dbp, NULL, dbfname, NULL, DB_BTREE, dbflags, 0);

  if(status != 0){
    if(dbp != NULL)
    (void)dbp->close(dbp, 0);
  }else
    *db = dbp;

  return(status);
}
开发者ID:Adnan-Polewall,项目名称:nbsp,代码行数:30,代码来源:spoolbdb.c

示例2: int

DB *sg_open_db(DB_ENV *dbenv, char *filename,
	       int (*bt_compare_fcn)(DB *, const DBT *, const DBT *) )
{
    int ret;
    DB *dbp = NULL;

    if ((ret = db_create(&dbp, dbenv , 0)) != 0) {
	ci_debug_printf(1, "db_create: %s\n", db_strerror(ret));
	return NULL;
    }
    //     dbp->set_flags(dbp, DB_DUP);
    dbp->set_bt_compare(dbp, bt_compare_fcn);


#if(DB_VERSION_MINOR>=1)
    if ((ret = dbp->open( dbp, NULL, filename, NULL,
			  DB_BTREE, DB_RDONLY|DB_THREAD, 0)) != 0)
#else
	if ((ret = dbp->open( dbp, filename, NULL,
			      DB_BTREE, DB_RDONLY, 0)) != 0)
#endif
	{
	    ci_debug_printf(1, "open db %s: %s\n", filename, db_strerror(ret));
	    dbp->close(dbp, 0);
	    return NULL;
	}
    return dbp;
}
开发者ID:p1rate5s,项目名称:c-icap,代码行数:28,代码来源:sguardDB.c

示例3: TestPartOneKeyNoData

int TestPartOneKeyNoData(CuTest *ct) {
	DB_ENV *dbenv;
	DB *dbp;
	/* Allocate the memory from stack. */
	DBT keys[4];
	u_int32_t i;

	dbenv = NULL;
	dbp = NULL;
	nparts = 5;

	/* Do not assign any data to the first DBT. */
	memset(&keys[0], 0, sizeof(DBT));
	for (i = 1 ; i < (nparts - 1); i++) {
		memset(&keys[i], 0, sizeof(DBT));
		keys[i].data = &content[(i + 1) * (strlen(content) / nparts)];
		keys[i].size = sizeof(char);
	}

	/* Do not set any database flags. */
	CuAssertTrue(ct, create_db(&dbenv, &dbp, 0, ct) == 0);
	/*
	 * Verify that before the database is opened, DB->set_partition can
	 * be called multiple times regardless of its return code.
	 */
	keys[0].flags = DB_DBT_MALLOC;
	CuAssertTrue(ct, dbp->set_partition(dbp, nparts, keys, NULL) != 0);
	keys[0].flags = 0;
	CuAssertTrue(ct, dbp->set_partition(dbp, nparts, keys, NULL) == 0);
	CuAssertTrue(ct, dbp->set_partition(dbp, nparts, keys, NULL) == 0);
	CuAssertTrue(ct, dbp->open(dbp, NULL,
	    "test.db", NULL, DB_BTREE, DB_CREATE, 0644) != 0);
	CuAssertTrue(ct, close_db(dbenv, dbp, ct) == 0);
	fclose(errfp);
	errfp = NULL;

	/* Set DB_DUPSORT flags. */
	setup_envdir(TEST_ENV, 1);
	errfp = fopen("TESTDIR/errfile", "w");
	CuAssertTrue(ct, create_db(&dbenv, &dbp, 0, ct) == 0);
	CuAssertTrue(ct, dbp->set_partition(dbp, nparts, keys, NULL) == 0);
	CuAssertTrue(ct, dbp->set_flags(dbp, DB_DUPSORT) == 0);
	CuAssertTrue(ct, dbp->open(dbp, NULL,
	    "test.db", NULL, DB_BTREE, DB_CREATE, 0644) != 0);
	CuAssertTrue(ct, close_db(dbenv, dbp, ct) == 0);
	fclose(errfp);
	errfp = NULL;

	/* Set DB_DUP flags. */
	setup_envdir(TEST_ENV, 1);
	CuAssertTrue(ct, create_db(&dbenv, &dbp, 0, ct) == 0);
	CuAssertTrue(ct, dbp->set_partition(dbp, nparts, keys, NULL) == 0);
	CuAssertTrue(ct, dbp->set_flags(dbp, DB_DUP) == 0);
	CuAssertTrue(ct, dbp->open(dbp, NULL,
	    "test.db", NULL, DB_BTREE, DB_CREATE, 0644) == 0);
	CuAssertTrue(ct, put_data(dbp) == 0);
	CuAssertTrue(ct, close_db(dbenv, dbp, ct) == 0);
	return (0);
}
开发者ID:tux-mind,项目名称:platform_external_bdb,代码行数:59,代码来源:TestPartition.c

示例4: mail_cache_db_open

int mail_cache_db_open(const char * filename,
    struct mail_cache_db ** pcache_db)
{
#if DBVERS >= 1
  DB * dbp;
#if DBVERS > 1
  int r;
#endif
  struct mail_cache_db * cache_db;

#if DB_VERSION_MAJOR >= 3
  r = db_create(&dbp, NULL, 0);
  if (r != 0)
    goto err;

#if (DB_VERSION_MAJOR >= 4) && ((DB_VERSION_MAJOR > 4) || (DB_VERSION_MINOR >= 1))
  r = dbp->open(dbp, NULL, filename, NULL, DB_BTREE, DB_CREATE,
      S_IRUSR | S_IWUSR);
#else
  r = dbp->open(dbp, filename, NULL, DB_BTREE, DB_CREATE, S_IRUSR | S_IWUSR);
#endif
  if (r != 0)
    goto close_db;
#else
#if DBVERS > 1  
  r = db_open(filename, DB_BTREE, DB_CREATE, S_IRUSR | S_IWUSR,
      NULL, NULL, &dbp);
  if (r != 0)
    goto err;
#elif DBVERS == 1
  dbp = dbopen(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, DB_BTREE, NULL);
  if (dbp == NULL)
    goto err;
#else
  goto err;
#endif  
#endif

  cache_db = mail_cache_db_new(dbp);
  if (cache_db == NULL)
    goto close_db;
  
  * pcache_db = cache_db;

  return 0;

 close_db:
#if DBVERS > 1  
  dbp->close(dbp, 0);
#elif DBVERS == 1
  dbp->close(dbp);
#endif
 err:
  return -1;
#else
  return -1;
#endif
}
开发者ID:mralexgray,项目名称:etPanKit,代码行数:58,代码来源:mail_cache_db.c

示例5: TestPartUnsortedKey

int TestPartUnsortedKey(CuTest *ct) {
	DB_ENV *dbenv;
	DB *dbp;
	DBT *keys;
	u_int32_t i, indx;

	dbenv = NULL;
	dbp = NULL;
	keys = NULL;
	nparts = 6;

	CuAssertTrue(ct, (keys = malloc((nparts - 1) * sizeof(DBT))) != NULL);
	memset(keys, 0, (nparts - 1) * sizeof(DBT));
	/* Assign unsorted keys to the array. */
	for (i = 0, indx = 0; i < (nparts - 1); i++) {
		if (i == (nparts - 2) && i % 2 == 0)
			indx = i;
		else if (i % 2 != 0)
			indx = i - 1;
		else
			indx = i + 1;
		keys[i].data =
		    &content[(indx + 1) * (strlen(content) / nparts)];
		keys[i].size = sizeof(char);
	}

	CuAssertTrue(ct, create_db(&dbenv, &dbp, 0, ct) == 0);
	CuAssertTrue(ct,
	    dbp->set_partition(dbp, nparts - 1, &keys[1], NULL) == 0);
	CuAssertTrue(ct, dbp->open(dbp, NULL,
	    "test.db", NULL, DB_BTREE, DB_CREATE, 0644) == 0);
	CuAssertTrue(ct, put_data(dbp) == 0);
	CuAssertTrue(ct, dbp->close(dbp, 0) == 0);

	/*
	 * Reconfig with a different partition number and
	 * re-open the database.
	 */
	CuAssertTrue(ct, db_create(&dbp, dbenv, 0) == 0);
	CuAssertTrue(ct, dbp->set_partition(dbp, nparts, keys, NULL) == 0);
	CuAssertTrue(ct, dbp->open(dbp, NULL,
	    "test.db", NULL, DB_BTREE, 0, 0644) != 0);
	CuAssertTrue(ct, dbp->close(dbp, 0) == 0);

	/*
	 * Reconfig with a different set of partition keys and
	 * re-open the database.
	 */
	CuAssertTrue(ct, db_create(&dbp, dbenv, 0) == 0);
	CuAssertTrue(ct, dbp->set_partition(dbp, nparts - 1, keys, NULL) == 0);
	CuAssertTrue(ct, dbp->open(dbp, NULL,
	    "test.db", NULL, DB_BTREE, 0, 0644) != 0);
	CuAssertTrue(ct, close_db(dbenv, dbp, ct) == 0);
	free(keys);
	return (0);
}
开发者ID:tux-mind,项目名称:platform_external_bdb,代码行数:56,代码来源:TestPartition.c

示例6: TestPartDuplicatedKey

int TestPartDuplicatedKey(CuTest *ct) {
	DB_ENV *dbenv;
	DB *dbp;
	DBT *keys;
	u_int32_t i;

	dbenv = NULL;
	dbp = NULL;
	keys = NULL;
	nparts = 5;

	CuAssertTrue(ct, (keys = malloc((nparts - 1) * sizeof(DBT))) != NULL);
	memset(keys, 0, (nparts - 1) * sizeof(DBT));
	/* Assign the same data to the first 2 DBTs. */
	for (i = 0 ; i < (nparts - 1); i++) {
		if (i < 2)
			keys[i].data = &content[strlen(content) / nparts];
		else
			keys[i].data = &content[(i + 1) *
			    (strlen(content) / nparts)];
		keys[i].size = sizeof(char);
	}

	/* Do not set any database flags. */
	CuAssertTrue(ct, create_db(&dbenv, &dbp, 0, ct) == 0);
	CuAssertTrue(ct, dbp->set_partition(dbp, nparts, keys, NULL) == 0);
	CuAssertTrue(ct, dbp->open(dbp, NULL,
	    "test.db", NULL, DB_BTREE, DB_CREATE, 0644) != 0);
	CuAssertTrue(ct, close_db(dbenv, dbp, ct) == 0);
	fclose(errfp);
	errfp = NULL;

	/* Set DB_DUPSORT flags. */
	setup_envdir(TEST_ENV, 1);
	errfp = fopen("TESTDIR/errfile", "w");
	CuAssertTrue(ct, create_db(&dbenv, &dbp, 0, ct) == 0);
	CuAssertTrue(ct, dbp->set_partition(dbp, nparts, keys, NULL) == 0);
	CuAssertTrue(ct, dbp->set_flags(dbp, DB_DUPSORT) == 0);
	CuAssertTrue(ct, dbp->open(dbp, NULL,
	    "test.db", NULL, DB_BTREE, DB_CREATE, 0644) != 0);
	CuAssertTrue(ct, close_db(dbenv, dbp, ct) == 0);
	fclose(errfp);
	errfp = NULL;

	/* Set DB_DUP flags. */
	setup_envdir(TEST_ENV, 1);
	CuAssertTrue(ct, create_db(&dbenv, &dbp, 0, ct) == 0);
	CuAssertTrue(ct, dbp->set_partition(dbp, nparts, keys, NULL) == 0);
	CuAssertTrue(ct, dbp->set_flags(dbp, DB_DUP) == 0);
	CuAssertTrue(ct, dbp->open(dbp, NULL,
	    "test.db", NULL, DB_BTREE, DB_CREATE, 0644) == 0);
	CuAssertTrue(ct, put_data(dbp) == 0);
	CuAssertTrue(ct, close_db(dbenv, dbp, ct) == 0);
	free(keys);
	return (0);
}
开发者ID:tux-mind,项目名称:platform_external_bdb,代码行数:56,代码来源:TestPartition.c

示例7: spoolbdb_open_create

static int spoolbdb_open_create(DB **db, DB_ENV *dbenv,
				char *dbfname, int dbmode,
				int f_mpool_nofile){
  /*
   * If dbfname == NULL, then it is an in-memory (private) bdb.
   * If dbfname != NULL, then if the flag f_mpool_nofile is 1 the db
   * is configured as shared memory db or a normal db if the flag is 0.
   */
  DB *dbp = NULL;
  DB_MPOOLFILE *mpf = NULL;
  int status = 0;
  uint32_t dbflags = SPOOLBDB_FLAGS_CREATE;

  if(dbenv == NULL)
    return(EINVAL);

  /*
   * Let the user know that this combination is not valid.
   */
  if((dbfname == NULL) && (f_mpool_nofile == 0))
    return(EINVAL);

  status = db_create(&dbp, dbenv, 0);
  if(status != 0)
    return(status);

  if((dbfname == NULL) || (f_mpool_nofile == 1)){
    /*
     * Private or shared memory db.
     */
    mpf = dbp->get_mpf(dbp);
    status = mpf->set_flags(mpf, DB_MPOOL_NOFILE, 1);
  }

  if(status == 0){
    if(dbfname == NULL)
      status = dbp->open(dbp, NULL, NULL, NULL, DB_BTREE, dbflags, dbmode);
    else if(f_mpool_nofile != 0)
      status = dbp->open(dbp, NULL, NULL, dbfname, DB_BTREE, dbflags, dbmode);
    else
      status = dbp->open(dbp, NULL, dbfname, NULL, DB_BTREE, dbflags, dbmode);
  }

#if 0
  dbp->set_errcall(dbp, XXX_db_errcall_fcn); /* XXX */
#endif

  if(status != 0){
    if(dbp != NULL)
    (void)dbp->close(dbp, 0);
  }else
    *db = dbp;

  return(status);
}
开发者ID:Adnan-Polewall,项目名称:nbsp,代码行数:55,代码来源:spoolbdb.c

示例8: TRACE

char *smf_lookup_db4_query(char *database, char *key) {
    DB *dbp;
    DBT db_key, db_value;
    int ret;
    char *db_res = NULL;

    /* initialize db4 */
    if ((ret = db_create(&dbp, NULL, 0)) != 0) {
        TRACE(TRACE_ERR, "db_create: %s\n", db_strerror(ret));
        return NULL;
    }

    TRACE(TRACE_LOOKUP, "[%p] lookup key [%s]", dbp,key);

    if ((ret = dbp->set_pagesize(dbp, 1024)) != 0) {
        TRACE(TRACE_WARNING, "DB (%s): %s", database, db_strerror(ret));
    }
    if ((ret = dbp->set_cachesize(dbp, 0, 32 * 1024, 0)) != 0) {
        TRACE(TRACE_WARNING, "DB (%s): %s", database, db_strerror(ret));
    }

    /* open db */
#if DB_VERSION_MAJOR >= 4 && DB_VERSION_MINOR < 1
    if ((ret = dbp->open(dbp, database, NULL, DB_HASH, DB_RDONLY, 0)) != 0) {
        TRACE(TRACE_ERR, "DB (%s): %s", database, db_strerror(ret));
        return NULL;
    }
#else
    if ((ret = dbp->open(dbp, NULL, database, NULL, DB_HASH, DB_RDONLY, 0)) != 0) {
        TRACE(TRACE_ERR,"DB (%s): %s", database, db_strerror(ret));
        return NULL;
    }
#endif
    else {
        TRACE(TRACE_DEBUG, "DB (%s): open", database);
    }

    memset(&db_key, 0, sizeof(DBT));
    memset(&db_value, 0, sizeof(DBT));
    db_key.data = (void *)key;
    db_key.size = strlen(key) + 1;

    ret = dbp->get(dbp, NULL, &db_key, &db_value, 0);
    
    if (ret == 0) {
        if (asprintf(&db_res, "%s", (char *)db_value.data) != -1)
            TRACE(TRACE_LOOKUP, "[%p] found value [%s]", dbp, db_res);
    } else
        TRACE(TRACE_LOOKUP, "[%p] nothing found", dbp);

    if (dbp != NULL)
        dbp->close(dbp, 0);

    return db_res;
}
开发者ID:spmfilter,项目名称:spmfilter,代码行数:55,代码来源:smf_lookup_db4.c

示例9: getopt

int
b_curalloc(int argc, char *argv[])
{
	extern char *optarg;
	extern int optind, __db_getopt_reset;
	DB *dbp;
	DBC *curp;
	int ch, i, count;

	count = 100000;
	__db_getopt_reset = 1;
	while ((ch = getopt(argc, argv, "c:")) != EOF)
		switch (ch) {
		case 'c':
			count = atoi(optarg);
			break;
		case '?':
		default:
			return (b_curalloc_usage());
		}
	argc -= optind;
	argv += optind;
	if (argc != 0)
		return (b_curalloc_usage());

	/* Create the database. */
	DB_BENCH_ASSERT(db_create(&dbp, NULL, 0) == 0);
	dbp->set_errfile(dbp, stderr);

#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
	DB_BENCH_ASSERT(dbp->open(
	    dbp, NULL, TESTFILE, NULL, DB_BTREE, DB_CREATE, 0666) == 0);
#else
	DB_BENCH_ASSERT(
	    dbp->open(dbp, TESTFILE, NULL, DB_BTREE, DB_CREATE, 0666) == 0);
#endif

	/* Allocate a cursor count times. */
	TIMER_START;
	for (i = 0; i < count; ++i) {
		DB_BENCH_ASSERT(dbp->cursor(dbp, NULL, &curp, 0) == 0);
		DB_BENCH_ASSERT(curp->c_close(curp) == 0);
	}
	TIMER_STOP;

	printf("# %d cursor allocations\n", count);
	TIMER_DISPLAY(count);

	DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);

	return (0);
}
开发者ID:CompassHXM,项目名称:h-store,代码行数:52,代码来源:b_curalloc.c

示例10: strerror

_nc_db_open(const char *path, bool modify)
{
    DB *result = 0;
    int code;

#if HASHED_DB_API >= 4
    db_create(&result, NULL, 0);
    if ((code = result->open(result,
			     NULL,
			     path,
			     NULL,
			     DB_HASH,
			     modify ? DB_CREATE : DB_RDONLY,
			     0644)) != 0) {
	result = 0;
    }
#elif HASHED_DB_API >= 3
    db_create(&result, NULL, 0);
    if ((code = result->open(result,
			     path,
			     NULL,
			     DB_HASH,
			     modify ? DB_CREATE : DB_RDONLY,
			     0644)) != 0) {
	result = 0;
    }
#elif HASHED_DB_API >= 2
    if ((code = db_open(path,
			DB_HASH,
			modify ? DB_CREATE : DB_RDONLY,
			0644,
			(DB_ENV *) 0,
			(DB_INFO *) 0,
			&result)) != 0) {
	result = 0;
    }
#else
    if ((result = dbopen(path,
			 modify ? (O_CREAT | O_RDWR) : O_RDONLY,
			 0644,
			 DB_HASH,
			 NULL)) == 0) {
	code = errno;
    }
#endif
    if (result != 0) {
	T(("opened %s", path));
    } else {
	T(("cannot open %s: %s", path, strerror(code)));
    }
    return result;
}
开发者ID:ysleu,项目名称:RTL8685,代码行数:52,代码来源:hashed_db.c

示例11: 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);
}
开发者ID:Pakrik,项目名称:libdb,代码行数:25,代码来源:TestEnvMethod.c

示例12: TestPartNumber

int TestPartNumber(CuTest *ct) {
	DB_ENV *dbenv;
	DB *dbp;
	DBT *keys;
	u_int32_t i;

	dbenv = NULL;
	dbp = NULL;
	keys = NULL;
	nparts = 5;

	CuAssertTrue(ct, (keys = malloc((nparts - 1) * sizeof(DBT))) != NULL);
	memset(keys, 0, (nparts - 1) * sizeof(DBT));
	/* Assign data to the keys. */
	for (i = 0 ; i < (nparts - 1); i++) {
		keys[i].data = &content[(i + 1) * (strlen(content) / nparts)];
		keys[i].size = sizeof(char);
	}

	/* Partition number is less than 2. */
	CuAssertTrue(ct, create_db(&dbenv, &dbp, ct) == 0);
	CuAssertTrue(ct, dbp->set_partition(dbp, 1, keys, NULL) != 0);

	/* Partition number is less than key array length plus 1. */
	CuAssertTrue(ct, dbp->set_partition(dbp, nparts - 1, keys, NULL) == 0);
	CuAssertTrue(ct, dbp->open(dbp, NULL,
	    "test.db", NULL, DB_BTREE, DB_CREATE, 0644) == 0);
	CuAssertTrue(ct, put_data(dbp) == 0);
	CuAssertTrue(ct, close_db(dbenv, dbp, ct) == 0);
	free(keys);
	return (0);
}
开发者ID:hyc,项目名称:BerkeleyDB,代码行数:32,代码来源:TestPartition.c

示例13: userToSubname_open

int userToSubname_open(struct userToSubnameDbFormat * userToSubnameDb, char mode) {
		unsigned int flags;
		int ret;
		int filemode;
		DB * db;

		debug("Using DB version %s\n", DB_VERSION_STRING);

		switch (mode) {
			case 'w':
				flags = DB_CREATE;    	/* If the database does not exist, * create it.*/
				filemode = 0664;
				break;
			case 'r':
				flags = DB_RDONLY;
				filemode = 0;
				break;
			default:
				errx(1, "%s %d Unknown open mode '%d'", __FILE__, __LINE__, mode);
		}

		if ((ret = db_create(&db, NULL, 0)) != 0)
			errx(1, "%s db_create: %s\n", __FILE__, db_strerror(ret));

		if ((ret = db->set_flags(db, DB_DUPSORT)) != 0)
			errx(1, "set dupsort flags, %s\n", db_strerror(ret));

		ret = db->open(db, NULL, bfile(userToSubnameDbFile), NULL, DB_BTREE, flags, filemode);
		if (ret != 0)
			errx(1, "db open error %s\n", db_strerror(ret));
	
		(*userToSubnameDb).dbp = db;

		return 1;
}
开发者ID:FlavioFalcao,项目名称:enterprise-search,代码行数:35,代码来源:acls.c

示例14: vdadisk_read

int vdadisk_read (const char *db_name, LogicalSector *sector, tSectorId idToSearch) {
	DB *base;
	DBT key, data;
	int ret;

	if ((ret = db_create(&base, NULL, 0)) != 0)
		return ret;
	/* Associate DB with a file (create a btree)*/
	//if ((ret = base->open(base, NULL, concat( getGlobalHeap(), 2, db_name, ".db"), NULL, DB_BTREE, DB_CREATE, 0)) != 0) {
	if ((ret = base->open(base, NULL, db_name, NULL, DB_BTREE, DB_CREATE, 0)) != 0) {
		if(isDebugEnabled()) error( "[BDB] Fallo al abrir la base" );
		//base->err(base, ret, "DB open failed\n");
		base->close(base,0);
		return ret;
	}
	loadDBT (&key, &data, sector);
	ret = base->get(base, NULL, &key, &data, 0);
	if((ret = base->get(base, NULL, &key, &data, 0)) != 0) {
		if(isDebugEnabled()) 
			debug(concat( getGlobalHeap() , 2 , "[BDB] No se encuentra el sector " ,itoa_buf(sector->sectorId)));
		//base->err(base, ret, "Not found.");
	}
	base->close(base,0);
	return ret;
}
开发者ID:kronleuchter85,项目名称:tomateperita,代码行数:25,代码来源:vda-db.c

示例15: vdadisk_write

int vdadisk_write (const char *db_name, LogicalSector *sector) {
	DB *base;
	DBT key, data;
	int ret;

	if ((ret = db_create(&base, NULL, 0)) != 0)
		return ret;
	/* Associate DB with a file (create a btree)*/
	//if ((ret = base->open(base, NULL,concat( getGlobalHeap(), 2, db_name, ".db"), NULL, DB_BTREE, DB_CREATE, 0)) != 0) {
	if ((ret = base->open(base, NULL, db_name, NULL, DB_BTREE, DB_CREATE, 0)) != 0) {
		if(isDebugEnabled()) error( "[BDB] Fallo al abrir la base" );
		//base->err(base, ret, "DB open failed\n");
		base->close(base,0);
		return ret;
	}
	loadDBT (&key, &data, sector);
	ret = base->put(base, NULL, &key, &data, DB_NOOVERWRITE);
	if (ret == DB_KEYEXIST) {
		//base->err(base, ret, "La clave %d ya existe!\n");*
		//_itoa_s(sector->sectorId, aux, 10, 10);
		if(isDebugEnabled()) debug(concat( getGlobalHeap() , 2 , "[BDB] Ya existe el sector ", itoa_buf(sector->sectorId)));
		if ((ret = base->del(base, NULL, &key, 0)) == 0 ){  /* Si existe lo borro y lo vuelvo a escribir */
			if(isDebugEnabled()) debug(concat( getGlobalHeap() , 2 , "[BDB] Reescribiendo el sector ", itoa_buf(sector->sectorId)));
			ret = base->put(base, NULL, &key, &data, DB_NOOVERWRITE);
		}
	}
	base->close(base,0);
	return ret;
}
开发者ID:kronleuchter85,项目名称:tomateperita,代码行数:29,代码来源:vda-db.c


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