List of usage examples for android.database.sqlite SQLiteQueryBuilder query
public Cursor query(SQLiteDatabase db, String[] projectionIn, String selection, String[] selectionArgs,
String groupBy, String having, String sortOrder, String limit)
From source file:com.hyunnyapp.easycursor.sqlcursor.querymodels.SelectQueryModel.java
@Override protected Cursor executeQueryInternal(final SQLiteDatabase db) { final SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); builder.setTables(getTables());/* w w w . j ava2s .c om*/ builder.setDistinct(isDistinct()); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { builder.setStrict(isStrict()); } return builder.query(db, getProjectionIn(), getSelection(), getSelectionArgs(), getGroupBy(), getHaving(), getSortOrder(), getLimit()); }
From source file:com.nadmm.airports.ActivityBase.java
public Cursor getAirportDetails(String siteNumber) { SQLiteDatabase db = getDatabase(DatabaseManager.DB_FADDS); SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); builder.setTables(Airports.TABLE_NAME + " a LEFT OUTER JOIN " + States.TABLE_NAME + " s" + " ON a." + Airports.ASSOC_STATE + "=s." + States.STATE_CODE); Cursor c = builder.query(db, new String[] { "*" }, Airports.SITE_NUMBER + "=?", new String[] { siteNumber }, null, null, null, null);/*from www. j a va 2 s . co m*/ if (!c.moveToFirst()) { return null; } return c; }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
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; }/*from w ww. ja va 2 s . co m*/ 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; }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Cursor queryArtwork(@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; }/*from w w w.ja va 2s . co m*/ final SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(MuzeiContract.Artwork.TABLE_NAME + " INNER JOIN " + MuzeiContract.Sources.TABLE_NAME + " ON " + MuzeiContract.Artwork.TABLE_NAME + "." + MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME + "=" + MuzeiContract.Sources.TABLE_NAME + "." + MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME); qb.setProjectionMap(allArtworkColumnProjectionMap); final SQLiteDatabase db = databaseHelper.getReadableDatabase(); if (MuzeiProvider.uriMatcher.match(uri) == ARTWORK_ID) { // If the incoming URI is for a single source identified by its ID, appends "_ID = <artworkId>" // to the where clause, so that it selects that single piece of artwork qb.appendWhere( MuzeiContract.Artwork.TABLE_NAME + "." + BaseColumns._ID + "=" + uri.getLastPathSegment()); } String orderBy; if (TextUtils.isEmpty(sortOrder)) orderBy = MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED + " DESC, " + MuzeiContract.Artwork.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; }
From source file:org.thomnichols.android.gmarks.GmarksProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); // Log.d(TAG, "Managed query: " + uri); String groupBy = null;//from w ww .ja va 2 s . c om String orderBy = null; String limit = null; switch (sUriMatcher.match(uri)) { case BOOKMARKS_URI: qb.setTables(BOOKMARKS_TABLE_NAME); qb.setProjectionMap(bookmarksProjectionMap); String labelID = uri.getQueryParameter("label_id"); if (labelID != null) { qb.setTables("bookmarks join bookmark_labels on bookmarks._id = bookmark_labels.bookmark_id"); qb.appendWhere("bookmark_labels.label_id=?"); selectionArgs = (String[]) ArrayUtils.addAll(selectionArgs, new String[] { labelID }); } break; case BOOKMARK_SEARCH_URI: case BOOKMARK_SEARCH_SUGGEST_URI: String query = null; if (sUriMatcher.match(uri) == BOOKMARK_SEARCH_SUGGEST_URI) { qb.setProjectionMap(searchSuggestProjectionMap); // path looks like "search_suggest_query/[query]?limit=50 query = uri.getLastPathSegment(); limit = uri.getQueryParameter("limit"); if (sortOrder == null) sortOrder = Bookmark.Columns.SORT_MODIFIED; } else query = uri.getQueryParameter("q"); if (query != null) { qb.setTables("bookmarks join bookmarks_FTS on bookmarks._id = bookmarks_FTS.docid"); qb.appendWhere("bookmarks_FTS MATCH ?"); if (selectionArgs == null) selectionArgs = new String[] { query }; else selectionArgs = (String[]) ArrayUtils.addAll(selectionArgs, new String[] { query }); } else if (selectionArgs == null || selectionArgs.length < 1) throw new IllegalArgumentException("No search criteria given for query!"); break; case BOOKMARK_ID_URI: qb.setTables(BOOKMARKS_TABLE_NAME); qb.setProjectionMap(bookmarksProjectionMap); qb.appendWhere(Bookmark.Columns._ID + "=" + uri.getPathSegments().get(1)); break; case LABELS_URI: qb.setTables("labels join bookmark_labels on labels._id = bookmark_labels.label_id"); groupBy = "label"; if (sortOrder == null) sortOrder = Label.Columns.DEFAULT_SORT_ORDER; qb.setProjectionMap(labelsProjectionMap); break; case LIVE_FOLDER_BOOKMARKS_URI: qb.setTables(BOOKMARKS_TABLE_NAME); qb.setProjectionMap(sLiveFolderProjectionMap); String labelId = uri.getQueryParameter("label_id"); if (labelId != null) { qb.setTables("bookmarks join bookmark_labels on bookmarks._id = bookmark_labels.bookmark_id"); qb.appendWhere("bookmark_labels.label_id=?"); selectionArgs = (String[]) ArrayUtils.addAll(selectionArgs, new String[] { labelId }); } sortOrder = "modified DESC"; // for some reason this gets set to 'name ASC' break; case BOOKMARK_LISTS_URI: qb.setTables(BookmarkList.TABLE_NAME); qb.setProjectionMap(listsProjectionMap); if (sortOrder == null) sortOrder = BookmarkList.Columns.DEFAULT_SORT_ORDER; String type = uri.getQueryParameter(BookmarkList.PARAM_CATEGORY); if (BookmarkList.LISTS_PRIVATE.equals(type)) qb.appendWhere("owned=1"); else if (BookmarkList.LISTS_SHARED.equals(type)) qb.appendWhere("shared=1"); else if (BookmarkList.LISTS_PUBLIC.equals(type)) qb.appendWhere("publshed=1"); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } // If no sort order is specified use the default if (TextUtils.isEmpty(sortOrder)) { orderBy = Bookmark.Columns.DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } // Get the database and run the query SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, groupBy, null, orderBy, limit); // Tell the cursor what uri to watch, so it knows when its source data changes c.setNotificationUri(getContext().getContentResolver(), uri); return c; }