Пример #1
0
  public static long save(SQLiteDatabase db, Refuel rf) {
    ContentValues cv = new ContentValues();
    cv.put(ODOMETER, rf.getOdometer());
    cv.put(LITRE, rf.getLitre());
    cv.put(RATE, rf.getRate());
    cv.put(PUMP_NAME, rf.getPumpName());
    cv.put(FULL_TANK, rf.isFullTank());
    rf.getExpense().setDesc("Refuel at " + rf.getPumpName());
    rf.getExpense().setType("refuel");
    cv.put(EXP_ID, ExpenseTable.save(db, rf.getExpense()));

    return db.insert(TABLE_NAME, null, cv);
  }
Пример #2
0
  public static int update(SQLiteDatabase db, Refuel rf) {
    try {
      rf.getExpense().setDesc("Refuel at " + rf.getPumpName());
      rf.getExpense().setType("refuel");
      ExpenseTable.update(db, rf.getExpense());

      ContentValues cv = new ContentValues();
      cv.put(ODOMETER, rf.getOdometer());
      cv.put(LITRE, rf.getLitre());
      cv.put(RATE, rf.getRate());
      cv.put(PUMP_NAME, rf.getPumpName());
      cv.put(FULL_TANK, rf.isFullTank());
      cv.put(EXP_ID, rf.getExpense().getId());

      return db.update(TABLE_NAME, cv, ID + "=" + rf.getId(), null);
    } catch (NullPointerException e) {
      e.printStackTrace();
      return 0;
    }
  }