mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-30 16:05:51 +00:00
Fix database getNextRow().
This commit is contained in:
@@ -86,18 +86,18 @@ HashedObject::pointer HashedObject::retrieve(const uint256& hash)
|
||||
uint32 index;
|
||||
std::vector<unsigned char> data;
|
||||
data.reserve(8192);
|
||||
if(1)
|
||||
|
||||
{
|
||||
ScopedLock sl(theApp->getHashNodeDB()->getDBLock());
|
||||
Database* db=theApp->getHashNodeDB()->getDB();
|
||||
|
||||
if(!db->executeSQL(sql.c_str()) || !db->startIterRows() || !db->getNextRow())
|
||||
if(!db->executeSQL(sql.c_str()) || !db->startIterRows())
|
||||
return HashedObject::pointer();
|
||||
|
||||
std::string type;
|
||||
db->getStr("ObjType", type);
|
||||
db->getStr("ObjType", type);
|
||||
if(type.size()==0) return HashedObject::pointer();
|
||||
|
||||
|
||||
index=db->getBigInt("LedgerIndex");
|
||||
|
||||
int size=db->getBinary("Object", NULL, 0);
|
||||
@@ -105,7 +105,7 @@ HashedObject::pointer HashedObject::retrieve(const uint256& hash)
|
||||
db->getBinary("Object", &(data.front()), size);
|
||||
db->endIterRows();
|
||||
}
|
||||
|
||||
|
||||
HashedObjectType htype=UNKNOWN;
|
||||
switch(type[0])
|
||||
{
|
||||
@@ -114,7 +114,7 @@ HashedObject::pointer HashedObject::retrieve(const uint256& hash)
|
||||
case 'A': htype=ACCOUNT_NODE; break;
|
||||
case 'N': htype=TRANSACTION_NODE; break;
|
||||
}
|
||||
|
||||
|
||||
HashedObject::pointer obj(new HashedObject(htype, index, data));
|
||||
obj->mHash=hash;
|
||||
#ifdef DEBUG
|
||||
@@ -122,3 +122,4 @@ HashedObject::pointer HashedObject::retrieve(const uint256& hash)
|
||||
#endif
|
||||
return obj;
|
||||
}
|
||||
// vim:ts=4
|
||||
|
||||
@@ -269,7 +269,8 @@ Ledger::pointer Ledger::getSQL(const std::string& sql)
|
||||
{
|
||||
ScopedLock sl(theApp->getLedgerDB()->getDBLock());
|
||||
Database *db = theApp->getLedgerDB()->getDB();
|
||||
if (!db->executeSQL(sql.c_str()) || !db->startIterRows() || !db->getNextRow())
|
||||
|
||||
if (!db->executeSQL(sql) || !db->startIterRows())
|
||||
return Ledger::pointer();
|
||||
|
||||
db->getStr("LedgerHash", hash);
|
||||
@@ -285,7 +286,7 @@ Ledger::pointer Ledger::getSQL(const std::string& sql)
|
||||
ledgerSeq = db->getBigInt("LedgerSeq");
|
||||
db->endIterRows();
|
||||
}
|
||||
|
||||
|
||||
Ledger::pointer ret=boost::make_shared<Ledger>(prevHash, transHash, accountHash, totCoins, closingTime, ledgerSeq);
|
||||
if (ret->getHash() != ledgerHash)
|
||||
{
|
||||
@@ -425,3 +426,4 @@ bool Ledger::isAcquiringAS(void)
|
||||
{
|
||||
return mAccountStateMap->isSynching();
|
||||
}
|
||||
// vim:ts=4
|
||||
|
||||
@@ -19,11 +19,11 @@ CKey::pointer PubKeyCache::locate(const NewcoinAddress& id)
|
||||
std::vector<unsigned char> data;
|
||||
data.reserve(65); // our public keys are actually 33 bytes
|
||||
int pkSize;
|
||||
if(1)
|
||||
|
||||
{ // is it in the database
|
||||
ScopedLock sl(theApp->getTxnDB()->getDBLock());
|
||||
Database* db=theApp->getTxnDB()->getDB();
|
||||
if(!db->executeSQL(sql.c_str()) || !db->startIterRows() || !db->getNextRow())
|
||||
if(!db->executeSQL(sql.c_str()) || !db->startIterRows())
|
||||
return CKey::pointer();
|
||||
pkSize=db->getBinary("PubKey", &(data.front()), data.size());
|
||||
db->endIterRows();
|
||||
@@ -36,7 +36,6 @@ CKey::pointer PubKeyCache::locate(const NewcoinAddress& id)
|
||||
return CKey::pointer();
|
||||
}
|
||||
|
||||
if(1)
|
||||
{ // put it in cache (okay if we race with another retriever)
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
mCache.insert(std::make_pair(id, ckp));
|
||||
@@ -46,7 +45,6 @@ CKey::pointer PubKeyCache::locate(const NewcoinAddress& id)
|
||||
|
||||
CKey::pointer PubKeyCache::store(const NewcoinAddress& id, CKey::pointer key)
|
||||
{ // stored if needed, returns cached copy (possibly the original)
|
||||
if(1)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
std::pair<std::map<NewcoinAddress,CKey::pointer>::iterator, bool> pit(mCache.insert(std::make_pair(id, key)));
|
||||
@@ -74,3 +72,4 @@ void PubKeyCache::clear()
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
mCache.empty();
|
||||
}
|
||||
// vim:ts=4
|
||||
|
||||
@@ -225,7 +225,7 @@ bool Transaction::save() const
|
||||
theApp->getTxnDB()->getDB()->escape(static_cast<const unsigned char *>(s.getDataPtr()), s.getLength(), rawTxn);
|
||||
sql.append(rawTxn);
|
||||
sql.append(");");
|
||||
|
||||
|
||||
ScopedLock sl(theApp->getTxnDB()->getDBLock());
|
||||
Database* db = theApp->getTxnDB()->getDB();
|
||||
return db->executeSQL(sql.c_str());
|
||||
@@ -237,12 +237,11 @@ Transaction::pointer Transaction::transactionFromSQL(const std::string& sql)
|
||||
std::string status;
|
||||
|
||||
rawTxn.reserve(2048);
|
||||
if(1)
|
||||
{
|
||||
ScopedLock sl(theApp->getTxnDB()->getDBLock());
|
||||
Database* db = theApp->getTxnDB()->getDB();
|
||||
|
||||
if (!db->executeSQL(sql.c_str(), true) || !db->startIterRows() || !db->getNextRow())
|
||||
if (!db->executeSQL(sql, true) || !db->startIterRows())
|
||||
return Transaction::pointer();
|
||||
|
||||
db->getStr("Status", status);
|
||||
@@ -258,7 +257,7 @@ Transaction::pointer Transaction::transactionFromSQL(const std::string& sql)
|
||||
Transaction::pointer tr = boost::make_shared<Transaction>(txn, true);
|
||||
|
||||
TransStatus st(INVALID);
|
||||
switch(status[0])
|
||||
switch (status[0])
|
||||
{
|
||||
case 'N': st = NEW; break;
|
||||
case 'A': st = INCLUDED; break;
|
||||
@@ -382,3 +381,4 @@ Json::Value Transaction::getJson(bool decorate, bool paid, bool credited) const
|
||||
|
||||
return ret;
|
||||
}
|
||||
// vim:ts=4
|
||||
|
||||
@@ -50,24 +50,18 @@ bool ValidationCollection::hasValidation(uint32 ledgerIndex,uint160& hanko,uint3
|
||||
db->escape(hanko.begin(),hanko.GetSerializeSize(),hankoStr);
|
||||
string sql=strprintf("SELECT ValidationID,seqnum from Validations where LedgerIndex=%d and hanko=%s",
|
||||
ledgerIndex,hankoStr.c_str());
|
||||
if(db->executeSQL(sql.c_str()))
|
||||
if(db->executeSQL(sql) && db->startIterRows())
|
||||
{
|
||||
if(db->startIterRows())
|
||||
uint32 currentSeqNum=db->getInt(1);
|
||||
if(currentSeqNum>=seqnum)
|
||||
{
|
||||
if(db->getNextRow())
|
||||
{
|
||||
uint32 currentSeqNum=db->getInt(1);
|
||||
if(currentSeqNum>=seqnum)
|
||||
{
|
||||
db->endIterRows();
|
||||
return(true);
|
||||
}
|
||||
// delete the old validation we were storing
|
||||
sql=strprintf("DELETE FROM Validations where ValidationID=%d",db->getInt(0));
|
||||
db->endIterRows();
|
||||
db->executeSQL(sql.c_str());
|
||||
}
|
||||
db->endIterRows();
|
||||
return(true);
|
||||
}
|
||||
// delete the old validation we were storing
|
||||
sql=strprintf("DELETE FROM Validations where ValidationID=%d",db->getInt(0));
|
||||
db->endIterRows();
|
||||
db->executeSQL(sql);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
@@ -191,7 +185,6 @@ void ValidationCollection::getValidations(uint32 ledgerIndex,vector<newcoin::Val
|
||||
string sql=strprintf("SELECT * From Validations where LedgerIndex=%d and wecare=1",ledgerIndex);
|
||||
|
||||
// TODO: ValidationCollection::getValidations(uint32 ledgerIndex)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -203,7 +196,6 @@ bool ValidationCollection::getConsensusLedger(uint32 ledgerIndex, uint256& ourHa
|
||||
bool ret=false;
|
||||
if(mIndexGroups.count(ledgerIndex))
|
||||
{
|
||||
|
||||
unsigned int maxVotes=theConfig.MIN_VOTES_FOR_CONSENSUS;
|
||||
vector< Group >& groups=mIndexGroups[ledgerIndex];
|
||||
Group empty;
|
||||
@@ -228,6 +220,7 @@ bool ValidationCollection::getConsensusLedger(uint32 ledgerIndex, uint256& ourHa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return(ret);
|
||||
}
|
||||
// vim:ts=4
|
||||
|
||||
@@ -190,7 +190,7 @@ LocalAccountFamily::pointer LocalAccountFamily::readFamily(const NewcoinAddress&
|
||||
ScopedLock sl(theApp->getWalletDB()->getDBLock());
|
||||
Database *db=theApp->getWalletDB()->getDB();
|
||||
|
||||
if(!db->executeSQL(sql.c_str()) || !db->startIterRows() || !db->getNextRow())
|
||||
if(!db->executeSQL(sql.c_str()) || !db->startIterRows())
|
||||
return LocalAccountFamily::pointer();
|
||||
|
||||
db->getStr("Comment", comment);
|
||||
@@ -456,8 +456,7 @@ void Wallet::load()
|
||||
|
||||
if(!db->startIterRows()) return;
|
||||
|
||||
while(db->getNextRow())
|
||||
{
|
||||
do {
|
||||
std::string strGenerator, strComment;
|
||||
|
||||
db->getStr("FamilyGenerator", strGenerator);
|
||||
@@ -476,7 +475,8 @@ void Wallet::load()
|
||||
f->setComment(strComment);
|
||||
}
|
||||
else assert(false);
|
||||
}
|
||||
} while(db->getNextRow());
|
||||
|
||||
db->endIterRows();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user