public void excludeEpisodesBd(long serieId) { String where = "id_serie = " + serieId; try { super.open(); db.delete(TABLE_NAME, where, null); } catch (SQLException e) { Log.e("SeriesManager", "Error trying to exclude Episode: " + e.toString()); } finally { super.close(); } }
public void addEpisode(Episode episode, Serie serie) { try { super.open(); ContentValues values = new ContentValues(); values.put("id_serie", serie.getId()); values.put("name", episode.getName()); values.put("season", episode.getSeason()); values.put("number", episode.getNumber()); db.insert(TABLE_NAME, null, values); } catch (SQLException e) { Log.e("SeriesManager", "Error trying to include Episode: " + e.toString()); } finally { super.close(); } }
public Episode searchEpisode(Serie serie) { Cursor c = getCursor(); Episode episode = new Episode(); if (c.moveToFirst()) { int idxName = c.getColumnIndex(Episodes.NAME); int idxId = c.getColumnIndex(Episodes.PK_ID); int idxSeason = c.getColumnIndex(Episodes.SEASON); int idxEpisode = c.getColumnIndex(Episodes.NUMBER); int idxIdSerie = c.getColumnIndex(Episodes.ID_SERIE); do { if (serie.getId() == c.getLong(idxIdSerie) && serie.getSeason().intValue() == c.getInt(idxSeason) && serie.getEpisode().intValue() == c.getInt(idxEpisode)) { episode.setName(c.getString(idxName)); episode.setId(c.getLong(idxId)); episode.setSeason(c.getInt(idxSeason)); episode.setNumber(c.getInt(idxEpisode)); break; } } while (c.moveToNext()); } c.close(); super.close(); return episode; }
public ArrayList<Episode> listBySerieAndSeason(Serie serie) { Cursor c = getCursor(); ArrayList<Episode> episodes = new ArrayList<Episode>(); if (c.moveToFirst()) { int idxName = c.getColumnIndex(Episodes.NAME); int idxId = c.getColumnIndex(Episodes.PK_ID); int idxSeason = c.getColumnIndex(Episodes.SEASON); int idxEpisode = c.getColumnIndex(Episodes.NUMBER); int idxIdSerie = c.getColumnIndex(Episodes.ID_SERIE); do { if (serie.getId() == c.getLong(idxIdSerie) && serie.getSeason().intValue() == c.getInt(idxSeason)) { Episode episode = new Episode(); episode.setName(c.getString(idxName)); episode.setId(c.getLong(idxId)); episode.setSeason(c.getInt(idxSeason)); episode.setNumber(c.getInt(idxEpisode)); episodes.add(episode); } } while (c.moveToNext()); } c.close(); super.close(); return episodes; }
public Cursor getCursor() { try { super.open(); return super.db.query( TABLE_NAME, Episode.columns, null, null, null, null, Episodes.DEFAULT_SORT_ORDER); } catch (SQLException e) { return null; } }
public void updateEpisode(Episode episode, Serie serie) { try { String where = "pk_id = " + episode.getId(); super.open(); ContentValues values = new ContentValues(); values.put("id_serie", serie.getId()); values.put("name", episode.getName()); values.put("season", episode.getSeason()); values.put("number", episode.getNumber()); db.update(TABLE_NAME, values, where, null); } catch (SQLException e) { Log.e("SeriesManager", "Error trying to update Episode: " + e.toString()); } finally { super.close(); } }