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


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

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


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

示例1:

/**
 * librdf_hash_bdb_cursor_init - Initialise a new bdb cursor
 * @cursor_context: hash cursor context
 * @hash_context: hash to operate over
 * 
 * Return value: non 0 on failure
 **/
static int
librdf_hash_bdb_cursor_init(void *cursor_context, void *hash_context)
{
  librdf_hash_bdb_cursor_context *cursor=(librdf_hash_bdb_cursor_context*)cursor_context;
#ifdef HAVE_BDB_CURSOR
  DB* db;
#endif

  cursor->hash=(librdf_hash_bdb_context*)hash_context;

#ifdef HAVE_BDB_CURSOR
  db=cursor->hash->db;
#ifdef HAVE_BDB_CURSOR_4_ARGS
  /* V3 prototype:
   * int DB->cursor(DB *db, DB_TXN *txnid, DBC **cursorp, u_int32_t flags);
   */
  if(db->cursor(db, NULL, &cursor->cursor, 0))
    return 1;
#else
  /* V2 prototype:
   * int DB->cursor(DB *db, DB_TXN *txnid, DBC **cursorp);
   */
  if(db->cursor(db, NULL, &cursor->cursor))
    return 1;
#endif
#endif

  return 0;
}
开发者ID:stefanhusmann,项目名称:Amaya,代码行数:36,代码来源:rdf_hash_bdb.c

示例2: hrai_list

int hrai_list(const char *db_name)
{
    DBT key, data;
    DBC *it;
    DB *dbp = hrai_db_open();

    memset(&key, 0, sizeof(DBT));
    memset(&data, 0, sizeof(DBT));

    dbp->cursor(dbp, NULL, &it, 0);

    int ret;
    while ((ret = it->get(it, &key, &data, DB_NEXT)) == 0) {
        struct hrai_entry *entry = (struct hrai_entry *)data.data;
        time_t *keystamp = (time_t *)key.data;

        printf("%ld: %4d-%02d-%02d [%u] %s\n", *keystamp
                                             , (entry->date).tm_year + 1900
                                             , (entry->date).tm_mon + 1
                                             , (entry->date).tm_mday
                                             , entry->amount
                                             , entry->description
                                             );
    }

    if (ret != DB_NOTFOUND) return 1;
    if (it != NULL) it->close(it);
    hrai_db_close(dbp);

    return 0;
}
开发者ID:gerard,项目名称:hrai,代码行数:31,代码来源:list.c

示例3: sizeof

/**
 * e_dbhash_foreach_key:
 * @edbh: an #EDbHash
 * @func: a callback function
 * @user_data: data to pass to @func
 *
 * Calls @func for each database object.
 **/
void
e_dbhash_foreach_key (EDbHash *edbh,
                      EDbHashFunc func,
                      gpointer user_data)
{
	DB *db;
	DBT dkey;
	DBT ddata;
	DBC *dbc;
	gint db_error = 0;

	g_return_if_fail (edbh != NULL);
	g_return_if_fail (edbh->priv != NULL);
	g_return_if_fail (func != NULL);

	db = edbh->priv->db;

	db_error = db->cursor (db, NULL, &dbc, 0);

	if (db_error != 0) {
		return;
	}

	memset (&dkey, 0, sizeof (DBT));
	memset (&ddata, 0, sizeof (DBT));
	db_error = dbc->c_get (dbc, &dkey, &ddata, DB_FIRST);

	while (db_error == 0) {
		(*func) ((const gchar *) dkey.data, user_data);

		db_error = dbc->c_get (dbc, &dkey, &ddata, DB_NEXT);
	}
	dbc->c_close (dbc);
}
开发者ID:Pecisk,项目名称:eds-gtasks,代码行数:42,代码来源:e-dbhash.c

示例4: pctlmfdb_stat

