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


C++ Dbt::get_data方法代码示例

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


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

示例1: dumpDB

void BDBFile::dumpDB()
{
  cout << "\n\n\n===== dumping contents of " << bdbFileName << " =====\n" << endl;

  // We put a try block around this section of code
  // to ensure that our database is properly closed
  // in the event of an error.
  //
  try {
    // Acquire a cursor for the table.
    Dbc *dbcp;
    dbHandle->cursor(NULL, &dbcp, 0);

    // Walk through the table, printing the key/data pairs.
    Dbt key;
    Dbt data;
    int rtrnCode = 0;
    int count = 0;
    while ((rtrnCode = dbcp->get(&key, &data, DB_NEXT) == 0)) {
      char *key_string = (char *)key.get_data();
      //char *data_string = (char *)data.get_data();
      char* data_string = (char *)data.get_data();
      cout << key_string << " : " << *(data_string) << "\n";
      ++count;
    }
    if (rtrnCode > 0) dbHandle->err(rtrnCode, "BDBFile::dumpDB");
    dbcp->close();
    cout << "\n\n\n===== total of " << count << " record(s) =====\n" << endl;
  }
  catch (DbException &dbe) {
    cout << "BDBFile::dumpDB " << dbe.what() << "\n";
  }
}
开发者ID:mesadb,项目名称:mesadb.github.io,代码行数:33,代码来源:BDBFile.cpp

示例2: printEntireDB

void DatabaseManager::printEntireDB()
{
	Dbc *cursor = NULL;
	try 
	{
		Dbt dbKey;
		Dbt dbData;

		m_pimpl->checkTSSInit();
		m_pimpl->m_database->cursor(&(**m_pimpl->m_transaction), &cursor, m_pimpl->m_cursorFlags);
		int ret = cursor->get(&dbKey, &dbData, DB_SET_RANGE);
		while(ret != DB_NOTFOUND)
		{
			StringPimpl dataString = StringPimpl((char *) dbData.get_data());
			StringPimpl keyString = StringPimpl((char *) dbKey.get_data());
			cout << "key :" << keyString.c_str() << endl << "data:" << dataString.c_str() << endl << endl;
			ret = cursor->get(&dbKey, &dbData, DB_NEXT);
		}
		cursor->close();
	}
	catch (DbException &e) 
	{
		std::cerr << "Error in deleteRecordRange: "
				   << e.what() << e.get_errno() << std::endl;
		if(cursor != NULL)
		{
			cursor->close();
		}
	}
}
开发者ID:Tiger66639,项目名称:librebecca,代码行数:30,代码来源:DatabaseManager.cpp

示例3: partDbFind

Header* MultiPartHeader::partDbFind(Db* pdb, quint16 partNo)
{
	int ret = 0;
	Header* h = 0;
    Dbc *cursorp = 0;

	Dbt key;
	Dbt data;

	key.set_data(&multiPartKey);
	key.set_size(sizeof(quint64));

	data.set_data(&partNo);
	data.set_size(sizeof(quint16));

	// Get a cursor
	pdb->cursor(NULL, &cursorp, 0);

	// Position the cursor to the first record in the database whose
	// key matches the search key and whose data begins with the search
	// data.
	if  (!(ret = cursorp->get(&key, &data, DB_GET_BOTH_RANGE)))
	{
		h = new Header((char*)data.get_data(), (char*)key.get_data());
	}

	// Close the cursor
	if (cursorp != NULL)
	    cursorp->close();

	return h;
}
开发者ID:quban2,项目名称:quban,代码行数:32,代码来源:MultiPartHeader.cpp

示例4: readBlockBerkeleyDB

AntiCacheBlock AntiCacheDB::readBlockBerkeleyDB(std::string tableName, int16_t blockId) {
    
    Dbt key;
    key.set_data(&blockId);
    key.set_size(sizeof(int16_t));

    Dbt value;
    value.set_flags(DB_DBT_MALLOC);
    
    VOLT_DEBUG("Reading evicted block with id %d", blockId);
    
    int ret_value = m_db->get(NULL, &key, &value, 0);
    if (ret_value != 0) 
    {
        VOLT_ERROR("Invalid anti-cache blockId '%d' for table '%s'", blockId, tableName.c_str());
        throw UnknownBlockAccessException(tableName, blockId);
    }
    else 
    {
//        m_db->del(NULL, &key, 0);  // if we have this the benchmark won't end
        assert(value.get_data() != NULL);
    }
    
    AntiCacheBlock block(blockId, static_cast<char*>(value.get_data()), value.get_size());
    return (block);
}
开发者ID:huanchenz,项目名称:h-store-index,代码行数:26,代码来源:AntiCacheDB.cpp

示例5: getGroup

