Search in sources :

Example 11 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 12 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project robolectric by robolectric.

the class SQLiteQueryBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    database = SQLiteDatabase.create(null);
    database.execSQL("create table " + TABLE_NAME + " (" + COL_VALUE + " TEXT, " + COL_GROUP + " INTEGER" + ")");
    ContentValues values = new ContentValues();
    values.put(COL_VALUE, "record1");
    values.put(COL_GROUP, 1);
    firstRecordId = database.insert(TABLE_NAME, null, values);
    assertThat(firstRecordId).isGreaterThan(0);
    values.clear();
    values.put(COL_VALUE, "record2");
    values.put(COL_GROUP, 1);
    long secondRecordId = database.insert(TABLE_NAME, null, values);
    assertThat(secondRecordId).isGreaterThan(0).isNotEqualTo(firstRecordId);
    values.clear();
    values.put(COL_VALUE, "won't be selected");
    values.put(COL_GROUP, 2);
    database.insert(TABLE_NAME, null, values);
    builder = new SQLiteQueryBuilder();
    builder.setTables(TABLE_NAME);
    builder.appendWhere(COL_VALUE + " <> ");
    builder.appendWhereEscapeString("won't be selected");
}
Also used : ContentValues(android.content.ContentValues) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder) Before(org.junit.Before)

Example 13 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project cw-omnibus by commonsguy.

the class Provider method query.

@Override
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sort) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(TABLE);
    String orderBy;
    if (TextUtils.isEmpty(sort)) {
        orderBy = Constants.DEFAULT_SORT_ORDER;
    } else {
        orderBy = sort;
    }
    Cursor c = qb.query(db.getReadableDatabase(), projection, selection, selectionArgs, null, null, orderBy);
    c.setNotificationUri(getContext().getContentResolver(), url);
    return (c);
}
Also used : Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 14 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project cw-advandroid by commonsguy.

the class Provider method query.

@Override
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sort) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(TABLE);
    String orderBy;
    if (TextUtils.isEmpty(sort)) {
        orderBy = Constants.DEFAULT_SORT_ORDER;
    } else {
        orderBy = sort;
    }
    Cursor c = qb.query(db.getReadableDatabase(), projection, selection, selectionArgs, null, null, orderBy);
    c.setNotificationUri(getContext().getContentResolver(), url);
    return (c);
}
Also used : Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 15 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project cw-advandroid by commonsguy.

the class Provider method query.

@Override
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sort) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(TABLE);
    String orderBy;
    if (TextUtils.isEmpty(sort)) {
        orderBy = Constants.DEFAULT_SORT_ORDER;
    } else {
        orderBy = sort;
    }
    Cursor c = qb.query(db.getReadableDatabase(), projection, selection, selectionArgs, null, null, orderBy);
    c.setNotificationUri(getContext().getContentResolver(), url);
    return (c);
}
Also used : Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

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