List of usage examples for android.database.sqlite SQLiteQueryBuilder appendWhere
public void appendWhere(@NonNull CharSequence inWhere)
From source file:com.hivewallet.androidclient.wallet.AddressBookProvider.java
private static void appendAddresses(@Nonnull final SQLiteQueryBuilder qb, @Nonnull final String[] addresses) { for (final String address : addresses) { qb.appendWhereEscapeString(address.trim()); if (!address.equals(addresses[addresses.length - 1])) qb.appendWhere(","); }//w w w .ja va2s . co m }
From source file:com.manning.androidhacks.hack043.provider.MySQLContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (sUriMatcher.match(uri)) { case ITEM:/*from ww w . j av a 2 s . c o m*/ qb.setTables(TABLE_NAME); qb.setProjectionMap(projectionMap); break; case ITEM_ID: qb.setTables(TABLE_NAME); qb.setProjectionMap(projectionMap); qb.appendWhere(COLUMN_ID + "=" + uri.getPathSegments().get(1)); break; default: throw new RuntimeException("Unknown URI"); } SQLiteDatabase db = getDatabaseHelper().getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
From source file:com.manning.androidhacks.hack043.provider.BatchNumbersContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (sUriMatcher.match(uri)) { case ITEM:/*from ww w.j av a 2 s. c o m*/ qb.setTables(TABLE_NAME); qb.setProjectionMap(projectionMap); break; case ITEM_ID: qb.setTables(TABLE_NAME); qb.setProjectionMap(projectionMap); qb.appendWhere(COLUMN_ID + "=" + uri.getPathSegments().get(1)); break; default: throw new RuntimeException("Unknown URI"); } SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
From source file:com.manning.androidhacks.hack023.provider.TodoContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (sUriMatcher.match(uri)) { case TODO://from w ww .ja v a 2s . c o m qb.setTables(TODO_TABLE_NAME); qb.setProjectionMap(projectionMap); break; case TODO_ID: qb.setTables(TODO_TABLE_NAME); qb.setProjectionMap(projectionMap); qb.appendWhere(COLUMN_ID + "=" + uri.getPathSegments().get(1)); break; default: throw new RuntimeException("Unknown URI"); } SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
From source file:org.mozilla.labs.Soup.provider.AppsProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(APPS_TABLE_NAME);//w w w. ja v a 2s . c om switch (sUriMatcher.match(uri)) { case APPS: qb.setProjectionMap(sAppsProjectionMap); break; case APP_ID: qb.setProjectionMap(sAppsProjectionMap); qb.appendWhere(Apps._ID + "=" + uri.getPathSegments().get(1)); break; case LIVE_FOLDER_APPS: qb.setProjectionMap(sLiveFolderProjectionMap); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } // If no sort order is specified use the default String orderBy; if (TextUtils.isEmpty(sortOrder)) { orderBy = AppsContract.Apps.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; }
From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferDBBase.java
/** * Query records from the database.//from www .ja v a 2 s. c om * * @param uri A Uri indicating which part of data to query. * @param projection The projection of columns. * @param selection The "where" clause of sql. * @param selectionArgs Strings in the "where" clause. * @param sortOrder Sorting order of the query. * @param type Type of transfers to query. * @return A Cursor pointing to records. */ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); // TODO: currently all methods calling this pass null to projection. // In the future we want to update projection to be more specific for // performance and must handle that here. queryBuilder.setTables(TransferTable.TABLE_TRANSFER); final int uriType = uriMatcher.match(uri); switch (uriType) { case TRANSFERS: queryBuilder.appendWhere(TransferTable.COLUMN_PART_NUM + "=" + 0); break; case TRANSFER_ID: queryBuilder.appendWhere(TransferTable.COLUMN_ID + "=" + uri.getLastPathSegment()); break; case TRANSFER_PART: queryBuilder.appendWhere(TransferTable.COLUMN_MAIN_UPLOAD_ID + "=" + uri.getLastPathSegment()); break; case TRANSFER_STATE: queryBuilder.appendWhere(TransferTable.COLUMN_STATE + "="); queryBuilder.appendWhereEscapeString(uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } ensureDatabaseOpen(); final Cursor cursor = queryBuilder.query(database, projection, selection, selectionArgs, null, null, sortOrder); return cursor; }
From source file:com.appsimobile.appsii.module.apps.AppsProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); // Generate the body of the query int match = sURLMatcher.match(uri); switch (match) { // loads all tagged-apps in a given tag. case TABLE_APPS_ITEM: long id = ContentUris.parseId(uri); qb.setTables(TaggedAppColumns.TABLE_NAME + "," + TagColumns.TABLE_NAME); qb.setProjectionMap(sAppsProjectionMap); qb.appendWhere(TaggedAppColumns.TAG_ID + "=" + id + " AND "); qb.appendWhere("taggedApps.tag_id=tags._id"); break;//w w w. ja v a 2 s.c o m // loads all tagged apps case TABLE_APPS: qb.setTables(TaggedAppColumns.TABLE_NAME + "," + TagColumns.TABLE_NAME); qb.setProjectionMap(sAppsProjectionMap); qb.appendWhere("taggedApps.tag_id=tags._id"); break; // loads items in the launch history table case TABLE_HISTORY: qb.setTables(LaunchHistoryColumns.TABLE_NAME); qb.setProjectionMap(sHistoryProjectionMap); break; // loads all tags case TABLE_TAGS: qb.setTables(TagColumns.TABLE_NAME); qb.setProjectionMap(sTagsProjectionMap); break; default: throw new IllegalArgumentException("Invalid uri: " + uri); } return qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); }
From source file:com.hivewallet.androidclient.wallet.AddressBookProvider.java
@Override public Cursor query(final Uri uri, final String[] projection, final String originalSelection, final String[] originalSelectionArgs, final String sortOrder) { final SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(DATABASE_TABLE);/* ww w .j a va 2 s .c o m*/ final List<String> pathSegments = uri.getPathSegments(); if (pathSegments.size() > 1) throw new IllegalArgumentException(uri.toString()); String selection = null; String[] selectionArgs = null; if (pathSegments.size() == 1) { final String address = uri.getLastPathSegment(); qb.appendWhere(KEY_ADDRESS + "="); qb.appendWhereEscapeString(address); } else if (SELECTION_IN.equals(originalSelection)) { final String[] addresses = originalSelectionArgs[0].trim().split(","); qb.appendWhere(KEY_ADDRESS + " IN ("); appendAddresses(qb, addresses); qb.appendWhere(")"); } else if (SELECTION_NOTIN.equals(originalSelection)) { final String[] addresses = originalSelectionArgs[0].trim().split(","); qb.appendWhere(KEY_ADDRESS + " NOT IN ("); appendAddresses(qb, addresses); qb.appendWhere(")"); } else if (SELECTION_QUERY.equals(originalSelection)) { final String query = '%' + originalSelectionArgs[0].trim() + '%'; selection = KEY_ADDRESS + " LIKE ? OR " + KEY_LABEL + " LIKE ?"; selectionArgs = new String[] { query, query }; } final Cursor cursor = qb.query(helper.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
From source file:com.android.talkback.labeling.LabelProvider.java
/** * Queries for a label or multiple labels in the labels database. * * @param uri The URI representing the type of query to perform: * {@code LABELS_CONTENT_URI} for a subset of all labels, * {@code LABELS_ID_CONTENT_URI} for a specific label, or * {@code PACKAGE_SUMMARY} for a label count per package. * @param projection The columns to return. * @param selection The WHERE clause for the query. * @param selectionArgs The arguments for the WHERE clause of the query. * @param sortOrder the ORDER BY clause for the query. * @return A cursor representing the data resulting from the query, or] * {@code null} if the query failed to execute. *//*from www .java 2 s . co m*/ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { if (uri == null) { LogUtils.log(this, Log.WARN, NULL_URI_FORMAT_STRING); return null; } if (!UserManagerCompat.isUserUnlocked(getContext())) { return null; } final SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(LabelsTable.TABLE_NAME); String groupBy = null; switch (sUriMatcher.match(uri)) { case LABELS: if (TextUtils.isEmpty(sortOrder)) { sortOrder = LabelsTable.KEY_ID; } break; case LABELS_ID: final String labelIdString = uri.getLastPathSegment(); final int labelId; try { labelId = Integer.parseInt(labelIdString); } catch (NumberFormatException e) { LogUtils.log(this, Log.WARN, UNKNOWN_URI_FORMAT_STRING, uri); return null; } final String where = String.format(Locale.ROOT, "%s = %d", LabelsTable.KEY_ID, labelId); queryBuilder.appendWhere(where); break; case PACKAGE_SUMMARY: projection = new String[] { LabelsTable.KEY_PACKAGE_NAME, "COUNT(*)" }; groupBy = LabelsTable.KEY_PACKAGE_NAME; sortOrder = LabelsTable.KEY_PACKAGE_NAME; break; default: LogUtils.log(this, Log.WARN, UNKNOWN_URI_FORMAT_STRING, uri); return null; } initializeDatabaseIfNull(); return queryBuilder.query(mDatabase, projection, selection, selectionArgs, groupBy, null /* having */, sortOrder); }
From source file:com.gmail.emerssso.srbase.database.SRContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selArgs, String sortOrder) { // Using SQLiteQueryBuilder instead of query() method SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); int uriType = sURIMatcher.match(uri); String tableName = ""; String[] columns;//from w w w . j a v a2 s.c o m switch (uriType) { case SRS: case SR_ID: tableName = SRTable.TABLE_NAME; columns = SRTable.COLUMNS; break; case DAILIES: case DAILY_ID: tableName = DailyTable.TABLE_NAME; columns = DailyTable.COLUMNS; break; case PARTS: case PART_ID: tableName = PartTable.TABLE_NAME; columns = PartTable.COLUMNS; break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } checkColumns(projection, columns); queryBuilder.setTables(tableName); if (isIdType(uriType)) { queryBuilder.appendWhere("_id =" + uri.getLastPathSegment()); } SQLiteDatabase db = database.getWritableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selArgs, null, null, sortOrder); // make sure that potential listeners are getting notified cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }