From f7ec1d6580d6b94484c4b15a4e11822801b5843c Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Mon, 18 Mar 2019 11:26:49 +0200 Subject: [PATCH] remove all profile data when removing a profile --- .../mobileledger/model/MobileLedgerProfile.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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 17b6ac7a..71b53cd7 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -282,8 +282,19 @@ public final class MobileLedgerProfile { } public void removeFromDB() { SQLiteDatabase db = MLDB.getWritableDatabase(); - Log.d("db", String.format("removing progile %s from DB", uuid)); - db.execSQL("delete from profiles where uuid=?", new Object[]{uuid}); + Log.d("db", String.format("removing profile %s from DB", uuid)); + try { + db.beginTransaction(); + db.execSQL("delete from profiles where uuid=?", new Object[]{uuid}); + db.execSQL("delete from accounts where profile=?", new Object[]{uuid}); + db.execSQL("delete from account_values where profile=?", new Object[]{uuid}); + db.execSQL("delete from transactions where profile=?", new Object[]{uuid}); + db.execSQL("delete from transaction_accounts where profile=?", new Object[]{uuid}); + db.setTransactionSuccessful(); + } + finally { + db.endTransaction(); + } } @NonNull public LedgerAccount loadAccount(String name) { -- 2.39.5