HeaderGroup* BulkHeaderGroup::getGroup(NewsGroup* ng, QString& articleIndex)
{
    HeaderGroup *hg = 0;

    int ret;
    Dbt groupkey;
    Dbt groupdata;
    memset(&groupkey, 0, sizeof(groupkey));
    memset(&groupdata, 0, sizeof(groupdata));
    groupdata.set_flags(DB_DBT_MALLOC);

    QByteArray ba = articleIndex.toLocal8Bit();
    const char *k= ba.constData();
    groupkey.set_data((void*)k);
    groupkey.set_size(articleIndex.length());

    Db* groupsDb = ng->getGroupingDb();
    ret=groupsDb->get(NULL, &groupkey, &groupdata, 0);
    if (ret != 0) //key not found
    {
        qDebug() << "Failed to find group with key " << articleIndex;
    }
    else
    {
        qDebug() << "Found group with key " << articleIndex;

        hg=new HeaderGroup(articleIndex.length(), (char*)k, (char*)groupdata.get_data());
        void* ptr = groupdata.get_data();
        Q_FREE(ptr);
    }

    return hg;
}
开发者ID:quban2,项目名称:quban,代码行数:33,代码来源:bulkHeaderGroup.cpp

示例6: memcmp

bool operator==(const Dbt&d1, const Dbt&d2)  
{
	if (d1.get_size() != d2.get_size())
		return false;

	return memcmp(d1.get_data(), d2.get_data(), 
	    d2.get_size()) == 0;
}
开发者ID:CompassHXM,项目名称:h-store,代码行数:8,代码来源:dbstl_container.cpp

示例7: dbdump

static int dbdump(const char *env_dir, const char *dbfile, const char *dbname) {
    int r;

#if defined(USE_ENV) && USE_ENV
    DbEnv env(DB_CXX_NO_EXCEPTIONS);
    r = env.set_redzone(0); assert(r==0);
    r = env.open(env_dir, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0);
    Db db(&env, DB_CXX_NO_EXCEPTIONS);
#else
    Db db(0, DB_CXX_NO_EXCEPTIONS);
#endif
    r = db.open(0, dbfile, dbname, DB_UNKNOWN, 0, 0777); 
    if (r != 0) {
        printf("cant open %s:%s %d:%s\n", dbfile, dbname, r, db_strerror(r));
#if defined(USE_ENV) && USE_ENV
        r = env.close(0); assert(r == 0);
#endif
        return 1;
    }

    u_int32_t dbflags;
    r = db.get_flags(&dbflags); assert(r == 0);
#ifndef TOKUDB
    if (dbflags & DB_DUP)
        printf("duplicates=1\n");
    if (dbflags & DB_DUPSORT)
        printf("dupsort=1\n");
#endif
#if 0
    u_int32_t nodesize;
    r = db.get_nodesize(&nodesize); assert(r == 0);
    printf("nodesize=%d\n", nodesize);
#endif

    Dbc *cursor;
    r = db.cursor(0, &cursor, 0); assert(r == 0);

    Dbt key; key.set_flags(DB_DBT_REALLOC);
    Dbt val; val.set_flags(DB_DBT_REALLOC);
    for (;;) {
        r = cursor->get(&key, &val, DB_NEXT);
        if (r != 0) break;
        // printf("%.*s\n", key.get_size(), (char *)key.get_data());
        hexdump(&key);
        // printf("%.*s\n", val.get_size(), (char *)val.get_data());
        hexdump(&val);
    }
    if (key.get_data()) toku_free(key.get_data());
    if (val.get_data()) toku_free(val.get_data());

    r = cursor->close(); assert(r == 0);
    r = db.close(0); assert(r == 0);
#if defined(USE_ENV) && USE_ENV
    r = env.close(0); assert(r == 0);
#endif
    return 0;
}
开发者ID:Alienfeel,项目名称:ft-index,代码行数:57,代码来源:db_dump.cpp

示例8: db

vector<string>
Freeze::EvictorIBase::allDbs() const
{
    vector<string> result;

    try
    {
        Db db(_dbEnv->getEnv(), 0);

        //
        // Berkeley DB expects file paths to be UTF8 encoded.
        //
        db.open(0, nativeToUTF8(_filename, getProcessStringConverter()).c_str(), 0, DB_UNKNOWN,
                DB_RDONLY, 0);

        Dbc* dbc = 0;
        db.cursor(0, &dbc, 0);

        Dbt dbKey;
        dbKey.set_flags(DB_DBT_MALLOC);

        Dbt dbValue;
        dbValue.set_flags(DB_DBT_USERMEM | DB_DBT_PARTIAL);

        bool more = true;
        while(more)
        {
            more = (dbc->get(&dbKey, &dbValue, DB_NEXT) == 0);
            if(more)
            {
                string dbName(static_cast<char*>(dbKey.get_data()), dbKey.get_size());

                if(dbName.find(indexPrefix) != 0)
                {
                    result.push_back(dbName);
                }
                free(dbKey.get_data());
            }
        }

        dbc->close();
        db.close(0);
    }
    catch(const DbException& dx)
    {
        if(dx.get_errno() != ENOENT)
        {
            DatabaseException ex(__FILE__, __LINE__);
            ex.message = dx.what();
            throw ex;
        }
    }

    return result;
}
开发者ID:ming-hai,项目名称:freeze,代码行数:55,代码来源:EvictorI.cpp

