Search in sources :

Example 1 with SelectionBuilder

use of com.battlelancer.seriesguide.util.SelectionBuilder in project SeriesGuide by UweTrottmann.

the class SeriesGuideProvider method query.

@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if (LOGV) {
        Timber.v("query(uri=%s, proj=%s)", uri, Arrays.toString(projection));
    }
    // always get writable database, might have to be upgraded
    final SQLiteDatabase db = mDbHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);
    switch(match) {
        case RENEW_FTSTABLE:
            {
                SeriesGuideDatabase.rebuildFtsTable(db);
                return null;
            }
        case EPISODESEARCH:
            {
                if (selectionArgs == null) {
                    throw new IllegalArgumentException("selectionArgs must be provided for the Uri: " + uri);
                }
                return SeriesGuideDatabase.search(selection, selectionArgs, db);
            }
        case SEARCH_SUGGEST:
            {
                if (selectionArgs == null) {
                    throw new IllegalArgumentException("selectionArgs must be provided for the Uri: " + uri);
                }
                return SeriesGuideDatabase.getSuggestions(selectionArgs[0], db);
            }
        default:
            {
                // Most cases are handled with simple SelectionBuilder
                final SelectionBuilder builder = buildSelection(uri, match);
                Cursor query = null;
                try {
                    query = builder.map(BaseColumns._COUNT, // support count base column
                    "count(*)").where(selection, selectionArgs).query(db, projection, sortOrder);
                } catch (SQLiteException e) {
                    Timber.e(e, "Failed to query with uri=%s", uri);
                }
                if (query != null) {
                    //noinspection ConstantConditions
                    query.setNotificationUri(getContext().getContentResolver(), uri);
                }
                return query;
            }
    }
}
Also used : SelectionBuilder(com.battlelancer.seriesguide.util.SelectionBuilder) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SQLiteException (android.database.sqlite.SQLiteException)1 SelectionBuilder (com.battlelancer.seriesguide.util.SelectionBuilder)1