Search in sources :

Example 66 with ContentValues

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);
    }
}
Also used : ContentValues(android.content.ContentValues)

Example 67 with ContentValues

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();
    }
}
Also used : ContentValues(android.content.ContentValues) Calendar(java.util.Calendar) Cursor(android.database.Cursor)

Example 68 with ContentValues

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();
}
Also used : ContentValues(android.content.ContentValues) Cursor(android.database.Cursor)

Example 69 with ContentValues

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();
}
Also used : ContentValues(android.content.ContentValues) SharedPreferences(android.content.SharedPreferences)

Example 70 with ContentValues

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);
}
Also used : ContentValues(android.content.ContentValues)

Aggregations

ContentValues (android.content.ContentValues)3993 Cursor (android.database.Cursor)720 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)638 Uri (android.net.Uri)619 Test (org.junit.Test)374 SQLException (android.database.SQLException)231 ContentResolver (android.content.ContentResolver)212 ArrayList (java.util.ArrayList)192 Intent (android.content.Intent)162 File (java.io.File)156 IOException (java.io.IOException)131 RemoteException (android.os.RemoteException)96 CursorAssert.assertThatCursor (org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor)91 NonNull (android.support.annotation.NonNull)74 Date (java.util.Date)73 MediumTest (android.test.suitebuilder.annotation.MediumTest)63 HashMap (java.util.HashMap)62 JSONException (org.json.JSONException)60 SQLiteException (android.database.sqlite.SQLiteException)53 ContentProviderOperation (android.content.ContentProviderOperation)49