- public boolean existsInDb(SQLiteDatabase db) {
- fillDataHash();
- try (Cursor c = db.rawQuery("SELECT 1 from transactions where data_hash = ?",
- new String[]{dataHash}))
- {
- boolean result = c.moveToFirst();
-// debug("db", String.format("Transaction %d (%s) %s", id, dataHash,
-// result ? "already present" : "not present"));
- return result;
- }
- }
- public void loadData(SQLiteDatabase db) {
- if (dataLoaded)
- return;
-
- try (Cursor cTr = db.rawQuery(
- "SELECT year, month, day, description, comment from transactions WHERE profile=? " +
- "AND id=?", new String[]{profile, String.valueOf(id)}))
- {
- if (cTr.moveToFirst()) {
- date = new SimpleDate(cTr.getInt(0), cTr.getInt(1), cTr.getInt(2));
- description = cTr.getString(3);
- comment = cTr.getString(4);
-
- accounts.clear();
-
- try (Cursor cAcc = db.rawQuery(
- "SELECT account_name, amount, currency, comment FROM " +
- "transaction_accounts WHERE profile=? AND transaction_id = ?",
- new String[]{profile, String.valueOf(id)}))
- {
- while (cAcc.moveToNext()) {
-// debug("transactions",
-// String.format("Loaded %d: %s %1.2f %s", id, cAcc.getString(0),
-// cAcc.getFloat(1), cAcc.getString(2)));
- addAccount(new LedgerTransactionAccount(cAcc.getString(0), cAcc.getFloat(1),
- cAcc.getString(2), cAcc.getString(3)));
- }
-
- finishLoading();
- }
- }
- }
-
- }