Search in sources :

Example 1 with AbstractCursor

use of android.database.AbstractCursor in project android_frameworks_base by ParanoidAndroid.

the class SettingsProvider method queryForUser.

private Cursor queryForUser(Uri url, String[] select, String where, String[] whereArgs, String sort, int forUser) {
    if (LOCAL_LOGV)
        Slog.v(TAG, "query(" + url + ") for user " + forUser);
    SqlArguments args = new SqlArguments(url, where, whereArgs);
    DatabaseHelper dbH;
    dbH = getOrEstablishDatabase(TABLE_GLOBAL.equals(args.table) ? UserHandle.USER_OWNER : forUser);
    SQLiteDatabase db = dbH.getReadableDatabase();
    // let the caller of the query have a chance to recover and avoid the exception
    if (TABLE_FAVORITES.equals(args.table)) {
        return null;
    } else if (TABLE_OLD_FAVORITES.equals(args.table)) {
        args.table = TABLE_FAVORITES;
        Cursor cursor = db.rawQuery("PRAGMA table_info(favorites);", null);
        if (cursor != null) {
            boolean exists = cursor.getCount() > 0;
            cursor.close();
            if (!exists)
                return null;
        } else {
            return null;
        }
    }
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(args.table);
    Cursor ret = qb.query(db, select, args.where, args.args, null, null, sort);
    // the default Cursor interface does not support per-user observation
    try {
        AbstractCursor c = (AbstractCursor) ret;
        c.setNotificationUri(getContext().getContentResolver(), url, forUser);
    } catch (ClassCastException e) {
        // details of the concrete Cursor implementation have changed and this code has
        // not been updated to match -- complain and fail hard.
        Log.wtf(TAG, "Incompatible cursor derivation!");
        throw e;
    }
    return ret;
}
Also used : AbstractCursor(android.database.AbstractCursor) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) AbstractCursor(android.database.AbstractCursor) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Aggregations

AbstractCursor (android.database.AbstractCursor)1 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)1