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


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

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


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

示例1: mail_cache_db_get

int mail_cache_db_get(struct mail_cache_db * cache_db,
    const void * key, size_t key_len, void ** pvalue, size_t * pvalue_len)
{
#if DBVERS >= 1
  int r;
  DBT db_key;
  DBT db_data;
  DB * dbp;
  
  dbp = cache_db->internal_database;
  
  memset(&db_key, 0, sizeof(db_key));
  memset(&db_data, 0, sizeof(db_data));
  db_key.data = (void *) key;
  db_key.size = key_len;
  
#if DBVERS > 1  
  r = dbp->get(dbp, NULL, &db_key, &db_data, 0);
#elif DBVERS == 1
  r = dbp->get(dbp, &db_key, &db_data, 0);
#else
  r = -1;
#endif
  
  if (r != 0)
    return -1;
  
  * pvalue = db_data.data;
  * pvalue_len = db_data.size;
  
  return 0;
#else
  return -1;
#endif
}
开发者ID:mralexgray,项目名称:etPanKit,代码行数:35,代码来源:mail_cache_db.c

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

示例3: search

int search(context_t context, char*fname, resSet*set, int*len) {
  int 
    ret,
    ix;

  DB*   dbContext = db_getContext(context);

  DBT 
    key, 
    data;

  analSet   anal;
  analTuple  toComp[MAXRES * MAXINDEX];
  cmpString   *list[MAXRES * MAXINDEX];
  
  char *pContext;
  if(context[0]) {
    pContext = context;
  } else {
    pContext = g_lastcontext;
  }

  if(strlen(fname) < 1) {
    return 0;
  }
  memset (&key, 0, sizeof (key));
  memset (&data, 0, sizeof (data));
  
  //compress(fname, comp);
  key.data = fname;
  key.size = strlen(fname);

  // first we grab the file from the table
  if ((ret = dbContext->get (dbContext, NULL, &key, &data, 0)) != 0) {
    return 0;
  }
  memcpy(&anal, (analSet*)data.data, sizeof(analSet));
  // then we execute an index search on the image
  ixGet(&anal, list, len);

  printf ("(db) [%s] getting %d\n", pContext, *len);

  // retrieve the entries from bdb
  for(ix = 0; ix < *len; ix++) {
    key.data = list[ix];
    key.size = strlen(*list[ix]);

    if ((ret = dbContext->get (dbContext, NULL, &key, &data, 0)) != 0) {
      return 0;
    } else {
      memcpy(&toComp[ix].set, (analSet*)data.data, sizeof(analSet));
      toComp[ix].name = list[ix];
    }
  }

  // then do a full analysis over the list
  // and return it
  return match(&anal, toComp, set, *len);
}
开发者ID:kristopolous,项目名称:similarcolors,代码行数:59,代码来源:db.c

示例4: sizeof

AccountingInfo *getAccoutingInfo(int db)
{
	DB_ENV *dbenv = radacct_dbenv[db];
	DB *dbp = radacct_dbp[db];
	DB_TXN *tid = NULL;
	DBT key, data;
	db_recno_t recno;
	AccountingInfo *info = NULL;
	char buf[REC_SIZE];
	int ret;

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

	key.data = &recno;
	key.size = key.ulen = sizeof(recno);
	key.flags = DB_DBT_USERMEM;

	data.data = buf;
	data.ulen = sizeof(buf);
	data.flags = DB_DBT_USERMEM;

	#if USE_TXN
	if((ret = dbenv->txn_begin(dbenv, NULL, &tid, 0)) != 0)
	{
		NETERROR(MRADC, ("getAccoutingInfo: transaction failed: %s\n", db_strerror(ret)));
		return 0;
	}

	switch((ret = dbp->get(dbp, tid, &key, &data, DB_CONSUME)))
	#else
	switch((ret = dbp->get(dbp, NULL, &key, &data, DB_CONSUME)))
	#endif
	{
		case DB_LOCK_DEADLOCK:
			NETERROR(MRADC, ("getAccoutingInfo: deadlock: %s\n", db_strerror(ret)));
			break;

		case 0:
			if((info = (AccountingInfo*)malloc(sizeof(AccountingInfo))))
			{
				memset(info, 0, sizeof(AccountingInfo));

				info->tid = tid;

				unMarshalAccountingInfo(buf, info);
			}
			break;

		default:
			NETERROR(MRADC, ("getAccoutingInfo: oops: %d\n", ret));
			break;
	}

	return info;
}
开发者ID:AkankshaGovil,项目名称:Automation,代码行数:56,代码来源:radacct_db.c

