From: Damyan Ivanov Date: Fri, 26 Mar 2021 16:54:20 +0000 (+0200) Subject: fix SQL when cleaning obsolete transaction/accounts X-Git-Tag: v0.18.0~97 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=85de776bda14d9fe73b60b40b5f73c6ed84c1494;hp=9d9baff5b649eda7609fe77fe6d6aadf986bb300;p=mobile-ledger.git fix SQL when cleaning obsolete transaction/accounts --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java index 6f70bda5..826ed397 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -566,17 +566,20 @@ public final class MobileLedgerProfile { } private void deleteNotPresentAccounts(SQLiteDatabase db, int generation) { Logger.debug("db/benchmark", "Deleting obsolete accounts"); - db.execSQL("DELETE FROM account_values WHERE profile=? AND generation <> ?", + db.execSQL("DELETE FROM account_values WHERE (select a.profile_id from accounts a where a" + + ".id=account_values.account_id)=? AND generation <> ?", new Object[]{id, generation}); - db.execSQL("DELETE FROM accounts WHERE profile=? AND generation <> ?", + db.execSQL("DELETE FROM accounts WHERE profile_id=? AND generation <> ?", new Object[]{id, generation}); Logger.debug("db/benchmark", "Done deleting obsolete accounts"); } private void deleteNotPresentTransactions(SQLiteDatabase db, int generation) { Logger.debug("db/benchmark", "Deleting obsolete transactions"); - db.execSQL("DELETE FROM transaction_accounts WHERE profile=? AND generation <> ?", + db.execSQL( + "DELETE FROM transaction_accounts WHERE (select t.profile_id from transactions t " + + "where t.id=transaction_accounts.transaction_id)=? AND generation" + " <> ?", new Object[]{id, generation}); - db.execSQL("DELETE FROM transactions WHERE profile=? AND generation <> ?", + db.execSQL("DELETE FROM transactions WHERE profile_id=? AND generation <> ?", new Object[]{id, generation}); Logger.debug("db/benchmark", "Done deleting obsolete transactions"); }