Search in sources :

Example 6 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project mobile-android by photo.

the class UploadsProvider method query.

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(PHOTOS_TABLE);
    switch(uriMatcher.match(uri)) {
        case UPLOAD_ID:
            qb.appendWhere(KEY_ID + "=" + uri.getPathSegments().get(1));
            break;
        default:
            break;
    }
    Cursor c = qb.query(mDb, projection, selection, selectionArgs, null, null, null);
    c.setNotificationUri(getContext().getContentResolver(), uri);
    return c;
}
Also used : Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 7 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project PocketHub by pockethub.

the class Organizations method getCursor.

@Override
public Cursor getCursor(SQLiteDatabase readableDatabase) {
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables("orgs JOIN users ON (orgs.id = users.id)");
    return builder.query(readableDatabase, new String[] { "users.id", "users.name", "users.avatarurl" }, null, null, null, null, null);
}
Also used : SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 8 with SQLiteQueryBuilder

use of android.database.sqlite.SQLiteQueryBuilder in project PocketHub by pockethub.

the class AccountDataManager method query.

/**
     * Query tables for columns
     *
     * @param helper
     * @param tables
     * @param columns
     * @param selection
     * @param selectionArgs
     * @return cursor
     */
protected Cursor query(SQLiteOpenHelper helper, String tables, String[] columns, String selection, String[] selectionArgs) {
    SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
    builder.setTables(tables);
    return builder.query(helper.getReadableDatabase(), columns, selection, selectionArgs, null, null, null);
}
Also used : SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 9 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 10 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)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