예제 #1
0
  /**
   * Find all shows in the database
   *
   * @return a list of all found shows
   */
  public List<Show> getAllShows() {
    List<Show> shows = new ArrayList<Show>();
    SQLiteDatabase db = getWritableDatabase();
    String[] columns = {COLUMN_TVDB_ID, COLUMN_TITLE};

    Cursor cursor = db.query(TABLE_NAME, columns, null, null, null, null, null);

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
      Show show = new Show();
      show.setTvdb_id(cursor.getInt(0));
      show.setTitle(cursor.getString(1));
      shows.add(show);
      cursor.moveToNext();
    }
    cursor.close();
    close();
    return shows;
  }
예제 #2
0
  public Long createShow(Show show) {
    Long id;
    ContentValues values = new ContentValues();
    values.put(COLUMN_TVDB_ID, show.getTvdb_id());
    values.put(COLUMN_TITLE, show.getTitle());
    SQLiteDatabase db = getWritableDatabase();

    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    queryBuilder.setTables(TABLE_NAME);
    Cursor cursor =
        queryBuilder.query(
            db, null, "tvdb_id = ?", new String[] {"" + show.getTvdb_id()}, null, null, null);

    if (!(cursor.moveToFirst()) || cursor.getCount() == 0) {
      id = db.insert(TABLE_NAME, null, values);
    } else {
      id = cursor.getLong(0);
    }
    cursor.close();
    close();
    return id;
  }