X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FMobileLedgerProfile.java;h=4be38d4aed442de5d3939dc22803fbf995eefbbd;hp=17b6ac7ae9b8128007c95fefd93a17ab0f978a42;hb=7a7e5a8003d62bcef2aafced877c35ff0043f21b;hpb=c6fe580ac5a93cff593d95a0fe34bd6c2c7bddfc 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..4be38d4a 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) { @@ -293,13 +304,13 @@ public final class MobileLedgerProfile { @Nullable public LedgerAccount tryLoadAccount(String acct_name) { SQLiteDatabase db = MLDB.getReadableDatabase(); - return loadAccount(acct_name); + return tryLoadAccount(db, acct_name); } @NonNull public LedgerAccount loadAccount(SQLiteDatabase db, String accName) { LedgerAccount acc = tryLoadAccount(db, accName); - if (acc == null) throw new RuntimeException("Unable to load account with name "+accName); + if (acc == null) throw new RuntimeException("Unable to load account with name " + accName); return acc; }