Esempio n. 1
0
  public static Shift load(Context aContext, int aId) {
    ShiftCalendarDbOpenHelper dbOpener = new ShiftCalendarDbOpenHelper(aContext);
    SQLiteDatabase db = dbOpener.getReadableDatabase();
    Cursor query =
        db.query(TABLE_NAME, null, "id=" + String.valueOf(aId), new String[0], null, null, null);

    try {
      if (query.moveToNext()) {
        Shift shift =
            new Shift(
                query.getInt(query.getColumnIndex(ID_COLUMN)),
                query.getString(query.getColumnIndex(NAME_COLUMN)),
                query.getInt(query.getColumnIndex(COLOUR_COLUMN)),
                query.getString(query.getColumnIndex(TIME_FROM_COLUMN)),
                query.getString(query.getColumnIndex(TIME_TO_COLUMN)),
                query.getInt(query.getColumnIndex(SORT_ORDER_COLUMN)));
        db.close();
        dbOpener.close();
        return shift;
      } else {
        db.close();
        dbOpener.close();
        return null;
      }
    } finally {
      query.close();
    }
  }
Esempio n. 2
0
  public static List<Shift> loadAll(Context aContext) {
    ShiftCalendarDbOpenHelper dbOpener = new ShiftCalendarDbOpenHelper(aContext);
    SQLiteDatabase db = dbOpener.getReadableDatabase();
    Cursor query = db.query(Shift.TABLE_NAME, null, "", new String[0], "", "", SORT_ORDER_COLUMN);
    ArrayList<Shift> shifts = new ArrayList<Shift>();

    try {
      while (query.moveToNext()) {
        shifts.add(
            new Shift(
                query.getInt(query.getColumnIndex(ID_COLUMN)),
                query.getString(query.getColumnIndex(NAME_COLUMN)),
                query.getInt(query.getColumnIndex(COLOUR_COLUMN)),
                query.getString(query.getColumnIndex(TIME_FROM_COLUMN)),
                query.getString(query.getColumnIndex(TIME_TO_COLUMN)),
                query.getInt(query.getColumnIndex(SORT_ORDER_COLUMN))));
      }
    } finally {
      query.close();
    }

    return shifts;
  }