X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FMobileLedgerProfile.java;h=826ed397d55b74b0cc0c951add20365418082f39;hb=85de776bda14d9fe73b60b40b5f73c6ed84c1494;hp=a7a6eeab98749876188044cf200c47ee8e1dcb0b;hpb=1fd204fbd59c59032c67d8451b28307a2bf89e2f;p=mobile-ledger.git 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 a7a6eeab..826ed397 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -547,41 +547,39 @@ public final class MobileLedgerProfile { this.themeHue = themeHue; } public int getNextTransactionsGeneration(SQLiteDatabase db) { - int generation = 1; try (Cursor c = db.rawQuery( "SELECT generation FROM transactions WHERE profile_id=? LIMIT 1", new String[]{String.valueOf(id)})) { - if (c.moveToFirst()) { - generation = c.getInt(0) + 1; - } + if (c.moveToFirst()) + return c.getInt(0) + 1; } - return generation; + return 1; } private int getNextAccountsGeneration(SQLiteDatabase db) { - int generation = 1; try (Cursor c = db.rawQuery("SELECT generation FROM accounts WHERE profile_id=? LIMIT 1", - new String[]{String.valueOf(id)})) - { - if (c.moveToFirst()) { - generation = c.getInt(0) + 1; - } + new String[]{String.valueOf(id)})) { + if (c.moveToFirst()) + return c.getInt(0) + 1; } - return generation; + return 1; } 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"); }