Code example for SQLiteQueryBuilder

Methods: appendWhere, appendWhereEscapeString, query, setProjectionMap, setStrict, setTables, x 1

0
    } 
 
    @Override 
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
                        String sortOrder) {
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
        qb.setStrict(true);
        switch(ms_uriMatcher.match(uri)) {
            case ACTIVITY:
                qb.appendWhere("activities.id=");
                qb.appendWhereEscapeString(uri.getLastPathSegment());
            case ACTIVITIES:
                qb.setTables(
                        "activities " 
                      + "LEFT OUTER JOIN objects AS activity_object ON (activities.id=activity_object.id) " 
                      + "LEFT OUTER JOIN objects AS object          ON (activities.object=object.id) "); 
                qb.setProjectionMap(ms_activityProjection);
                return qb.query(m_database, projection, selection, selectionArgs, null, null, sortOrder);
 
            case OBJECT:
                qb.appendWhere("objects.id=");
                qb.appendWhereEscapeString(uri.getLastPathSegment());
            case OBJECTS:
                qb.setTables("objects");
                qb.setProjectionMap(ms_objectProjection);
                return qb.query(m_database, projection, selection, selectionArgs, null, null, sortOrder);
 
            case FEED:
                qb.setTables(
                        "feed_entries " 
                      + "LEFT OUTER JOIN activities AS activity     ON (feed_entries.id=activity.id) " 
                      + "LEFT OUTER JOIN objects AS activity_object ON (feed_entries.id=activity_object.id) " 
                      + "LEFT OUTER JOIN objects AS object          ON (activity.object=object.id) "); 
                qb.setProjectionMap(ms_feedProjection);
                qb.appendWhere("account=");
                qb.appendWhereEscapeString(uri.getLastPathSegment());
 
                return qb.query(m_database, projection, selection, selectionArgs, null, null, sortOrder);
 
            default: 
                throw new IllegalArgumentException("Bad URI");
        } 
    }