示例#1
0
 public static int deleteById(SQLiteDatabase db, Refuel rf) {
   /*
   We can just delete the parent expense row.
   The ON DELETE CASCADE clause, will make sure the
   refuel row is also deleted.
    */
   return ExpenseTable.deleteById(db, rf.getExpense());
 }
示例#2
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);
  }
示例#3
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;
    }
  }