static int pctlmfdb_stat(struct pctldb_st *pctldb, int *dberror){

  int status = 0;
  DB* mfdbp = pctldb->mfdbp;
  DBC *cursor;
  DBT key, data;
  uint32_t memfile_size;

  *dberror = mfdbp->cursor(mfdbp, NULL, &cursor, 0);
  if(*dberror != 0)
    return(-1);

  memset(&key, 0, sizeof(DBT));
  memset(&data, 0, sizeof(DBT));

  pctldb->mf_total_size = 0;
  while(status == 0){
    status = cursor->c_get(cursor, &key, &data, DB_NEXT);
    if(status == 0){
      memfile_size = data.size;
      pctldb->mf_total_size += memfile_size;
    }
  }

  cursor->c_close(cursor);

  if(status == DB_NOTFOUND)
    status = 0;
  else{
    *dberror = status;
    status = -1;
  }

  return(status);
}
开发者ID:noaaport,项目名称:nbsp,代码行数:35,代码来源:pctldb.c

示例5:

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);
}
开发者ID:qixin,项目名称:wiredtiger,代码行数:29,代码来源:bdb.c

示例6: assert

static int db3copen(dbiIndex dbi, DB_TXN * txnid,
		DBC ** dbcp, unsigned int dbiflags)
{
    DB * db = dbi->dbi_db;
    DBC * dbcursor = NULL;
    int flags;
    int rc;

   /* XXX DB_WRITECURSOR cannot be used with sunrpc dbenv. */
    assert(db != NULL);
    if ((dbiflags & DB_WRITECURSOR) &&
	(dbi->dbi_eflags & DB_INIT_CDB) && !(dbi->dbi_oflags & DB_RDONLY))
    {
	flags = DB_WRITECURSOR;
    } else
	flags = 0;

    rc = db->cursor(db, txnid, &dbcursor, flags);
    rc = cvtdberr(dbi, "db->cursor", rc, _debug);

    if (dbcp)
	*dbcp = dbcursor;
    else
	(void) db3cclose(dbi, dbcursor, 0);

    return rc;
}
开发者ID:xrg,项目名称:RPM,代码行数:27,代码来源:db3.c

示例7: sizeof

void
bdb_dump_users_score(const char *dbpath) 
{
	struct passwd *p;
	uid_t uid;
	int mailcount;
	DBT key, data;
	DB *map = _bdb_open_database(dbpath);
	DBC *cursor;
	map->cursor(map, NULL, &cursor, 0);	
	memset(&key, 0, sizeof(DBT));
	memset(&data, 0, sizeof(DBT));
	data.data = &mailcount;
	data.ulen = sizeof(int);
	data.flags = DB_DBT_USERMEM;
	while (cursor->get(cursor, &key, &data, DB_NEXT) == 0) {
		uid = *((uid_t *)key.data);
		if((p = getpwuid(uid)) == NULL) {
			warn("Can't find user for uid : %d\n", uid);
			continue;
		}
		printf("%s\t%d\n", p->pw_name, mailcount);
	}
	cursor->close(cursor);
	map->close(map, 0); 
}
开发者ID:rmdir,项目名称:sendmailornot,代码行数:26,代码来源:bdb.c

示例8: mail_cache_db_clean_up

int mail_cache_db_clean_up(struct mail_cache_db * cache_db,
    chash * exist)
{
  DB * dbp;
  int r;
  DBC * dbcp;
  DBT db_key;
  DBT db_data;
  
  dbp = cache_db->internal_database;
 
#if DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR < 6
  r = dbp->cursor(dbp, NULL, &dbcp);
#else
  r = dbp->cursor(dbp, NULL, &dbcp, 0);
#endif  
  if (r != 0)
    return -1;
  
  memset(&db_key, 0, sizeof(db_key));
  memset(&db_data, 0, sizeof(db_data));
  
  while (1) {
    chashdatum hash_key;
    chashdatum hash_data;
    
    r = dbcp->c_get(dbcp, &db_key, &db_data, DB_NEXT);
    if (r != 0)
      break;
    
    hash_key.data = db_key.data;
    hash_key.len = db_key.size;

    r = chash_get(exist, &hash_key, &hash_data);
    if (r < 0) {
      r = dbcp->c_del(dbcp, 0);
      if (r != 0)
        return -1;
    }
  }
  
  r = dbcp->c_close(dbcp);
  if (r != 0)
    return -1;
  
  return 0;
}
开发者ID:mralexgray,项目名称:etPanKit,代码行数:47,代码来源:mail_cache_db.c

