Code example for SQLiteQueryBuilder

Methods: appendWhere, query, setProjectionMap, setTables

0
    } 
 
    @Override 
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
            String sortOrder) {
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
 
        switch (sUriMatcher.match(uri)) {
        case WORDS:
            qb.setTables(USERDICT_TABLE_NAME);
            qb.setProjectionMap(sDictProjectionMap);
            break; 
 
        case WORD_ID:
            qb.setTables(USERDICT_TABLE_NAME);
            qb.setProjectionMap(sDictProjectionMap);
            qb.appendWhere("_id" + "=" + uri.getPathSegments().get(1));
            break; 
 
        default: 
            throw new IllegalArgumentException("Unknown URI " + uri);
        } 
 
        // If no sort order is specified use the default 
        String orderBy;
        if (TextUtils.isEmpty(sortOrder)) {
            orderBy = Words.DEFAULT_SORT_ORDER;
        } else { 
            orderBy = sortOrder;
        } 
 
        // Get the database and run the query 
        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
        Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
 
        // Tell the cursor what uri to watch, so it knows when its source data changes 
        c.setNotificationUri(getContext().getContentResolver(), uri);
        return c;
    }