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;
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);
}
}
};
}
- 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, " +
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;
--- /dev/null
+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