gnucash stable: Bug 798789 - Trading Accounts

John Ralls jralls at code.gnucash.org
Sun Oct 6 17:17:11 EDT 2024


Updated	 via  https://github.com/Gnucash/gnucash/commit/7f8d5456 (commit)
	from  https://github.com/Gnucash/gnucash/commit/292adf69 (commit)



commit 7f8d5456c79406eb4516d411696e60d747c7bda8
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Oct 6 14:09:57 2024 -0700

    Bug 798789 - Trading Accounts
    
    Scrubbing during SQL load can't commit the changes from the scrub
    because the backend's m_loading member is true so disable scrubbing
    during database load and edit/commit all transactions again after
    loading is complete.

diff --git a/libgnucash/backend/sql/gnc-sql-backend.cpp b/libgnucash/backend/sql/gnc-sql-backend.cpp
index 09bd5d318b..49a040582c 100644
--- a/libgnucash/backend/sql/gnc-sql-backend.cpp
+++ b/libgnucash/backend/sql/gnc-sql-backend.cpp
@@ -271,6 +271,13 @@ typedef struct
     gnc_sql_query_info* pQueryInfo;
 } sql_backend;
 
+static void
+scrub_txn_callback (QofInstance* inst, [[maybe_unused]] void* data)
+{
+    auto trans = GNC_TRANSACTION(inst);
+    xaccTransBeginEdit(trans);
+    xaccTransCommitEdit(trans);
+}
 
 void
 GncSqlBackend::load (QofBook* book, QofBackendLoadType loadType)
@@ -336,6 +343,12 @@ GncSqlBackend::load (QofBook* book, QofBackendLoadType loadType)
                       gnc_commodity_commit_edit(comm);
                   });
     m_postload_commodities.clear();
+    /* We deferred the transaction scrub while loading because having
+     * m_loading true prevents changes from being written back to the
+     * database. Do that now.
+     */
+    auto transactions = qof_book_get_collection (book, GNC_ID_TRANS);
+    qof_collection_foreach(transactions, scrub_txn_callback, nullptr);
 
     /* Mark the session as clean -- though it should never be marked
      * dirty with this backend
diff --git a/libgnucash/backend/sql/gnc-transaction-sql.cpp b/libgnucash/backend/sql/gnc-transaction-sql.cpp
index e600c923e0..04aa286089 100644
--- a/libgnucash/backend/sql/gnc-transaction-sql.cpp
+++ b/libgnucash/backend/sql/gnc-transaction-sql.cpp
@@ -36,6 +36,7 @@
 
 #include "Account.h"
 #include "Transaction.h"
+#include <TransactionP.hpp>
 #include <Scrub.h>
 #include "gnc-lot.h"
 #include "engine-helpers.h"
@@ -389,10 +390,12 @@ query_transactions (GncSqlBackend* sql_be, std::string selector)
 					     (BookLookupFn)xaccTransLookup);
     }
 
-    // Commit all of the transactions
+    // Commit all of the transactions, but don't scrub because any
+    // scrubbing changes won't be written back to the database
+    xaccDisableDataScrubbing();
     for (auto instance : instances)
          xaccTransCommitEdit(GNC_TRANSACTION(instance));
-
+    xaccEnableDataScrubbing();
 }
 
 



Summary of changes:
 libgnucash/backend/sql/gnc-sql-backend.cpp     | 13 +++++++++++++
 libgnucash/backend/sql/gnc-transaction-sql.cpp |  7 +++++--
 2 files changed, 18 insertions(+), 2 deletions(-)



More information about the gnucash-changes mailing list