示例9: guard

void berkeleydb_store<Object>::get_range(const timestamp& from,
                                         const timestamp& to,
                                         const long lp_id,
                                         std::vector<obj_ptr>& ret_obj) {
  boost::lock_guard<boost::mutex> guard(get_mutex_);
  if (from > to) return;

  /* generate key */
  std::vector<char> from_char;
  key_lpid_to_char(from, lp_id, from_char);
  Dbt db_key = Dbt(&from_char[0], from_char.size());

  /* prepare data */
  char* binary;
  Dbt data;
  data.set_data(binary);
  data.set_flags(DB_DBT_MALLOC);

  /* seek to from */
  Dbc* cursorp;
  db->cursor(NULL, &cursorp, 0);
  int ret = cursorp->get(&db_key, &data, DB_SET_RANGE);
  if (ret) {
    if (cursorp != NULL) cursorp->close();
    return;
  }
  std::string get_data_binary
      = std::string((char*) data.get_data(), data.get_size());
  std::stringstream from_ss;
  from_ss << get_data_binary;
  boost::archive::binary_iarchive iar(from_ss);
  Object obj;
  iar >> obj;
  ret_obj.push_back(boost::make_shared<Object>(obj));

  /* get until end */
  while ((ret = cursorp->get(&db_key, &data, DB_NEXT)) == 0) {
    timestamp tmstmp;
    long id;
    char_to_key_lpid((char*) db_key.get_data(), tmstmp, id);
    if (tmstmp > to || id != lp_id) break;

    get_data_binary = std::string((char*) data.get_data(), data.get_size());
    std::stringstream ss;
    ss << get_data_binary;
    boost::archive::binary_iarchive iar(ss);
    Object deserialized_obj;
    iar >> deserialized_obj;
    ret_obj.push_back(boost::make_shared<Object>(deserialized_obj));
  }

  if (cursorp != NULL) cursorp->close();
};
开发者ID:masatoshihanai,项目名称:ScaleSim,代码行数:53,代码来源:berkeleydb_store.hpp

示例10: next

bool DbMultipleDataIterator::next(Dbt &data)
{
	if (*p_ == (u_int32_t)-1) {
		data.set_data(0);
		data.set_size(0);
		p_ = 0;
	} else {
		data.set_data(data_ + *p_--);
		data.set_size(*p_--);
		if (data.get_size() == 0 && data.get_data() == data_)
			data.set_data(0);
	}
	return (data.get_data() != 0);
}
开发者ID:SergeStinckwich,项目名称:openqwaq,代码行数:14,代码来源:cxx_multi.cpp

示例11: main

int main(int argc, char *argv[])
{
	try {
		Db *db = new Db(NULL, 0);
		db->open(NULL, "my.db", NULL, DB_BTREE, DB_CREATE, 0644);

		// populate our massive database.
		// all our strings include null for convenience.
		// Note we have to cast for idiomatic
		// usage, since newer gcc requires it.
		Dbt *keydbt = new Dbt((char *)"key", 4);
		Dbt *datadbt = new Dbt((char *)"data", 5);
		db->put(NULL, keydbt, datadbt, 0);

		// Now, retrieve.  We could use keydbt over again,
		// but that wouldn't be typical in an application.
		Dbt *goodkeydbt = new Dbt((char *)"key", 4);
		Dbt *badkeydbt = new Dbt((char *)"badkey", 7);
		Dbt *resultdbt = new Dbt();
		resultdbt->set_flags(DB_DBT_MALLOC);

		int ret;

		if ((ret = db->get(NULL, goodkeydbt, resultdbt, 0)) != 0) {
			cout << "get: " << DbEnv::strerror(ret) << "\n";
		}
		else {
			char *result = (char *)resultdbt->get_data();
			cout << "got data: " << result << "\n";
		}

		if ((ret = db->get(NULL, badkeydbt, resultdbt, 0)) != 0) {
			// We expect this...
			cout << "get using bad key: "
			     << DbEnv::strerror(ret) << "\n";
		}
		else {
			char *result = (char *)resultdbt->get_data();
			cout << "*** got data using bad key!!: "
			     << result << "\n";
		}
		cout << "finished test\n";
	}
	catch (DbException &dbe) {
		cerr << "Db Exception: " << dbe.what();
	}
	return 0;
}
开发者ID:RomiPierre,项目名称:osx,代码行数:48,代码来源:TestSimpleAccess.cpp

