Skip to content

Commit

Permalink
Bug 798789 - Trading Accounts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jralls committed Oct 6, 2024
1 parent 292adf6 commit 7f8d545
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions libgnucash/backend/sql/gnc-sql-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions libgnucash/backend/sql/gnc-transaction-sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "Account.h"
#include "Transaction.h"
#include <TransactionP.hpp>
#include <Scrub.h>
#include "gnc-lot.h"
#include "engine-helpers.h"
Expand Down Expand Up @@ -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();
}


Expand Down

0 comments on commit 7f8d545

Please sign in to comment.