]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
minor optimization in getting next generation
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / MobileLedgerProfile.java
index 15be74b6be1c572ba9c4e65d4a94e84dab2bfcbd..6f70bda5498d283aa5d62b5ba346d34ec1806b2a 100644 (file)
@@ -449,7 +449,7 @@ public final class MobileLedgerProfile {
                     });
             db.execSQL("INSERT INTO transaction_accounts(transaction_id, " +
                        "order_no, account_name, amount, currency, comment, generation) " +
-                       "select ?, ?, ?, ?, ?, ?, ?, ? WHERE (select changes() = 0)",
+                       "select ?, ?, ?, ?, ?, ?, ? WHERE (select changes() = 0)",
                     new Object[]{tr.getId(), accountOrderNo, item.getAccountName(),
                                  item.getAmount(), Misc.nullIsEmpty(item.getCurrency()),
                                  item.getComment(), generation
@@ -547,27 +547,22 @@ 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");