From 8feb9d6c29853e89deb0389317badf5529e01b82 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 17 Jan 2013 21:08:23 -0800 Subject: [PATCH] Handle an edge case. --- src/cpp/ripple/Ledger.cpp | 43 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index 9745e7ba85..2bdf42372e 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -415,29 +415,34 @@ void Ledger::saveAcceptedLedger(bool fromConsensus, LoadEvent::pointer event) if (!SQL_EXISTS(db, boost::str(AcctTransExists % item->getTag().GetHex()))) { // Transaction not in AccountTransactions - std::vector accts = meta.getAffectedAccounts(); - - std::string sql = "INSERT INTO AccountTransactions (TransID, Account, LedgerSeq) VALUES "; - bool first = true; - for (std::vector::iterator it = accts.begin(), end = accts.end(); it != end; ++it) + const std::vector accts = meta.getAffectedAccounts(); + if (!accts.empty()) { - if (!first) - sql += ", ('"; - else + + std::string sql = "INSERT INTO AccountTransactions (TransID, Account, LedgerSeq) VALUES "; + bool first = true; + for (std::vector::const_iterator it = accts.begin(), end = accts.end(); it != end; ++it) { - sql += "('"; - first = false; + if (!first) + sql += ", ('"; + else + { + sql += "('"; + first = false; + } + sql += txn.getTransactionID().GetHex(); + sql += "','"; + sql += it->humanAccountID(); + sql += "',"; + sql += boost::lexical_cast(getLedgerSeq()); + sql += ")"; } - sql += txn.getTransactionID().GetHex(); - sql += "','"; - sql += it->humanAccountID(); - sql += "',"; - sql += boost::lexical_cast(getLedgerSeq()); - sql += ")"; + sql += ";"; + Log(lsTRACE) << "ActTx: " << sql; + db->executeSQL(sql); // may already be in there } - sql += ";"; - Log(lsTRACE) << "ActTx: " << sql; - db->executeSQL(sql); // may already be in there + else + cLog(lsWARNING) << "Transaaction in ledger " << mLedgerSeq << " affects not accounts"; } if (SQL_EXISTS(db, boost::str(transExists % txn.getTransactionID().GetHex())))