public void insertTravel(Travel travel) { SQLiteDatabase db = getReadableDatabase(); ContentValues values = new ContentValues(); values.put(TravelsConstants.CITY, travel.getCity()); values.put(TravelsConstants.COUNTRY, travel.getCountry()); values.put(TravelsConstants.YEAR, travel.getYear()); values.put(TravelsConstants.NOTE, travel.getNote()); values.put(TravelsConstants.IMAGE_VIAJE, travel.getImage()); db.insert(TABLE_NAME, null, values); }
public ArrayList<Travel> getTravelList() { ArrayList<Travel> travels = new ArrayList<Travel>(); SQLiteDatabase db = getReadableDatabase(); Cursor c = db.query(TravelsConstants.TRAVELS_TABLE_NAME, null, null, null, null, null, null); if (c.moveToFirst()) { int idTravelIndex = c.getColumnIndex(TravelsConstants._ID); int cityIndex = c.getColumnIndex(TravelsConstants.CITY); int countryIndex = c.getColumnIndex(TravelsConstants.COUNTRY); int yearIndex = c.getColumnIndex(TravelsConstants.YEAR); int noteIndex = c.getColumnIndex(TravelsConstants.NOTE); int imageViajeIndex = c.getColumnIndex(TravelsConstants.IMAGE_VIAJE); do { Integer idTravel = c.getInt(idTravelIndex); String city = c.getString(cityIndex); String country = c.getString(countryIndex); Integer year = c.getInt(yearIndex); String note = c.getString(noteIndex); String imageViaje = c.getString(imageViajeIndex); Travel travel = new Travel(idTravel, city, country, year, note); if (imageViaje != null) { travel.setImage(imageViaje); } travels.add(travel); } while (c.moveToNext()); c.close(); } return travels; }
public void updateTravel(Travel travel) { SQLiteDatabase db = getReadableDatabase(); ContentValues values = new ContentValues(); values.put(TravelsConstants.CITY, travel.getCity()); values.put(TravelsConstants.COUNTRY, travel.getCountry()); values.put(TravelsConstants.YEAR, travel.getYear()); values.put(TravelsConstants.NOTE, travel.getNote()); values.put(TravelsConstants.IMAGE_VIAJE, travel.getImage()); db.update(TABLE_NAME, values, TravelsConstants._ID + "=" + travel.getIdTravel(), null); }