示例12: readLastRec

void* BDBFile::readLastRec(void* key_, unsigned int keySize_)    
{
  assert(dbHandle != NULL);
  Dbt key;
  Dbt data;
  int rtrnCode = this->cursorRead(key, data, DB_LAST);
  if (rtrnCode > 0) {
    key_ = NULL;
    keySize_ = 0;
    return NULL;
  } else {
    key_ = key.get_data();
    keySize_ = key.get_size();
    return data.get_data();
  }
}
开发者ID:mesadb,项目名称:mesadb.github.io,代码行数:16,代码来源:BDBFile.cpp

示例13: getAllArticleNums

void MultiPartHeader::getAllArticleNums(Db* pDB, PartNumMap* serverArticleNos, QMap<quint16, quint64>* partSize,QMap<quint16, QString>* partMsgId)
{
	quint64 multiPartKey = getMultiPartKey();
    Header* h = 0;

	// Walk the headers to get the PartNumMap
    Dbc *cursorp = 0;

	// Get a cursor
	pDB->cursor(NULL, &cursorp, 0);

	// Set up our DBTs
	Dbt key(&multiPartKey, sizeof(quint64));
	Dbt data;

	int ret = cursorp->get(&key, &data, DB_SET);

	while (ret != DB_NOTFOUND)
	{
		h = new Header((char*)data.get_data(), (char*)key.get_data());
		serverArticleNos->insert(h->getPartNo(), h->getServerArticlemap());
		partSize->insert(h->getPartNo(), h->getSize());
		partMsgId->insert(h->getPartNo(), h->getMessageId());

        Q_DELETE(h);
		ret = cursorp->get(&key, &data, DB_NEXT_DUP);
	}

	if (cursorp != NULL)
	    cursorp->close();
}
开发者ID:quban2,项目名称:quban,代码行数:31,代码来源:MultiPartHeader.cpp

示例14: db_key

void berkeleydb_store<Object>::get(const timestamp& time,
                                   const long lp_id,
                                   obj_ptr& ret) {
  boost::lock_guard<boost::mutex> guard(get_mutex_);
  /* generate key */
  std::vector<char> key;
  key_lpid_to_char(time, lp_id, key);
  Dbt db_key(&key[0], key.size());

  /* get data */
  char* event_binary;
  Dbt data;
  data.set_data(event_binary);
  data.set_flags(DB_DBT_MALLOC);

  db->get(NULL, &db_key, &data, 0);

  /* deserialize the data */
  std::string binary = std::string((char*) data.get_data(), data.get_size());
  std::stringstream from_ss;
  from_ss << binary;
  boost::archive::binary_iarchive iar(from_ss);
  Object obj;
  iar >> obj;

  ret = boost::make_shared<Object>(obj);
};
开发者ID:masatoshihanai,项目名称:ScaleSim,代码行数:27,代码来源:berkeleydb_store.hpp

示例15: getRegionName

/* This function searches region name db according to relation ID
 * and put the region name and namespace strings into the last twqo arguments.
 * at the end of region name in parenthesis. BY default it is false.
 * Returns -1 or -2 for exceptions;
 * returns 0 if record is not found;
 * returns -3 for any other errors;
 * returns 1 if record is found and variables are assisgned successfully.
 */
int getRegionName(string dbHome, string rDbName, long rID_in, 
		  string & rName_out, string & space_out)
{
  mydb rDB(dbHome, rDbName, DB_RDONLY);  
  Dbc *cursorp;
  Dbt key(&rID_in, sizeof(rID_in)); 
  Dbt data;
  long foo = -3;
  try {    
    rDB.getDb().cursor(NULL, &cursorp, 0);    
    int ret = cursorp->get(&key, &data, DB_SET);
    if (!ret) {
      regionRec rData(data.get_data());
      rName_out = rData.getName();
      space_out = rData.getNameSpace();
      foo = 1;
    }
    else if (ret == DB_NOTFOUND)
      foo = 0;
  } 
  catch(DbException &e) {
    rDB.getDb().err(e.get_errno(), "Error in getRegionName()");
    foo = -1;
  } 
  catch(exception &e) {
    rDB.getDb().errx("Error in getRegionName(): %s", e.what());
    foo = -2;
  }
  cursorp->close();

  return foo;
}
开发者ID:Ampelbein,项目名称:voxbo,代码行数:40,代码来源:brain_util.cpp


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