]> git.ktnx.net Git - mobile-ledger.git/commitdiff
account_update: replace delete/insert with three stage mark for removal, update/inser...
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 7 Dec 2018 05:56:34 +0000 (05:56 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 7 Dec 2018 05:56:34 +0000 (05:56 +0000)
not to remove/insert all the rows every time

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

index f1511f8051dc4fb4ee71eba7f98f49d65f0d295a..670b14935e21328d4453e3e77892eda69658e61e 100644 (file)
@@ -64,7 +64,7 @@ abstract public class RetrieveAccountsTask extends android.os.AsyncTask<SQLiteDa
                                 acct_name = acct_name.replace("\"", "");
                                 Log.d("account-parser", acct_name);
 
-                                db.execSQL("insert into accounts(name) values(?)", new Object[]{acct_name} );
+                                db.execSQL("insert or replace into accounts(name, keep) values(?, 1)", new Object[]{acct_name} );
                                 publishProgress(++count);
 
                                 last_account_name = acct_name;
@@ -87,11 +87,13 @@ abstract public class RetrieveAccountsTask extends android.os.AsyncTask<SQLiteDa
                                 if(currency == null) currency="";
                                 value = value.replace(',', '.');
                                 Log.d("db", "curr="+currency+", value="+value);
-                                db.execSQL("insert into account_values(account, currency, value) values(?, ?, ?);",
+                                db.execSQL("insert or replace into account_values(account, currency, value, keep) values(?, ?, ?, 1);",
                                         new Object[]{last_account_name, currency, Float.valueOf(value)});
                             }
                         }
 
+                        db.execSQL("delete from account_values where keep=0;");
+                        db.execSQL("delete from accounts where keep=0;");
                         db.setTransactionSuccessful();
                     }
                     finally {