From: Damyan Ivanov Date: Sat, 15 Aug 2020 12:00:37 +0000 (+0000) Subject: new currency ID: without (not working) dance around duplicate IDs X-Git-Tag: v0.15.0~65 X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=commitdiff_plain;h=7526e4b8588361e218b5215f77bc7445e02ba970 new currency ID: without (not working) dance around duplicate IDs --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/Currency.java b/app/src/main/java/net/ktnx/mobileledger/model/Currency.java index 6933930b..28e6d03e 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Currency.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Currency.java @@ -60,21 +60,13 @@ public class Currency { } public Currency(MobileLedgerProfile profile, String name, Position position, boolean hasGap) { SQLiteDatabase db = App.getDatabase(); - int attempts = 0; - while (true) { - if (++attempts > 10) - throw new RuntimeException("Giving up getting next ID after 10 attempts"); - try (Cursor c = db.rawQuery("select max(rowid) from currencies", null)) { - c.moveToNext(); - int nextId = c.getInt(0) + 1; - db.execSQL("insert into currencies(id, name, position, has_gap) values(?, ?, ?, ?)", - new Object[]{nextId, name, position.toString(), hasGap}); - - this.id = nextId; - break; - } + try (Cursor c = db.rawQuery("select max(rowid) from currencies", null)) { + c.moveToNext(); + this.id = c.getInt(0) + 1; } + db.execSQL("insert into currencies(id, name, position, has_gap) values(?, ?, ?, ?)", + new Object[]{this.id, name, position.toString(), hasGap}); this.name = name; this.position = position;