示例9: sizeof

int
hdb_dn2id_parent(
	Operation *op,
	DB_TXN *txn,
	EntryInfo *ei,
	ID *idp )
{
	struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
	DB *db = bdb->bi_dn2id->bdi_db;
	DBT		key, data;
	DBC	*cursor;
	int		rc = 0;
	diskNode *d;
	char	*ptr;
	ID	nid;

	DBTzero(&key);
	key.size = sizeof(ID);
	key.data = &nid;
	key.ulen = sizeof(ID);
	key.flags = DB_DBT_USERMEM;
	BDB_ID2DISK( ei->bei_id, &nid );

	DBTzero(&data);
	data.flags = DB_DBT_USERMEM;

	rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
	if ( rc ) return rc;

	data.ulen = sizeof(diskNode) + (SLAP_LDAPDN_MAXLEN * 2);
	d = op->o_tmpalloc( data.ulen, op->o_tmpmemctx );
	data.data = d;

	rc = cursor->c_get( cursor, &key, &data, DB_SET );
	if ( rc == 0 ) {
		if (d->nrdnlen[0] & 0x80) {
			rc = LDAP_OTHER;
		} else {
			db_recno_t dkids;
			ptr = (char *) data.data + data.size - sizeof(ID);
			BDB_DISK2ID( ptr, idp );
			ei->bei_nrdn.bv_len = (d->nrdnlen[0] << 8) | d->nrdnlen[1];
			ber_str2bv( d->nrdn, ei->bei_nrdn.bv_len, 1, &ei->bei_nrdn );
			ei->bei_rdn.bv_len = data.size - sizeof(diskNode) -
				ei->bei_nrdn.bv_len;
			ptr = d->nrdn + ei->bei_nrdn.bv_len + 1;
			ber_str2bv( ptr, ei->bei_rdn.bv_len, 1, &ei->bei_rdn );
			/* How many children does this node have? */
			cursor->c_count( cursor, &dkids, 0 );
			ei->bei_dkids = dkids;
		}
	}
	cursor->c_close( cursor );
	op->o_tmpfree( d, op->o_tmpmemctx );
	return rc;
}
开发者ID:cptaffe,项目名称:openldap,代码行数:56,代码来源:dn2id.c

示例10: sizeof

int
bdb_dn2id(
	Operation *op,
	struct berval	*dn,
	EntryInfo *ei,
	DB_TXN *txn,
	DB_LOCK *lock )
{
	struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
	DB *db = bdb->bi_dn2id->bdi_db;
	DBC	*cursor;
	int		rc;
	DBT		key, data;
	ID		nid;

	Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id(\"%s\")\n", dn->bv_val, 0, 0 );

	DBTzero( &key );
	key.size = dn->bv_len + 2;
	key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
	((char *)key.data)[0] = DN_BASE_PREFIX;
	AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );

	/* store the ID */
	DBTzero( &data );
	data.data = &nid;
	data.ulen = sizeof(ID);
	data.flags = DB_DBT_USERMEM;

	rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
	if ( rc ) goto func_leave;

	rc = bdb_dn2id_lock( bdb, dn, 0, txn, lock );
	if ( rc ) goto nolock;

	/* fetch it */
	rc = cursor->c_get( cursor, &key, &data, DB_SET );

nolock:
	cursor->c_close( cursor );
