本文整理汇总了C++中Dbc::close方法的典型用法代码示例。如果您正苦于以下问题:C++ Dbc::close方法的具体用法?C++ Dbc::close怎么用?C++ Dbc::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dbc
的用法示例。
在下文中一共展示了Dbc::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ListAccountCreditDebit
void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)
{
bool fAllAccounts = (strAccount == "*");
Dbc* pcursor = GetCursor();
if (!pcursor)
throw runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor");
unsigned int fFlags = DB_SET_RANGE;
while (true)
{
// Read next record
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
if (fFlags == DB_SET_RANGE)
ssKey << boost::make_tuple(string("acentry"), (fAllAccounts? string("") : strAccount), uint64_t(0));
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
fFlags = DB_NEXT;
if (ret == DB_NOTFOUND)
break;
else if (ret != 0)
{
pcursor->close();
throw runtime_error("CWalletDB::ListAccountCreditDebit() : error scanning DB");
}
// Unserialize
string strType;
ssKey >> strType;
if (strType != "acentry")
break;
CAccountingEntry acentry;
ssKey >> acentry.strAccount;
if (!fAllAccounts && acentry.strAccount != strAccount)
break;
ssValue >> acentry;
ssKey >> acentry.nEntryNo;
entries.push_back(acentry);
}
pcursor->close();
}
示例2: ListAccountCreditDebit
void CWalletDB::ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries)
{
bool fAllAccounts = (strAccount == "*");
Dbc* pcursor = batch.GetCursor();
if (!pcursor)
throw std::runtime_error(std::string(__func__) + ": cannot create DB cursor");
bool setRange = true;
while (true)
{
// Read next record
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
if (setRange)
ssKey << std::make_pair(std::string("acentry"), std::make_pair((fAllAccounts ? std::string("") : strAccount), uint64_t(0)));
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
int ret = batch.ReadAtCursor(pcursor, ssKey, ssValue, setRange);
setRange = false;
if (ret == DB_NOTFOUND)
break;
else if (ret != 0)
{
pcursor->close();
throw std::runtime_error(std::string(__func__) + ": error scanning DB");
}
// Unserialize
std::string strType;
ssKey >> strType;
if (strType != "acentry")
break;
CAccountingEntry acentry;
ssKey >> acentry.strAccount;
if (!fAllAccounts && acentry.strAccount != strAccount)
break;
ssValue >> acentry;
ssKey >> acentry.nEntryNo;
entries.push_back(acentry);
}
pcursor->close();
}
示例3: recordRangeExists
bool DatabaseManager::recordRangeExists(const StringPimpl &key)
{
//Go through the range of the existence keys and
//add them to the list
Dbc *cursor = NULL;
try
{
Dbt dbKey((void *)key.c_str(), key.size() + 1);
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());
if(!keyString.startsWith(key) || keyString == key) {
//We are at the end of the range
break;
}
else
{
cursor->close();
return true;
}
}
cursor->close();
return false;
}
catch (DbException &e)
{
std::cerr << "Error in deleteRecordRange: "
<< e.what() << e.get_errno() << std::endl;
if(cursor != NULL)
{
cursor->close();
}
return false;
}
}
示例4: ListPubCoin
void CWalletDB::ListPubCoin(std::list<CZerocoinEntry>& listPubCoin)
{
Dbc* pcursor = GetCursor();
if (!pcursor)
throw runtime_error("CWalletDB::ListPubCoin() : cannot create DB cursor");
unsigned int fFlags = DB_SET_RANGE;
loop
{
// Read next record
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
if (fFlags == DB_SET_RANGE)
ssKey << make_pair(string("zerocoin"), CBigNum(0));
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);
fFlags = DB_NEXT;
if (ret == DB_NOTFOUND)
break;
else if (ret != 0)
{
pcursor->close();
throw runtime_error("CWalletDB::ListPubCoin() : error scanning DB");
}
// Unserialize
string strType;
ssKey >> strType;
if (strType != "zerocoin")
break;
CBigNum value;
ssKey >> value;
CZerocoinEntry zerocoinItem;
ssValue >> zerocoinItem;
listPubCoin.push_back(zerocoinItem);
}
pcursor->close();
}
示例5: find_last_block_depth
uint32_t bdb_common::find_last_block_depth(txn_guard_ptr txn)
{
Dbc* cursor;
db_blocks_->cursor(txn->get(), &cursor, 0);
BITCOIN_ASSERT(cursor != nullptr);
writable_data_type key, data;
if (cursor->get(key.get(), data.get(), DB_LAST) == DB_NOTFOUND)
return std::numeric_limits<uint32_t>::max();
BITCOIN_ASSERT(key.get()->get_size() == 4);
uint32_t last_block_depth = cast_chunk<uint32_t>(key.data());
cursor->close();
return last_block_depth;
}
示例6: print_stocks
// Display all the stock quote information in the database.
int RepMgrGSG::print_stocks(Db *dbp)
{
Dbc *dbc;
Dbt key, data;
#define MAXKEYSIZE 10
#define MAXDATASIZE 20
char keybuf[MAXKEYSIZE + 1], databuf[MAXDATASIZE + 1];
int ret, t_ret;
u_int32_t keysize, datasize;
if ((ret = dbp->cursor(NULL, &dbc, 0)) != 0) {
dbp->err(ret, "can't open cursor");
return (ret);
}
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
cout << "\tSymbol\tPrice" << endl
<< "\t======\t=====" << endl;
for (ret = dbc->get(&key, &data, DB_FIRST);
ret == 0;
ret = dbc->get(&key, &data, DB_NEXT)) {
keysize = key.get_size() > MAXKEYSIZE ? MAXKEYSIZE : key.get_size();
memcpy(keybuf, key.get_data(), keysize);
keybuf[keysize] = '\0';
datasize = data.get_size() >=
MAXDATASIZE ? MAXDATASIZE : data.get_size();
memcpy(databuf, data.get_data(), datasize);
databuf[datasize] = '\0';
cout << "\t" << keybuf << "\t" << databuf << endl;
}
cout << endl << flush;
if ((t_ret = dbc->close()) != 0 && ret == 0) {
cout << "closed cursor" << endl;
ret = t_ret;
}
switch (ret) {
case 0:
case DB_NOTFOUND:
case DB_LOCK_DEADLOCK:
return (0);
default:
return (ret);
}
}
示例7: db
vector<string>
Freeze::EvictorIBase::allDbs() const
{
vector<string> result;
try
{
Db db(_dbEnv->getEnv(), 0);
db.open(0, Ice::nativeToUTF8(_communicator, _filename).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;
}
示例8: Visit
bool Table::Visit(TableVisitor &tv)
{
if (!tv.IsForward())
return VisitBackward(tv);
ByteString bsKey, bsValue;
Dbc* cursor = NULL;
bool ret = true;
u_int32_t flags = DB_NEXT;
// TODO call tv.OnComplete() or error handling
if (db->cursor(NULL, &cursor, 0) != 0)
return false;
Dbt key, value;
if (tv.GetStartKey() && tv.GetStartKey()->length > 0)
{
key.set_data(tv.GetStartKey()->buffer);
key.set_size(tv.GetStartKey()->length);
flags = DB_SET_RANGE;
}
while (cursor->get(&key, &value, flags) == 0)
{
bsKey.size = key.get_size();
bsKey.length = key.get_size();
bsKey.buffer = (char*) key.get_data();
bsValue.size = value.get_size();
bsValue.length = value.get_size();
bsValue.buffer = (char*) value.get_data();
ret = tv.Accept(bsKey, bsValue);
if (!ret)
break;
if (bsKey.length > 2 && bsKey.buffer[0] == '@' && bsKey.buffer[1] == '@')
{
key.set_data((void*)"@@~");
key.set_size(3);
flags = DB_SET_RANGE;
}
else
flags = DB_NEXT;
}
cursor->close();
tv.OnComplete();
return ret;
}
示例9: get
//-------------------------------------------------------------------------------------------------
unsigned BDBPersister::get(const unsigned from, const unsigned to, Session& session,
bool (Session::*callback)(const Session::SequencePair& with, Session::RetransmissionContext& rctx)) const
{
unsigned last_seq(0);
get_last_seqnum(last_seq);
unsigned recs_sent(0), startSeqNum(find_nearest_highest_seqnum (from, last_seq));
const unsigned finish(to == 0 ? last_seq : to);
Session::RetransmissionContext rctx(from, to, session.get_next_send_seq());
if (!startSeqNum || from > finish)
{
GlobalLogger::log("No records found");
rctx._no_more_records = true;
(session.*callback)(Session::SequencePair(0, ""), rctx);
return 0;
}
KeyDataBuffer buffer(startSeqNum);
KeyDataPair keyPair(buffer);
Dbc *cursorp;
_db->cursor (0, &cursorp, 0);
int retval;
if ((retval = cursorp->get(&keyPair._key, &keyPair._data, DB_SET)) == 0)
{
do
{
const unsigned seqnum(buffer.keyBuf_.int_);
if (!seqnum || seqnum > finish)
break;
Session::SequencePair result(seqnum, buffer.dataBuf_);
++recs_sent;
if (!(session.*callback)(result, rctx))
break;
}
while(cursorp->get(&keyPair._key, &keyPair._data, DB_NEXT) == 0);
rctx._no_more_records = true;
(session.*callback)(Session::SequencePair(0, ""), rctx);
}
else
{
ostringstream ostr;
ostr << "record not found (" << db_strerror(retval) << ')';
GlobalLogger::log(ostr.str());
}
cursorp->close();
return recs_sent;
}
示例10: deleteRecordRange
void DatabaseManager::deleteRecordRange(const StringPimpl &key)
{
Dbc *cursor = NULL;
try
{
Dbt dbKey((void *)key.c_str(), key.size() + 1);
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());
if(!keyString.startsWith(key)) {
//We are at the end of the range
break;
}
cursor->del(0);
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();
}
}
}
示例11: get_any
bool CDBStrMultiMap::get_any( string &key , vector<string> &values )
{
if( db_is_open == false )
{
cout<<"==== Can not get items from BDB.BDB has not been opened."<<endl;
return false;
}
try{
Dbc *dbcq;
db->cursor(NULL, &dbcq, 0);
Dbt dbt_key1;
Dbt dbt_data1;
char* key_str;
char* data_str;
if( dbcq->get(&dbt_key1, &dbt_data1, DB_FIRST) == 0 )
{
key_str = (char*)dbt_key1.get_data();
for( ; key_str< key_str + strlen(key_str) ; key_str++ )
{
key += *key_str;
}
data_str = (char*)dbt_data1.get_data();
values.push_back( data_str );
dbcq->del(0);
//Dbt dbt_key2( *key_str , strlen(key_str) );
while( dbcq -> get(&dbt_key1, &dbt_data1, DB_SET) == 0 )
{
key_str = (char*)dbt_key1.get_data();
values.push_back( data_str );
dbcq->del(0);
}
}
dbcq->close();
}
catch( DbException &e)
{
cerr<<"!! Exception: "<<e.what()<<endl;
return false;
}
return true;
}
示例12: Prune
bool Table::Prune(Transaction* tx, const ByteString &prefix)
{
Dbc* cursor = NULL;
u_int32_t flags = DB_NEXT;
DbTxn* txn;
if (tx == NULL)
txn = NULL;
else
txn = tx->txn;
if (db->cursor(txn, &cursor, 0) != 0)
return false;
Dbt key, value;
if (prefix.length > 0)
{
key.set_data(prefix.buffer);
key.set_size(prefix.length);
flags = DB_SET_RANGE;
}
while (cursor->get(&key, &value, flags) == 0)
{
if (key.get_size() < prefix.length)
break;
if (strncmp(prefix.buffer, (char*)key.get_data(), prefix.length) != 0)
break;
// don't delete keys starting with @@
if (!(key.get_size() >= 2 &&
((char*)key.get_data())[0] == '@' &&
((char*)key.get_data())[1] == '@'))
cursor->del(0);
flags = DB_NEXT;
}
if (cursor)
cursor->close();
return true;
}
示例13: get_last_seqnum
//-------------------------------------------------------------------------------------------------
unsigned BDBPersister::get_last_seqnum(unsigned& sequence) const
{
Dbc *cursorp;
_db->cursor (0, &cursorp, 0);
KeyDataBuffer buffer;
KeyDataPair keyPair(buffer);
int retval(cursorp->get(&keyPair._key, &keyPair._data, DB_LAST));
cursorp->close();
if (retval)
{
ostringstream ostr;
ostr << "last record not found (" << db_strerror(retval) << ')';
GlobalLogger::log(ostr.str());
return 0;
}
return sequence = buffer.keyBuf_.int_;
}
示例14: removeServer
void MultiPartHeader::removeServer(Db* pDB, quint16 serverId)
{
serverPart.remove(serverId);
serverLowest.remove(serverId);
quint64 multiPartKey = getMultiPartKey();
Header* h = 0;
// Walk the headers to get the PartNumMap
Dbc *cursorp = 0;
// Get a cursor
pDB->cursor(NULL, &cursorp, DB_WRITECURSOR);
// 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());
if (h->isHeldByServer(serverId))
{
h->removeServerPartNum(serverId);
if (h->isServerNumMapEmpty())
{
cursorp->del(0);
size-=h->getSize();
missingParts++;
}
}
Q_DELETE(h);
ret = cursorp->get(&key, &data, DB_NEXT_DUP);
}
if (cursorp != NULL)
cursorp->close();
}
示例15: get_index
bool CDBStrMultiMap::get_index( vector<string> &indexvec )
{
if( db_is_open == false )
{
cout<<"==== Can not get items from BDB.BDB has not been opened."<<endl;
return false;
}
try{
Dbc *dbcp;
db->cursor(NULL, &dbcp, 0);
Dbt dbt_key1;
Dbt dbt_data1;
char* key_str;
//char* data_str;
string key;
while( dbcp->get(&dbt_key1, &dbt_data1, DB_NEXT ) ==0 )
{
key_str = (char*)dbt_key1.get_data();
//get the key
for( ; key_str < key_str + strlen(key_str) ; key_str++ )
{
key += *key_str;
}
if( find( indexvec.begin(), indexvec.end(), key ) == indexvec.end() ){ //if it is not a duplicate key
indexvec.push_back( key );
}
key.clear();
//dbcp->del(0);
}
dbcp->close();
}
catch( DbException &e)
{
cerr<<"!! Exception: "<<e.what()<<endl;
return false;
}
return true;
}