From: Damyan Ivanov Date: Mon, 18 Mar 2019 09:26:49 +0000 (+0200) Subject: remove all profile data when removing a profile X-Git-Tag: v0.8.1~25 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=f7ec1d6580d6b94484c4b15a4e11822801b5843c;p=mobile-ledger.git remove all profile data when removing a profile --- 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) {