- try (SQLiteDatabase db = MLDB.getReadableDatabase(context)) {
- try (Cursor cursor = db.rawQuery(sql, null)) {
+ boolean hasFilter =
+ act.findViewById(R.id.transaction_list_account_name_filter).getVisibility() ==
+ View.VISIBLE;
+
+ String sql;
+ String[] params;
+
+ sql = "SELECT id FROM transactions ORDER BY date desc, id desc";
+ params = null;
+
+ if (hasFilter) {
+ String filterAccName = String.valueOf(
+ ((AutoCompleteTextView) act.findViewById(R.id.transaction_filter_account_name))
+ .getText());
+
+ if (!filterAccName.isEmpty()) {
+ sql = "SELECT distinct tr.id from transactions tr JOIN transaction_accounts ta " +
+ "ON ta.transaction_id=tr.id WHERE ta.account_name LIKE ?||'%' AND ta" +
+ ".amount <> 0 ORDER BY tr.date desc, tr.id desc";
+ params = new String[]{filterAccName};
+ }
+ }
+
+ Log.d("tmp", sql);
+ try (SQLiteDatabase db = MLDB.getReadableDatabase(act)) {
+ try (Cursor cursor = db.rawQuery(sql, params)) {