Code example for SQLiteQueryBuilder

Methods: appendWhere, query, setProjectionMap, setTables

0
		return true; 
	} 
	 
	@Override 
	public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
		SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
 
		switch (sUriMatcher.match(uri)) {
		case HOSTS:
			qb.setTables(HOSTS_TABLE_NAME);
			qb.setProjectionMap(sHostsProjectionMap);
			break; 
 
		case HOST_ID:
			qb.setTables(HOSTS_TABLE_NAME);
			qb.setProjectionMap(sHostsProjectionMap);
			qb.appendWhere(Hosts._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 = Hosts.DEFAULT_SORT_ORDER;
		} else { 
			orderBy = sortOrder;
		} 
 
		// Get the database and run the query 
		SQLiteDatabase db = mOpenHelper.getReadableDatabase();
		Log.d(TAG, "SQLite database version: " + db.getVersion());
		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;