]> git.ktnx.net Git - mobile-ledger.git/commitdiff
transactions.id -> integer
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 19 Dec 2018 20:48:48 +0000 (20:48 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 19 Dec 2018 20:48:48 +0000 (20:48 +0000)
app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java
app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java
app/src/main/res/raw/sql_9.sql [new file with mode: 0644]

index fab4ff3e0d1f2988eacd0f06be35687bb20c758e..c4127ab81641eaf679cc91efd7074fddecb0c18c 100644 (file)
@@ -41,13 +41,13 @@ public class LedgerTransaction {
                     return Float.compare(o1.getAmount(), o2.getAmount());
                 }
             };
-    private String id;
+    private Integer id;
     private String date;
     private String description;
     private ArrayList<LedgerTransactionItem> items;
     private String dataHash;
     private boolean dataLoaded;
-    public LedgerTransaction(String id, String date, String description) {
+    public LedgerTransaction(Integer id, String date, String description) {
         this.id = id;
         this.date = date;
         this.description = description;
@@ -55,9 +55,6 @@ public class LedgerTransaction {
         this.dataHash = null;
         dataLoaded = false;
     }
-    public LedgerTransaction(int id, String date, String description) {
-        this(String.valueOf(id), date, description);
-    }
     public LedgerTransaction(String date, String description) {
         this(null, date, description);
     }
@@ -96,13 +93,13 @@ public class LedgerTransaction {
             }
         };
     }
-    public String getId() {
+    public int getId() {
         return id;
     }
     public void insertInto(SQLiteDatabase db) {
         fillDataHash();
         db.execSQL("INSERT INTO transactions(id, date, description, data_hash) values(?,?,?,?)",
-                new String[]{id, date, description});
+                new Object[]{id, date, description, dataHash});
 
         for (LedgerTransactionItem item : items) {
             db.execSQL("INSERT INTO transaction_accounts(transaction_id, account_name, amount, " +
@@ -137,20 +134,20 @@ public class LedgerTransaction {
     public void loadData(SQLiteDatabase db) {
         if (dataLoaded) return;
 
-        try (Cursor cTr = db.rawQuery("SELECT date, description from transactions WHERE " +
-                                         "id=?",new String[]{id})) {
+        try (Cursor cTr = db.rawQuery("SELECT date, description from transactions WHERE id=?",
+                new String[]{String.valueOf(id)}))
+        {
             if (cTr.moveToFirst()) {
                 date = cTr.getString(0);
                 description = cTr.getString(1);
 
                 try (Cursor cAcc = db.rawQuery("SELECT account_name, amount, currency FROM " +
                                                "transaction_accounts WHERE transaction_id = ?",
-                        new String[]{id}))
+                        new String[]{String.valueOf(id)}))
                 {
                     while (cAcc.moveToNext()) {
-                        add_item(
-                                new LedgerTransactionItem(cAcc.getString(0), cAcc.getFloat(1),
-                                        cAcc.getString(2)));
+                        add_item(new LedgerTransactionItem(cAcc.getString(0), cAcc.getFloat(1),
+                                cAcc.getString(2)));
                     }
 
                     dataLoaded = true;
index 9d8950a6c373c925bd89176b49c4abb8c6ca6b0e..2773dc9f6cc4af4616f59373bdb515297f6d7f38 100644 (file)
@@ -117,7 +117,7 @@ public final class MLDB {
 
 class MobileLedgerDatabase extends SQLiteOpenHelper implements AutoCloseable {
     public static final String DB_NAME = "mobile-ledger.db";
-    public static final int LATEST_REVISION = 8;
+    public static final int LATEST_REVISION = 9;
 
     private final Context mContext;
 
diff --git a/app/src/main/res/raw/sql_9.sql b/app/src/main/res/raw/sql_9.sql
new file mode 100644 (file)
index 0000000..936cec6
--- /dev/null
@@ -0,0 +1,9 @@
+alter table transactions add keep boolean default 1 not null;
+update transactions set keep = 1;
+create table transactions_new(id integer, date varchar, description varchar, data_hash varchar, keep boolean);
+insert into transactions_new(id, date, description, data_hash, keep) select cast(id as integer), date, description, data_hash, keep from transactions;
+drop table transactions;
+create table transactions(id integer primary key, date varchar, description varchar, data_hash varchar, keep boolean);
+create unique index un_transactions_data_hash on transactions(data_hash);
+insert into transactions(id, date, description, data_hash, keep) select id, date, description, data_hash, keep from transactions_new;
+drop table transactions_new;
\ No newline at end of file