func_leave:

	if( rc != 0 ) {
		Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: get failed: %s (%d)\n",
			db_strerror( rc ), rc, 0 );
	} else {
		BDB_DISK2ID( &nid, &ei->bei_id );
		Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: got id=0x%lx\n",
			ei->bei_id, 0, 0 );
	}
	op->o_tmpfree( key.data, op->o_tmpmemctx );
	return rc;
}
开发者ID:ystk,项目名称:debian-openldap,代码行数:53,代码来源:dn2id.c

示例11: printf

/* FIXME should this be wrapped in an explicit transaction? */
static void
do_dump_triplets()
{
    DB *db;
    DBC *dbcp;
    int rc;
    DBT key = { 0 },
	data = { 0 };
    rc = get_db(&db, 1);
    if (rc) {
	fprintf(stderr, "DBD-%d: failed to open database\n", rc);
	return;
    }
    rc = db->cursor(db, 0, &dbcp, 0);
    if (rc)
	fprintf(stderr, "DBD-%d: db->cursor failed: %s\n",
		rc, db_strerror(rc));
    else {
	while (! exit_requested
	       && (rc = dbcp->c_get(dbcp, &key, &data, DB_NEXT)) == 0) {
	    const char *const start = key.data, *s = start;
	    const struct triplet_data *t = data.data;
	    printf("%d\t", t->crypted);
	    printf("%s\t", db_key_ntop(s));
	    switch ((enum dbkey_type_enum)*s++) {
	    case DBKEY_T_RAW:
		s += strlen(s) + 1;
		break;
	    case DBKEY_T_IP4:
		s += IPV4_BITS / 8;
		break;
	    case DBKEY_T_IP6:
		s += IPV6_BITS / 8;
		break;
	    }
	    printf("%s\t", s);
	    s += strlen(s) + 1;
	    fwrite(s, 1, key.size - (s - start), stdout);
	    putchar('\t');
	    write_ctime(&t->create_time);
	    putchar('\t');
	    write_ctime(&t->access_time);
	    printf("\t%lu\t%lu\n", t->block_count, t->pass_count);
	}
	if (rc && rc != DB_NOTFOUND)
	    fprintf(stderr, "DBD-%d: dbcp->c_get failed: %s\n",
		    rc, db_strerror(rc));
	rc = dbcp->c_close(dbcp);
	if (rc)
	    fprintf(stderr, "DBD-%d: dbcp->c_close failed: %s\n",
		    rc, db_strerror(rc));
    }
}
开发者ID:dtaht,项目名称:Cryptolisting,代码行数:54,代码来源:cryptolist.c

示例12: 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

示例13: main

int main(int argc,char * argv[])
{
	int rc;
	DB_ENV *env;
	DB *dbi;
	DBT key, data;
	DB_TXN *txn;
	DBC *cursor;
	char sval[32], kval[32];

#define FLAGS (DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_INIT_MPOOL|DB_CREATE|DB_THREAD)
	rc = db_env_create(&env, 0);
	rc = env->open(env, "./testdb", FLAGS, 0664);
	rc = db_create(&dbi, env, 0);
	rc = env->txn_begin(env, NULL, &txn, 0);
	rc = dbi->open(dbi, txn, "test.bdb", NULL, DB_BTREE, DB_CREATE, 0664);

	memset(&key, 0, sizeof(DBT));
	memset(&data, 0, sizeof(DBT));
	key.size = sizeof(int);
	key.data = sval;
	data.size = sizeof(sval);
	data.data = sval;

	sprintf(sval, "%03x %d foo bar", 32, 3141592);
	rc = dbi->put(dbi, txn, &key, &data, 0);
	rc = txn->commit(txn, 0);
	if (rc) {
		fprintf(stderr, "txn->commit: (%d) %s\n", rc, db_strerror(rc));
		goto leave;
	}
	rc = env->txn_begin(env, NULL, &txn, 0);
	rc = dbi->cursor(dbi, txn, &cursor, 0);
	key.flags = DB_DBT_USERMEM;
	key.data = kval;
	key.ulen = sizeof(kval);
	data.flags = DB_DBT_USERMEM;
	data.data = sval;
	data.ulen = sizeof(sval);
	while ((rc = cursor->c_get(cursor, &key, &data, DB_NEXT)) == 0) {
		printf("key: %p %.*s, data: %p %.*s\n",
			key.data,  (int) key.size,  (char *) key.data,
			data.data, (int) data.size, (char *) data.data);
	}
	rc = cursor->c_close(cursor);
	rc = txn->abort(txn);
leave:
	rc = dbi->close(dbi, 0);
	rc = env->close(env, 0);
	return rc;
}
开发者ID:AUSTRALIANBITCOINS,项目名称:rippled,代码行数:51,代码来源:sample-bdb.c

