]> git.ktnx.net Git - mobile-ledger.git/commitdiff
proper update of accounts in DB keeping existing settings
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 14 Dec 2018 05:58:37 +0000 (05:58 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 14 Dec 2018 05:58:37 +0000 (05:58 +0000)
insert or replace is more like insert or delete and insert which destroys
the hidden flag

app/src/main/java/net/ktnx/mobileledger/RetrieveAccountsTask.java

index 75c405642293b8b10af761abfa13969fdb0df981..8532e1ac2f270c25dbb7d155fe4d71a734106817 100644 (file)
@@ -180,9 +180,11 @@ class RetrieveAccountsTask extends android.os.AsyncTask<Void, Integer, Void> {
         do {
             LedgerAccount acc = new LedgerAccount(name);
             db.execSQL(
-                    "insert or replace into accounts(name, name_upper, level, parent_name, keep) "
-                            + "values(?, ?, ?, ?, 1)",
-                    new Object[]{name, name.toUpperCase(), acc.getLevel(), acc.getParentName()});
+                    "update accounts set level = ?, keep = 1 where name = ?",
+                    new Object[]{acc.getLevel(), name});
+            db.execSQL("insert into accounts(name, name_upper, parent_name, level) select ?,?,"
+                            + "?,? " + "where (select changes() = 0)",
+                    new Object[]{name, name.toUpperCase(), acc.getParentName(), acc.getLevel()});
             name = acc.getParentName();
         } while (name != null);
     }