Пример #1
0
  public static ArrayList<Refuel> getByArg(SQLiteDatabase db, String whereClause, String sortBy) {
    Cursor c =
        db.query(
            RefuelTable.TABLE_NAME + " , " + ExpenseTable.TABLE_NAME,
            Utils.concat(RefuelTable.PROJECTION, ExpenseTable.PROJECTION),
            RefuelTable.EXP_ID
                + " = "
                + ExpenseTable.ID
                + ((whereClause != null) ? " AND " + whereClause : ""),
            null,
            null,
            null,
            (sortBy != null) ? sortBy : ID + " DESC");

    ArrayList<Refuel> refuels = new ArrayList<>();
    c.moveToFirst();
    while (!c.isAfterLast()) {
      refuels.add(
          new Refuel(
              c.getInt(c.getColumnIndexOrThrow(ID)),
              c.getDouble(c.getColumnIndexOrThrow(ODOMETER)),
              c.getDouble(c.getColumnIndexOrThrow(RATE)),
              c.getDouble(c.getColumnIndexOrThrow(LITRE)),
              c.getString(c.getColumnIndexOrThrow(PUMP_NAME)),
              (c.getInt(c.getColumnIndexOrThrow(FULL_TANK)) != 0),
              new Expense(
                  c.getInt(c.getColumnIndexOrThrow(ExpenseTable.ID)),
                  c.getDouble(c.getColumnIndexOrThrow(ExpenseTable.AMOUNT)),
                  c.getLong(c.getColumnIndexOrThrow(ExpenseTable.TIMESTAMP)),
                  c.getString(c.getColumnIndexOrThrow(ExpenseTable.DESC)),
                  c.getString(c.getColumnIndexOrThrow(ExpenseTable.TYPE)))));
    }
    c.close();
    return refuels;
  }
Пример #2
0
  public static Refuel getById(SQLiteDatabase db, long id) {
    Cursor c =
        db.query(
            RefuelTable.TABLE_NAME + " , " + ExpenseTable.TABLE_NAME,
            Utils.concat(RefuelTable.PROJECTION, ExpenseTable.PROJECTION),
            RefuelTable.EXP_ID + " = " + ExpenseTable.ID + " AND " + RefuelTable.ID + " = " + id,
            null,
            null,
            null,
            null);

    c.moveToFirst();
    Refuel ref =
        new Refuel(
            c.getInt(c.getColumnIndexOrThrow(ID)),
            c.getDouble(c.getColumnIndexOrThrow(ODOMETER)),
            c.getDouble(c.getColumnIndexOrThrow(RATE)),
            c.getDouble(c.getColumnIndexOrThrow(LITRE)),
            c.getString(c.getColumnIndexOrThrow(PUMP_NAME)),
            (c.getInt(c.getColumnIndexOrThrow(FULL_TANK)) != 0),
            new Expense(
                c.getInt(c.getColumnIndexOrThrow(ExpenseTable.ID)),
                c.getDouble(c.getColumnIndexOrThrow(ExpenseTable.AMOUNT)),
                c.getLong(c.getColumnIndexOrThrow(ExpenseTable.TIMESTAMP)),
                c.getString(c.getColumnIndexOrThrow(ExpenseTable.DESC)),
                c.getString(c.getColumnIndexOrThrow(ExpenseTable.TYPE))));
    c.close();
    return ref;
  }