示例5: pctlmfdb_rcv

int pctlmfdb_rcv(struct pctldb_st *pctldb, struct timespec *ts,
		 struct memfile_st *mf, int *dberror){

  int status = 0;
  int dberror_del;
  DBT key, data;
  DB* mfdbp = pctldb->mfdbp;

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

  key.data = ts;
  key.ulen = sizeof(struct timespec);
  key.flags = DB_DBT_USERMEM;
  data.data = mf->p;
  data.ulen = get_memfile_allocated_size(mf);
  data.flags = DB_DBT_USERMEM;
  *dberror = mfdbp->get(mfdbp, NULL, &key, &data, 0);
  if(*dberror == DB_BUFFER_SMALL){
    status = realloc_memfile(mf, data.size);
    if(status == 0){
      data.data = mf->p;
      data.ulen = get_memfile_allocated_size(mf);
      *dberror = mfdbp->get(mfdbp, NULL, &key, &data, 0);
    }else
      *dberror = errno;
  }

  if(*dberror == 0)
    mf->size = data.size;
  else{
    status = -1;
    mf->size = 0; /* Only for convenience in the substraction below */
  }

  dberror_del = mfdbp->del(mfdbp, NULL, &key, 0);

  if(dberror_del == 0){
    if(pctldb->mf_total_size > mf->size)
      pctldb->mf_total_size -= mf->size;
    else
      pctldb->mf_total_size = 0;
  }else{
    if(*dberror == 0){
      status = -1;
      *dberror = dberror_del;
    }
  }

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

示例6: bucket_find

static int bucket_find(DB_TXN *txn, const char *bucket, char *owner,
		       int owner_len)
{
	DB *buckets = tdbrep.tdb.buckets;
	DBT key, val;
	struct db_bucket_ent ent;
	int rc;

	memset(&key, 0, sizeof(key));
	key.data = (char *) bucket;
	key.size = strlen(bucket) + 1;

	memset(&val, 0, sizeof(val));
	val.data = &ent;
	val.ulen = sizeof(struct db_bucket_ent);
	val.flags = DB_DBT_USERMEM;

	rc = buckets->get(buckets, txn, &key, &val, 0);

	if (rc == 0 && owner != NULL && owner_len > 0) {
		strncpy(owner, ent.owner, owner_len);
		owner[owner_len-1] = 0;
	}

	return rc;
}
开发者ID:jgarzik,项目名称:tabled,代码行数:26,代码来源:bucket.c

示例7: Get

 int PerconaFTEngine::Get(Context& ctx, const KeyObject& key, ValueObject& value)
 {
     DB* db = GetFTDB(ctx, key.GetNameSpace(), false);
     if (NULL == db)
     {
         return ERR_ENTRY_NOT_EXIST;
     }
     PerconaFTLocalContext& local_ctx = g_local_ctx.GetValue();
     Slice ks = local_ctx.GetSlice(key);
     DBT key_slice = to_dbt(ks);
     DB_TXN* txn = local_ctx.transc.Peek();
     int r = 0;
     DBT val_slice;
     memset(&val_slice, 0, sizeof(DBT));
     val_slice.flags = DB_DBT_MALLOC;
     //CHECK_EXPR(r = m_env->txn_begin(m_env, NULL, &txn, 0));
     CHECK_EXPR(r = db->get(db, txn, &key_slice, &val_slice, 0));
     if (0 == r)
     {
         Buffer valBuffer((char*) (val_slice.data), 0, val_slice.size);
         value.Decode(valBuffer, true);
     }
     //txn->commit(txn, 0);
     return ENGINE_ERR(r);
 }
开发者ID:yinqiwen,项目名称:ardb,代码行数:25,代码来源:perconaft_engine.cpp

示例8: rberkeley_db_get

/* {{{ rberkeley_db_get */
SEXP rberkeley_db_get(SEXP _dbp, SEXP _txnid, SEXP _key, SEXP _data, SEXP _flags)
{
  DB *dbp;
  DBT key, data;
  DB_TXN *txnid;
  u_int32_t flags = INTEGER(_flags)[0];
  int ret;

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

  key.data = (unsigned char *)RAW(_key);
  key.size = length(_key);
  if(!isNull(_data)) {
    data.data = (unsigned char *)RAW(_data);
    data.size = length(_data);
  }

  dbp = R_ExternalPtrAddr(_dbp);
  if(R_ExternalPtrTag(_dbp) != RBerkeley_DB || dbp == NULL)
    error("invalid 'db' handle");

  if(!isNull(_txnid)) {
    txnid = R_ExternalPtrAddr(_txnid);
  } else txnid = NULL;

  ret = dbp->get(dbp, txnid, &key, &data, flags);
  if(ret == 0) {
    SEXP retdata;
    PROTECT(retdata = allocVector(RAWSXP, data.size));
    memcpy(RAW(retdata), data.data, data.size);
    UNPROTECT(1);
    return retdata;
  } else return ScalarInteger(ret); 
}
开发者ID:rforge,项目名称:rberkeley,代码行数:36,代码来源:db.c

示例9: berkely_registry_get

static Info* berkely_registry_get(void *self, const char* filename)
{
  DB *dbp = NULL;
  int ret;

  dbp = get_db(self);
  g_assert(dbp != NULL);

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

  key.data = (void*) filename;
  key.size = strlen(filename) + 1;
  key.flags = DB_DBT_USERMEM;

  if ((ret = dbp->get(dbp, NULL, &key, &data, 0)) == 0) {
    g_debug("db: '%s' key retreived", (char*)key.data);
  } else {
    dbp->err(dbp, ret, "DB->get");
    g_warning("DB get failed");
  }

  return bab_info_unmarshall(data.data);
}
开发者ID:shanegibbs,项目名称:babirusa,代码行数:25,代码来源:dbreg.c

示例10: load_metadata_logflags

int load_metadata_logflags(bdb_table_p _tp)
{
	int i, ret;
	char dbuf[MAX_ROW_SIZE];

	DB *db = NULL;
	DBT key, data;
	i = 0;
	
	if(!_tp || !_tp->db)
		return -1;
	
	db = _tp->db;
	memset(&key, 0, sizeof(DBT));
	memset(&data, 0, sizeof(DBT));
	memset(dbuf, 0, MAX_ROW_SIZE);
	key.data = METADATA_LOGFLAGS;
	key.size = strlen(METADATA_LOGFLAGS);
	data.data = dbuf;
	data.ulen = MAX_ROW_SIZE;
	data.flags = DB_DBT_USERMEM;
	
	if ((ret = db->get(db, NULL, &key, &data, 0)) != 0) 
	{	return ret;
	}
	
	if( 1 == sscanf(dbuf,"%i", &i) )
		_tp->logflags=i;
	
	return 0;
}
开发者ID:SibghatullahSheikh,项目名称:kamailio,代码行数:31,代码来源:bdb_lib.c

示例11: km_load_metadata_readonly

int km_load_metadata_readonly(table_p _tp)
{
	int i, ret;
	char dbuf[MAX_ROW_SIZE];

	DB *db = NULL;
	DBT key, data;
	i = 0;
	
	if(!_tp || !_tp->db)
		return -1;
	
	db = _tp->db;
	memset(&key, 0, sizeof(DBT));
	memset(&data, 0, sizeof(DBT));
	memset(dbuf, 0, MAX_ROW_SIZE);
	key.data = METADATA_READONLY;
	key.size = strlen(METADATA_READONLY);
	data.data = dbuf;
	data.ulen = MAX_ROW_SIZE;
	data.flags = DB_DBT_USERMEM;
	
	if ((ret = db->get(db, NULL, &key, &data, 0)) != 0) 
	{	return ret;
	}
	
	if( 1 == sscanf(dbuf,"%i", &i) )
		_tp->ro=(i>0)?1:0;
	
	return 0;
}
开发者ID:GreenfieldTech,项目名称:kamailio,代码行数:31,代码来源:km_bdb_lib.c

示例12: main

int main() {
  DB *db;
  DB *uiddb;
  int ret;

  db_create(&db, NULL, 0);
  db->open(db, NULL, NULL, "data", DB_BTREE, DB_CREATE, 0);

  db_create(&uiddb, NULL, 0);
  uiddb->open(uiddb, NULL, NULL, "byuid", DB_BTREE, DB_CREATE, 0);

  ret = db->associate(db, NULL, uiddb, byuid_callback, 0);
  printf("associate: %d\n", ret);

  user_t u;
  strcpy(u.user, "jls");
  u.uid = 1000;
  strcpy(u.path, "/home/jls");

  DBT key, value;
  memset(&key, 0, sizeof(DBT));
  memset(&value, 0, sizeof(DBT));
  key.data = u.user;
  key.size = strlen(u.user);

  value.data = &u;
  value.size = sizeof(u);

  ret = db->put(db, NULL, &key, &value, 0);
  printf("put: %d\n", ret);

  memset(&value, 0, sizeof(value));
  ret = db->get(db, NULL, &key, &value, 0);
  printf("put: %d\n", ret);
  printf("Uid: %d\n", ((user_t*)value.data)->uid);

  memset(&value, 0, sizeof(value));
  int uid = 1000;
  key.data = &uid;
  key.size = sizeof(int);

  uiddb->get(uiddb, NULL, &key, &value, 0);
  printf("Secondary lookup: user=%s\n", ((user_t*)value.data)->user);

  return 0;
}
开发者ID:40a,项目名称:experiments,代码行数:46,代码来源:bdb_secondary_indeces.c

示例13: sizeof

/**
 *  Retrieving a concept:
 *  if it's already cached in memory,
 *  return a reference to it,
 *  otherwise check the MindMap DB
 *  and initialize a new concept.
 */
static struct ooConcept* 
ooMindMap_get(struct ooMindMap *self, mindmap_size_t id)
{
    DB *dbp;
    DBT key, data;
    int ret;

    struct ooConcept *conc = NULL;
    char *key_buffer;
    static mindmap_size_t idsize = sizeof(mindmap_size_t);

    if (id > self->num_concepts) return NULL;

    /* check the memory cache */
    conc = (struct ooConcept*)self->concept_index[id];
    if (conc) return conc;

    dbp = self->_storage;

    /* initialize the DBTs */
    memset(&key, 0, sizeof(DBT));
    memset(&data, 0, sizeof(DBT));

    key_buffer = malloc(idsize);
    if (!key_buffer) return NULL;

    memcpy(key_buffer, &id, idsize);

    /* set the search key with the Concept id */
    key.data = key_buffer;
    key.size = idsize;

    /* get the record */
    ret = dbp->get(dbp, NULL, &key, &data, 0);
    if (ret != 0) {
        dbp->err(dbp, ret,
                 "Error searching for id: %ld", id);
        return NULL;
    }

    /* create concept */
    ret = ooConcept_new(&conc);
    if (ret != oo_OK) return NULL;

    conc->numid = id;
    conc->bytecode = (char*)data.data;
    conc->bytecode_size = (size_t)data.size;
    conc->unpack(conc);

    /* update the cache */
    self->concept_index[id] = conc;

    free(key_buffer);

    return conc;
}
开发者ID:M0nsteR,项目名称:OOmnik,代码行数:63,代码来源:oomindmap.c

示例14: main

int main() {
	DB *dbp;
	DB_ENV *dbenv;
	DB_TXN *xid;
	DBT key, data;
	const unsigned int INSERT_NUM = 100;
	char value[22]; /* should be log INSERT_NUM */
	int ret, i, t_ret;

        env_dir_create();
        env_open(&dbenv);

	if ((ret = db_create(&dbp, dbenv, 0)) != 0) {
		fprintf(stderr, "db_create: %s\n", db_strerror(ret));
		exit (1);
	}

	dbenv->txn_begin(dbenv, NULL, &xid, 0);
	if ((ret = dbp->open(dbp,
					xid, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
		dbp->err(dbp, ret, "%s", DATABASE);
		goto err;
	}

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

	key.size = sizeof(int);
	key.data = malloc(sizeof(int));
	data.data = value;

	for( i = 0; i < INSERT_NUM; i++ ) {
		*((int*)key.data) = i;
		data.size = sizeof(char)*strlen(data.data);
		sprintf(value, "value: %u\n", i);
		dbp->put(dbp, xid, &key, &data, 0);
	}

	xid->commit(xid, 0);
	dbenv->txn_begin(dbenv, NULL, &xid, 0);
	
	for( i = 0; i < INSERT_NUM; i++ ) {
		*((int*)key.data) = i;
		dbp->get(dbp, xid, &key, &data, 0);
		printf("db: %u: key retrieved: data was %s.\n", *((int*)key.data), (char *)data.data);
	}

	xid->abort(xid);

err:    if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0)
			ret = t_ret; 


	return 0;

}
开发者ID:Zhoutall,项目名称:stasis,代码行数:56,代码来源:jbhashmany.c

示例15: malloc

static void
b_inmem_op_ds(u_int ops, int update)
{
	DB_ENV *dbenv;
	char *letters = "abcdefghijklmnopqrstuvwxuz";
	DB *dbp;
	DBT key, data;
	char *keybuf, *databuf;
	DB_MPOOL_STAT  *gsp;

	DB_BENCH_ASSERT((keybuf = malloc(keysize)) != NULL);
	DB_BENCH_ASSERT((databuf = malloc(datasize)) != NULL);

	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));
	key.data = keybuf;
	key.size = keysize;
	memset(keybuf, 'a', keysize);

	data.data = databuf;
	data.size = datasize;
	memset(databuf, 'b', datasize);

	DB_BENCH_ASSERT(db_create(&dbp, NULL, 0) == 0);
	dbenv = dbp->dbenv;
	dbp->set_errfile(dbp, stderr);

	DB_BENCH_ASSERT(dbp->set_pagesize(dbp, pagesize) == 0);
	DB_BENCH_ASSERT(dbp->open(
	    dbp, NULL, NULL, NULL, DB_BTREE, DB_CREATE, 0666) == 0);

	(void)dbenv->memp_stat(dbenv, &gsp, NULL, DB_STAT_CLEAR);

	if (update) {
		TIMER_START;
		for (; ops > 0; --ops) {
			keybuf[(ops % keysize)] = letters[(ops % 26)];
			DB_BENCH_ASSERT(
			    dbp->put(dbp, NULL, &key, &data, 0) == 0);
		}
		TIMER_STOP;
	} else {
		DB_BENCH_ASSERT(dbp->put(dbp, NULL, &key, &data, 0) == 0);
		TIMER_START;
		for (; ops > 0; --ops)
			DB_BENCH_ASSERT(
			    dbp->get(dbp, NULL, &key, &data, 0) == 0);
		TIMER_STOP;
	}

	if (dbenv->memp_stat(dbenv, &gsp, NULL, 0) == 0)
		DB_BENCH_ASSERT(gsp->st_cache_miss == 0);

	DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);
}
开发者ID:AdeebNqo,项目名称:poedit,代码行数:55,代码来源:b_inmem.c


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