From d4d3300eca984e3acf70b871a47ba7ddf179d9bb Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 11 Jun 2012 01:05:34 -0700 Subject: [PATCH 1/4] Typo --- src/DBInit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DBInit.cpp b/src/DBInit.cpp index 66a87f8af3..22d7b67d1a 100644 --- a/src/DBInit.cpp +++ b/src/DBInit.cpp @@ -4,7 +4,7 @@ const char *TxnDBInit[] = { "CREATE TABLE Transactions ( \ TransID CHARACTER(64) PRIMARY KEY, \ - TransType CHARACTER(24) \ + TransType CHARACTER(24), \ FromAcct CHARACTER(35), \ FromSeq BIGINT UNSIGNED, \ LedgerSeq BIGINT UNSIGNED, \ From 456beaa5bfdefe3e0535dcbd0afc8961555bf300 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 11 Jun 2012 01:05:42 -0700 Subject: [PATCH 2/4] Bugfixes. --- src/SerializedTransaction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp index a5fce40f25..4d502ee534 100644 --- a/src/SerializedTransaction.cpp +++ b/src/SerializedTransaction.cpp @@ -301,7 +301,7 @@ Json::Value SerializedTransaction::getJson(int options) const std::string SerializedTransaction::getSQLValueHeader() { - return "(TransID, TransType, FromAcct, FromSeq, CommitSeq, Status, RawTxn)"; + return "(TransID, TransType, FromAcct, FromSeq, LedgerSeq, Status, RawTxn)"; } std::string SerializedTransaction::getSQLInsertHeader() @@ -321,7 +321,7 @@ std::string SerializedTransaction::getSQL(Serializer rawTxn, uint32 inLedger, ch std::string rTxn; theApp->getTxnDB()->getDB()->escape( reinterpret_cast(rawTxn.getDataPtr()), rawTxn.getLength(), rTxn); - return str(boost::format("('%s', '%s', '%s', %d, %d, %c, '%s')") + return str(boost::format("('%s', '%s', '%s', '%d', '%d', '%c', %s)") % getTransactionID().GetHex() % getTransactionType() % getSourceAccount().humanAccountID() % getSequence() % inLedger % status % rTxn); } From 112c79229ceb8fc5360af9e7ce4ddec3e44261fd Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 11 Jun 2012 01:12:43 -0700 Subject: [PATCH 3/4] Cleanup chatty debug --- database/SqliteDatabase.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/database/SqliteDatabase.cpp b/database/SqliteDatabase.cpp index d29374acee..60d785d0c8 100644 --- a/database/SqliteDatabase.cpp +++ b/database/SqliteDatabase.cpp @@ -32,41 +32,43 @@ void SqliteDatabase::disconnect() bool SqliteDatabase::executeSQL(const char* sql, bool fail_ok) { sqlite3_finalize(mCurrentStmt); - int rc=sqlite3_prepare_v2(mConnection,sql,-1,&mCurrentStmt,NULL); - if( rc!=SQLITE_OK ) + int rc = sqlite3_prepare_v2(mConnection, sql, -1, &mCurrentStmt, NULL); + if (rc != SQLITE_OK ) { - if(!fail_ok) + if (!fail_ok) { +#ifdef DEBUG cout << "SQL Perror:" << rc << endl; -#ifdef DEBUG cout << "Statement: " << sql << endl; cout << "Error: " << sqlite3_errmsg(mConnection) << endl; #endif } - return(false); + return false; } - rc=sqlite3_step(mCurrentStmt); - if(rc==SQLITE_ROW) + rc = sqlite3_step(mCurrentStmt); + if (rc == SQLITE_ROW) { - mMoreRows=true; - }else if(rc==SQLITE_DONE) + mMoreRows = true; + } + else if (rc == SQLITE_DONE) { - mMoreRows=false; - }else + mMoreRows = false; + } + else { - mMoreRows=false; - if(!fail_ok) + mMoreRows = false; + if (!fail_ok) { - cout << "SQL Serror:" << rc << endl; #ifdef DEBUG + cout << "SQL Serror:" << rc << endl; cout << "Statement: " << sql << endl; cout << "Error: " << sqlite3_errmsg(mConnection) << endl; #endif } - return(false); + return false; } - return(true); + return true; } // tells you how many rows were changed by an update or insert From 6521ff52e3d36abe74e19570e944c329f9bbbe3c Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 11 Jun 2012 01:12:52 -0700 Subject: [PATCH 4/4] "Upsert" transactions if they're committed after they're stored. --- src/Ledger.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Ledger.cpp b/src/Ledger.cpp index 168c97cd56..0c3e95e8a3 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -293,7 +293,13 @@ void Ledger::saveAcceptedLedger(Ledger::pointer ledger) sql += ";"; Log(lsTRACE) << "ActTx: " << sql; db->executeSQL(sql); - db->executeSQL(txn.getSQLInsertHeader() + txn.getSQL(ledger->getLedgerSeq(), TXN_SQL_VALIDATED) + ";"); + if (!db->executeSQL( + txn.getSQLInsertHeader() + txn.getSQL(ledger->getLedgerSeq(), TXN_SQL_VALIDATED) + ";"), true) + { // transaction already in DB, update + db->executeSQL(boost::str(boost::format( + "UPDATE Transactions SET LedgerSeq = '%d', Status = '%c' WHERE TransID = '%s';") % + ledger->getLedgerSeq() % TXN_SQL_VALIDATED % txn.getTransactionID().GetHex())); + } // FIXME: If above updates no rows, modify seq/status (upsert) } db->executeSQL("COMMIT TRANSACTION;");