Search in sources :

Example 16 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project carat by amplab.

the class CaratSampleDB method query.

/**
     * Performs a database query.
     * 
     * @param selection
     *            The selection clause
     * @param selectionArgs
     *            Selection arguments for "?" components in the selection
     * @param columns
     *            The columns to return
     * @return A Cursor over all rows matching the query
     */
private Cursor query(String selection, String[] selectionArgs, String[] columns, String groupBy, String having, String sortOrder) {
    /*
         * The SQLiteBuilder provides a map for all possible columns requested
         * to actual columns in the database, creating a simple column alias
         * mechanism by which the ContentProvider does not need to know the real
         * column names
         */
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(SAMPLES_VIRTUAL_TABLE);
    builder.setProjectionMap(mColumnMap);
    Cursor cursor = builder.query(db, columns, selection, selectionArgs, groupBy, having, sortOrder);
    if (cursor == null) {
        return null;
    } else if (!cursor.moveToFirst()) {
        cursor.close();
        return null;
    }
    return cursor;
}
Also used : Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 17 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project Shuttle by timusus.

the class CustomArtworkContentProvider method query.

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    // Using SQLiteQueryBuilder instead of query() method
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    // Check if the caller has requested a column which does not exists
    checkColumns(projection);
    // Set the table
    queryBuilder.setTables(CustomArtworkTable.TABLE_ARTIST_ART);
    int uriType = sURIMatcher.match(uri);
    switch(uriType) {
        case CUSTOM_ARTWORK:
            break;
        default:
            throw new IllegalArgumentException("Unknown URI: " + uri);
    }
    SQLiteDatabase db = database.getWritableDatabase();
    Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
    // Make sure that potential listeners are getting notified
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 18 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project 9GAG by stormzhang.

the class DataProvider method query.

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    synchronized (DBLock) {
        SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
        String table = matchTable(uri);
        queryBuilder.setTables(table);
        SQLiteDatabase db = getDBHelper().getReadableDatabase();
        Cursor cursor = // The database to
        queryBuilder.query(// The database to
        db, // The columns to return from the queryFromDB
        projection, // The columns for the where clause
        selection, // The values for the where clause
        selectionArgs, // don't group the rows
        null, // don't filter by row groups
        null, // The sort order
        sortOrder);
        cursor.setNotificationUri(getContext().getContentResolver(), uri);
        return cursor;
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 19 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project greenDAO by greenrobot.

the class SimpleEntityContentProvider method query.

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    int uriType = sURIMatcher.match(uri);
    switch(uriType) {
        case SIMPLEENTITY_DIR:
            queryBuilder.setTables(TABLENAME);
            break;
        case SIMPLEENTITY_ID:
            queryBuilder.setTables(TABLENAME);
            queryBuilder.appendWhere(PK + "=" + uri.getLastPathSegment());
            break;
        default:
            throw new IllegalArgumentException("Unknown URI: " + uri);
    }
    Database db = getDatabase();
    Cursor cursor = queryBuilder.query(((StandardDatabase) db).getSQLiteDatabase(), projection, selection, selectionArgs, null, null, sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
Also used : Database(org.greenrobot.greendao.database.Database) StandardDatabase(org.greenrobot.greendao.database.StandardDatabase) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 20 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project cardslib by gabrielemariotti.

the class CardCursorProvider method query.

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Log.d(TAG, "query(uri=" + uri + ", proj=" + Arrays.toString(projection) + ")");
    // Open a read-only database.
    SQLiteDatabase db = myOpenHelper.getWritableDatabase();
    // Replace these with valid SQL statements if necessary.
    String groupBy = null;
    String having = null;
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    String rowID = "";
    // If this is a row query, limit the result set to the passed in row.
    switch(uriMatcher.match(uri)) {
        case CardCursor_SINGLE_ROW:
            queryBuilder.setTables(CardCursorSQLiteOpenHelper.Tables.CardCursor);
            rowID = uri.getPathSegments().get(1);
            queryBuilder.appendWhere(CardCursorContract.CardCursor.KeyColumns.KEY_ID + "=" + rowID);
            break;
        case CardCursor_ALLROWS:
            queryBuilder.setTables(CardCursorSQLiteOpenHelper.Tables.CardCursor);
            if (TextUtils.isEmpty(sortOrder)) {
                sortOrder = CardCursorContract.CardCursor.DEFAULT_SORT;
            }
            break;
        default:
            throw new IllegalArgumentException("Unsupported URI: " + uri);
    }
    Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, groupBy, having, sortOrder);
    // Make sure that potential listeners are getting notified
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Aggregations

SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)73 Cursor (android.database.Cursor)61 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)44 Account (android.accounts.Account)7 ContentValues (android.content.ContentValues)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 AbstractCursor (android.database.AbstractCursor)1 MergeCursor (android.database.MergeCursor)1 AtomicFile (android.util.AtomicFile)1 AtomicFile (com.android.internal.os.AtomicFile)1 HashSet (java.util.HashSet)1 Database (org.greenrobot.greendao.database.Database)1 StandardDatabase (org.greenrobot.greendao.database.StandardDatabase)1 Before (org.junit.Before)1