List of usage examples for android.database.sqlite SQLiteQueryBuilder appendWhereEscapeString
public void appendWhereEscapeString(@NonNull String 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(","); }//from ww w .ja va 2 s . c om }
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);/*from w w w . j a va2 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.amazonaws.mobileconnectors.s3.transferutility.TransferDBBase.java
/** * Query records from the database./*from w ww .j av a2s .co m*/ * * @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; }