]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/MobileLedgerDB.java
store transaction description history upon database refresh
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / MobileLedgerDB.java
index 2254cae784be0ad64ec1d3b05a03adc0772837d7..a4a078e7eb5b501c1a33dc8853847dfafa0d5ab3 100644 (file)
@@ -25,20 +25,9 @@ class MobileLedgerDB {
         MobileLedgerDB.db_filename = db_filename;
     }
 
-    static void initDB() {
+    static void initDB(Resources rm, String pkg_name) {
         db = SQLiteDatabase.openOrCreateDatabase(db_filename, null);
-
-        db.execSQL("create table if not exists accounts(name varchar);");
-        db.execSQL("create index if not exists idx_accounts_name on accounts(name);");
-        db.execSQL("create table if not exists options(name varchar, value varchar);");
-        db.execSQL("create unique index if not exists idx_options_name on options(name);");
-        db.execSQL("create table if not exists account_values(account varchar not null, currency varchar not null, value decimal(18,2) not null);");
-        db.execSQL("create index if not exists idx_account_values_account on account_values(account);");
-        db.execSQL("create unique index if not exists un_account_values on account_values(account,currency);");
-    }
-
-    static void applyRevisions(Resources rm, String pkg_name) {
-        int cur_ver = Integer.parseInt(get_option_value(OPT_DB_REVISION, "0"));
+        int cur_ver = Integer.parseInt(get_option_value(OPT_DB_REVISION, "-1"));
 
         Log.d("db", "Current DB revision is "+String.valueOf(cur_ver));
 
@@ -51,12 +40,12 @@ class MobileLedgerDB {
     private static boolean applyRevision(Resources rm, String pkg_name, int rev_no) {
         String rev_file = String.format(Locale.US, "sql_%d", rev_no);
 
-        db.beginTransaction();
         int res_id = rm.getIdentifier(rev_file, "raw", pkg_name);
         if (res_id == 0) {
             Log.d("db", String.format(Locale.US, "No resource for revision %d", rev_no));
             return false;
         }
+        db.beginTransaction();
         try (InputStream res = rm.openRawResource(res_id)) {
             Log.d("db", "Applying revision " + String.valueOf(rev_no));
             InputStreamReader isr = new InputStreamReader(res);