示例14: Find

    Iterator* PerconaFTEngine::Find(Context& ctx, const KeyObject& key)
    {
        PerconaFTLocalContext& local_ctx = g_local_ctx.GetValue();
        DB_TXN* txn = local_ctx.transc.Get();
        PerconaFTIterator* iter = NULL;
        NEW(iter, PerconaFTIterator(this,key.GetNameSpace()));
        DB* db = GetFTDB(ctx, key.GetNameSpace(), false);
        if (NULL == db)
        {
            iter->MarkValid(false);
            return iter;
        }
        int r = 0;
        DBC* c = NULL;
        CHECK_EXPR(r = db->cursor(db, txn, &c, 0));
        if (0 != r)
        {
            local_ctx.transc.Release(false);
            iter->MarkValid(false);
            return iter;
        }
        iter->SetCursor(db, txn, c);
        if (key.GetType() > 0)
        {
            if (!ctx.flags.iterate_multi_keys)
            {
                if (!ctx.flags.iterate_no_upperbound)
                {
                    KeyObject& upperbound_key = iter->IterateUpperBoundKey();
                    upperbound_key.SetNameSpace(key.GetNameSpace());
                    if (key.GetType() == KEY_META)
                    {
                        upperbound_key.SetType(KEY_END);
                    }
                    else
                    {
                        upperbound_key.SetType(key.GetType() + 1);
                    }
                    upperbound_key.SetKey(key.GetKey());
                    upperbound_key.CloneStringPart();
                }
            }
            iter->Jump(key);

        }
        else
        {
            iter->JumpToFirst();
        }
        return iter;
    }
开发者ID:yinqiwen,项目名称:ardb,代码行数:51,代码来源:perconaft_engine.cpp

示例15: dir_is_empty

static bool dir_is_empty(DB_TXN *txn, const struct nfs_inode *ino)
{
	int rc;
	DBC *cur = NULL;
	DB *dirent = srv.fsdb.dirent;
	DBT pkey, pval;
	struct fsdb_de_key key;
	nfsino_t rnum = 0;
	uint64_t db_dummy;

	rc = dirent->cursor(dirent, txn, &cur, 0);
	if (rc) {
		dirent->err(dirent, rc, "dirent->cursor");
		return false;
	}

	key.inum = inum_encode(ino->inum);

	memset(&pkey, 0, sizeof(pkey));
	pkey.data = &key;
	pkey.size = sizeof(key);
	pkey.flags = DB_DBT_MALLOC;

	memset(&pval, 0, sizeof(pval));
	pval.data = &db_dummy;
	pval.ulen = sizeof(db_dummy);
	pval.flags = DB_DBT_USERMEM;

	rc = cur->get(cur, &pkey, &pval, DB_SET_RANGE);
	if (rc == 0) {
		struct fsdb_de_key *rkey = pkey.data;

		rnum = inum_decode(rkey->inum);

		free(rkey);
	} else if (rc != DB_NOTFOUND)
		dirent->err(dirent, rc, "dir_is_empty cur->get");

	rc = cur->close(cur);
	if (rc) {
		dirent->err(dirent, rc, "dirent->cursor close");
		return false;
	}

	if (rnum == ino->inum)
		return false;

	return true;
}
开发者ID:jgarzik,项目名称:nfs4d,代码行数:49,代码来源:dir.c


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