Search in sources :

Example 31 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project ABPlayer by winkstu.

the class PreferenceProvider method query.

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    switch(URI_MATCHER.match(uri)) {
        case PREFERENCES:
            qb.setTables(TB_NAME);
            break;
        case PREFERENCE_KEY:
            qb.setTables(TB_NAME);
            qb.appendWhere(COL_KEY + "= '" + uri.getPathSegments().get(1) + "'");
            break;
        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
    }
    SQLiteDatabase db = mDbHelper.getReadableDatabase();
    return qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 32 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project Material-Movies by saulmm.

the class DbProvider method query.

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    switch(uriMatcher.match(uri)) {
        case MOVIES_ID:
            queryBuilder.appendWhere(DbConstants.Movies.ID + "=" + uri.getLastPathSegment());
        case MOVIES:
            queryBuilder.setTables(DbConstants.Movies.TABLE_NAME);
            if (TextUtils.isEmpty(sortOrder)) {
                sortOrder = DbConstants.Movies.DEFAULT_SORT_ORDER;
            }
            break;
        default:
            throw new IllegalArgumentException("Unknown URI: " + uri);
    }
    Cursor c = queryBuilder.query(database, projection, selection, selectionArgs, null, null, sortOrder);
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}
Also used : Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 33 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project muzei by romannurik.

the class GalleryProvider method queryChosenPhotos.

private Cursor queryChosenPhotos(@NonNull final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) {
    ContentResolver contentResolver = getContext() != null ? getContext().getContentResolver() : null;
    if (contentResolver == null) {
        return null;
    }
    final SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(GalleryContract.ChosenPhotos.TABLE_NAME);
    qb.setProjectionMap(allChosenPhotosColumnProjectionMap);
    final SQLiteDatabase db = databaseHelper.getReadableDatabase();
    if (GalleryProvider.uriMatcher.match(uri) == CHOSEN_PHOTOS_ID) {
        // If the incoming URI is for a single chosen photo identified by its ID, appends "_ID = <chosenPhotoId>"
        // to the where clause, so that it selects that single chosen photo
        qb.appendWhere(BaseColumns._ID + "=" + uri.getLastPathSegment());
    }
    String orderBy;
    if (TextUtils.isEmpty(sortOrder))
        orderBy = GalleryContract.ChosenPhotos.DEFAULT_SORT_ORDER;
    else
        orderBy = sortOrder;
    final Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy, null);
    c.setNotificationUri(contentResolver, uri);
    return c;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder) ContentResolver(android.content.ContentResolver)

Example 34 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project muzei by romannurik.

the class GalleryProvider method queryMetadataCache.

private Cursor queryMetadataCache(@NonNull final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) {
    ContentResolver contentResolver = getContext() != null ? getContext().getContentResolver() : null;
    if (contentResolver == null) {
        return null;
    }
    final SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(GalleryContract.MetadataCache.TABLE_NAME);
    qb.setProjectionMap(allMetadataCacheColumnProjectionMap);
    final SQLiteDatabase db = databaseHelper.getReadableDatabase();
    String orderBy;
    if (TextUtils.isEmpty(sortOrder))
        orderBy = GalleryContract.MetadataCache.DEFAULT_SORT_ORDER;
    else
        orderBy = sortOrder;
    final Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy, null);
    c.setNotificationUri(contentResolver, uri);
    return c;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder) ContentResolver(android.content.ContentResolver)

Example 35 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project muzei by romannurik.

the class MuzeiProvider method querySource.

private Cursor querySource(@NonNull final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) {
    ContentResolver contentResolver = getContext() != null ? getContext().getContentResolver() : null;
    if (contentResolver == null) {
        return null;
    }
    final SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(MuzeiContract.Sources.TABLE_NAME);
    qb.setProjectionMap(allSourcesColumnProjectionMap);
    final SQLiteDatabase db = databaseHelper.getReadableDatabase();
    if (MuzeiProvider.uriMatcher.match(uri) == SOURCE_ID) {
        // If the incoming URI is for a single source identified by its ID, appends "_ID = <sourceId>"
        // to the where clause, so that it selects that single source
        qb.appendWhere(BaseColumns._ID + "=" + uri.getLastPathSegment());
    }
    String orderBy;
    if (TextUtils.isEmpty(sortOrder))
        orderBy = MuzeiContract.Sources.DEFAULT_SORT_ORDER;
    else
        orderBy = sortOrder;
    final Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy, null);
    c.setNotificationUri(contentResolver, uri);
    return c;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder) ContentResolver(android.content.ContentResolver)

Aggregations

SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)106 Cursor (android.database.Cursor)93 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)44 ContentValues (android.content.ContentValues)8 Account (android.accounts.Account)7 SQLiteException (android.database.sqlite.SQLiteException)7 File (java.io.File)7 HashMap (java.util.HashMap)7 SyncStatusInfo (android.content.SyncStatusInfo)6 MatrixCursor (android.database.MatrixCursor)5 RowBuilder (android.database.MatrixCursor.RowBuilder)5 ContentResolver (android.content.ContentResolver)4 Test (org.junit.Test)2 Matchers.anyLong (org.mockito.Matchers.anyLong)2 Returns (org.mockito.internal.stubbing.answers.Returns)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 AbstractCursor (android.database.AbstractCursor)1 MergeCursor (android.database.MergeCursor)1 AtomicFile (android.util.AtomicFile)1 AtomicFile (com.android.internal.os.AtomicFile)1