use of android.content.ContentValues in project k-9 by k9mail.
the class Storage method writeValue.
private void writeValue(SQLiteDatabase mDb, String key, String value) {
ContentValues cv = new ContentValues();
cv.put("primkey", key);
cv.put("value", value);
long result = mDb.insert("preferences_storage", "primkey", cv);
if (result == -1) {
Timber.e("Error writing key '%s', value = '%s'", key, value);
}
}
use of android.content.ContentValues in project SeriesGuide by UweTrottmann.
the class SeriesGuideDatabase method upgradeToThirtyFour.
/**
* See {@link #DBVER_34_TRAKT_V2}.
*/
private static void upgradeToThirtyFour(SQLiteDatabase db) {
// add new columns
db.beginTransaction();
try {
// shows
if (isTableColumnMissing(db, Tables.SHOWS, Shows.RELEASE_TIMEZONE)) {
db.execSQL("ALTER TABLE " + Tables.SHOWS + " ADD COLUMN " + Shows.RELEASE_TIMEZONE + " TEXT;");
}
if (isTableColumnMissing(db, Tables.SHOWS, Shows.RATING_VOTES)) {
db.execSQL("ALTER TABLE " + Tables.SHOWS + " ADD COLUMN " + Shows.RATING_VOTES + " INTEGER;");
}
if (isTableColumnMissing(db, Tables.SHOWS, Shows.RATING_USER)) {
db.execSQL("ALTER TABLE " + Tables.SHOWS + " ADD COLUMN " + Shows.RATING_USER + " INTEGER;");
}
// episodes
if (isTableColumnMissing(db, Tables.EPISODES, Episodes.RATING_VOTES)) {
db.execSQL("ALTER TABLE " + Tables.EPISODES + " ADD COLUMN " + Episodes.RATING_VOTES + " INTEGER;");
}
if (isTableColumnMissing(db, Tables.EPISODES, Episodes.RATING_USER)) {
db.execSQL("ALTER TABLE " + Tables.EPISODES + " ADD COLUMN " + Episodes.RATING_USER + " INTEGER;");
}
// movies
if (isTableColumnMissing(db, Tables.MOVIES, Movies.RATING_USER)) {
db.execSQL("ALTER TABLE " + Tables.MOVIES + " ADD COLUMN " + Movies.RATING_USER + " INTEGER;");
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
// migrate existing data to new formats
Cursor query = db.query(Tables.SHOWS, new String[] { Shows._ID, Shows.RELEASE_TIME, Shows.RELEASE_WEEKDAY }, null, null, null, null, null);
// create calendar, set to custom time zone
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT-08:00"));
ContentValues values = new ContentValues();
db.beginTransaction();
try {
while (query.moveToNext()) {
// time changed from ms to encoded local time
long timeOld = query.getLong(1);
int timeNew;
if (timeOld != -1) {
calendar.setTimeInMillis(timeOld);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
timeNew = hour * 100 + minute;
} else {
timeNew = -1;
}
values.put(Shows.RELEASE_TIME, timeNew);
// week day changed from string to int
String weekDayOld = query.getString(2);
int weekDayNew = TimeTools.parseShowReleaseWeekDay(weekDayOld);
values.put(Shows.RELEASE_WEEKDAY, weekDayNew);
db.update(Tables.SHOWS, values, Shows._ID + "=" + query.getInt(0), null);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
query.close();
}
}
use of android.content.ContentValues in project SeriesGuide by UweTrottmann.
the class SeriesGuideDatabase method upgradeToEighteen.
/**
* In version 18 the series text column nextairdatetext was added.
*/
private static void upgradeToEighteen(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + Tables.SHOWS + " ADD COLUMN " + ShowsColumns.NEXTAIRDATETEXT + " TEXT DEFAULT '';");
// convert status text to 0/1 integer
final Cursor shows = db.query(Tables.SHOWS, new String[] { Shows._ID, Shows.STATUS }, null, null, null, null, null);
final ContentValues values = new ContentValues();
String status;
db.beginTransaction();
try {
while (shows.moveToNext()) {
status = shows.getString(1);
if (status.length() == 10) {
status = "1";
} else if (status.length() == 5) {
status = "0";
} else {
status = "";
}
values.put(Shows.STATUS, status);
db.update(Tables.SHOWS, values, Shows._ID + "=?", new String[] { shows.getString(0) });
values.clear();
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
shows.close();
}
use of android.content.ContentValues in project SeriesGuide by UweTrottmann.
the class HexagonSettings method resetSyncState.
/**
* Reset the sync state of shows, episodes, movies and lists so a data merge is triggered when
* next syncing with Hexagon.
*
* @return If the sync settings reset was committed successfully.
*/
public static boolean resetSyncState(Context context) {
// set all shows as not merged with Hexagon
ContentValues values = new ContentValues();
values.put(SeriesGuideContract.Shows.HEXAGON_MERGE_COMPLETE, false);
context.getContentResolver().update(SeriesGuideContract.Shows.CONTENT_URI, values, null, null);
// reset sync properties
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.putBoolean(HexagonSettings.KEY_MERGED_SHOWS, false);
editor.putBoolean(HexagonSettings.KEY_MERGED_MOVIES, false);
editor.putBoolean(HexagonSettings.KEY_MERGED_LISTS, false);
editor.remove(HexagonSettings.KEY_LAST_SYNC_EPISODES);
editor.remove(HexagonSettings.KEY_LAST_SYNC_SHOWS);
editor.remove(HexagonSettings.KEY_LAST_SYNC_MOVIES);
editor.remove(HexagonSettings.KEY_LAST_SYNC_LISTS);
return editor.commit();
}
use of android.content.ContentValues in project SeriesGuide by UweTrottmann.
the class JsonImportTask method addMovieToDatabase.
private void addMovieToDatabase(Movie movie) {
ContentValues values = new ContentValues();
values.put(Movies.TMDB_ID, movie.tmdbId);
values.put(Movies.IMDB_ID, movie.imdbId);
values.put(Movies.TITLE, movie.title);
values.put(Movies.TITLE_NOARTICLE, DBUtils.trimLeadingArticle(movie.title));
values.put(Movies.RELEASED_UTC_MS, movie.releasedUtcMs);
values.put(Movies.RUNTIME_MIN, movie.runtimeMin);
values.put(Movies.POSTER, movie.poster);
values.put(Movies.IN_COLLECTION, movie.inCollection);
values.put(Movies.IN_WATCHLIST, movie.inWatchlist);
values.put(Movies.WATCHED, movie.watched);
// full dump values
values.put(Movies.OVERVIEW, movie.overview);
context.getContentResolver().insert(Movies.CONTENT_URI, values);
}
Aggregations