Java Code Examples for android.database.sqlite.SQLiteQueryBuilder#appendWhere()
The following examples show how to use
android.database.sqlite.SQLiteQueryBuilder#appendWhere() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoContentProvider.java From NekoSMS with GNU General Public License v3.0 | 6 votes |
@Override public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { int matchCode = mUriMatcher.match(uri); if (matchCode < 0) { throw new IllegalArgumentException("Invalid query URI: " + uri); } SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); if (isItemUri(matchCode)) { queryBuilder.appendWhere(BaseColumns._ID + "=" + uri.getLastPathSegment()); } queryBuilder.setTables(getTableName(matchCode)); SQLiteDatabase db = getDatabase(false); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 2
Source File: SudokuDatabase.java From opensudoku with GNU General Public License v3.0 | 6 votes |
/** * Returns the folder info. * * @param folderID Primary key of folder. * @return */ public FolderInfo getFolderInfo(long folderID) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(FOLDER_TABLE_NAME); qb.appendWhere(FolderColumns._ID + "=" + folderID); SQLiteDatabase db = mOpenHelper.getReadableDatabase(); try (Cursor c = qb.query(db, null, null, null, null, null, null)) { if (c.moveToFirst()) { long id = c.getLong(c.getColumnIndex(FolderColumns._ID)); String name = c.getString(c.getColumnIndex(FolderColumns.NAME)); FolderInfo folderInfo = new FolderInfo(); folderInfo.id = id; folderInfo.name = name; return folderInfo; } else { return null; } } }
Example 3
Source File: MyTodoContentProvider.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Uisng SQLiteQueryBuilder instead of query() method SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); // Check if the caller has requested a column which does not exists checkColumns(projection); // Set the table queryBuilder.setTables(TodoTable.TABLE_TODO); int uriType = sURIMatcher.match(uri); switch (uriType) { case TODOS: break; case TODO_ID: // Adding the ID to the original query queryBuilder.appendWhere(TodoTable.COLUMN_ID + "=" + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } SQLiteDatabase db = database.getWritableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); // Make sure that potential listeners are getting notified cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 4
Source File: RecipeContentProvider.java From search-samples with Apache License 2.0 | 5 votes |
public Cursor getRecipe(Uri uri) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(RecipeTable.TABLE); String[] projection = { RecipeTable.ID, RecipeTable.TITLE, RecipeTable.DESCRIPTION, RecipeTable.PHOTO, RecipeTable.PREP_TIME}; SQLiteDatabase db = database.getReadableDatabase(); queryBuilder.appendWhere(RecipeTable.ID + "='" + uri.getLastPathSegment() + "'"); Cursor cursor = queryBuilder.query(db, projection, null, null, null, null, null); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 5
Source File: RecipeContentProvider.java From search-samples with Apache License 2.0 | 5 votes |
public Cursor getIngredientsByRecipe(Uri uri) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(RecipeTable.TABLE + ", " + RecipeIngredientTable.TABLE); queryBuilder.appendWhere(RecipeTable.ID + "='" + uri.getLastPathSegment() + "' AND " + RecipeIngredientTable.RECIPE_ID + "=" + RecipeTable.ID + ""); String[] projection = {RecipeIngredientTable.AMOUNT, RecipeIngredientTable.DESCRIPTION}; SQLiteDatabase db = database.getReadableDatabase(); Cursor cursor = queryBuilder.query(db, projection, null, null, null, null, null); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 6
Source File: CalendarProvider.java From ExtendedCalendarView with Apache License 2.0 | 5 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder(); sqlBuilder.setTables(EVENTS_TABLE); if(uriMatcher.match(uri) == 1){ sqlBuilder.setProjectionMap(mMap); }else if(uriMatcher.match(uri) == 2){ sqlBuilder.setProjectionMap(mMap); sqlBuilder.appendWhere(ID + "=?"); selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,new String[] {uri.getLastPathSegment()}); }else if(uriMatcher.match(uri) == 3){ sqlBuilder.setProjectionMap(mMap); sqlBuilder.appendWhere(START + ">=? OR "); sqlBuilder.appendWhere(END + "<=?"); List<String> list = uri.getPathSegments(); String start = list.get(1); String end = list.get(2); selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,new String[] {start,end}); } if(sortOrder == null || sortOrder == "") sortOrder = START + " COLLATE LOCALIZED ASC"; Cursor c = sqlBuilder.query(db, projection, selection, selectionArgs,null,null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
Example 7
Source File: OfflineNotesProvider.java From soas with Apache License 2.0 | 5 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); // Make sure requested columns exist. checkColumns(projection); // Set table. queryBuilder.setTables(OfflineNotesDataSource.TABLE_NAME); int uriType = sUriMatcher.match(uri); switch (uriType) { case OFFLINE_NOTES: break; case OFFLINE_NOTE_ID: // Query by OfflineNote Id queryBuilder.appendWhere(OfflineNotesDataSource.COLUMN_ID + "=" + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } SQLiteDatabase database = mDatabaseHelper.getWritableDatabase(); Cursor cursor = queryBuilder.query(database, projection, selection, selectionArgs, null, null, sortOrder); // Register to watch a content URI for changes. cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 8
Source File: RecipeContentProvider.java From app-indexing with Apache License 2.0 | 5 votes |
public Cursor getRecipe(Uri uri) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(RecipeTable.TABLE); String[] projection = {RecipeTable.ID, RecipeTable.TITLE, RecipeTable.DESCRIPTION, RecipeTable.PHOTO, RecipeTable.PREP_TIME}; SQLiteDatabase db = database.getReadableDatabase(); queryBuilder.appendWhere(RecipeTable.ID + "='" + uri.getLastPathSegment() + "'"); Cursor cursor = queryBuilder.query(db, projection, null, null, null, null, null); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 9
Source File: MyTodoContentProvider.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Uisng SQLiteQueryBuilder instead of query() method SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); // Check if the caller has requested a column which does not exists checkColumns(projection); // Set the table queryBuilder.setTables(TodoTable.TABLE_TODO); int uriType = sURIMatcher.match(uri); switch (uriType) { case TODOS: break; case TODO_ID: // Adding the ID to the original query queryBuilder.appendWhere(TodoTable.COLUMN_ID + "=" + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } SQLiteDatabase db = database.getWritableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); // Make sure that potential listeners are getting notified cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 10
Source File: MonsterInfoProvider.java From PADListener with GNU General Public License v2.0 | 5 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { MyLog.entry("uri = " + uri); final SQLiteDatabase db = getDbHelper().getReadableDatabase(); final MonsterInfoDescriptor.Paths path = MonsterInfoDescriptor.matchUri(uri); final SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); builder.setTables(MonsterInfoDescriptor.TABLE_NAME); switch (path) { case INFO_BY_ID: // Add the ID builder.appendWhere(MonsterInfoDescriptor.Fields.ID_JP.getColName() + "=?"); selectionArgs = MyDatabaseUtils.appendWhereArgsToSelectionArgs(selectionArgs, new String[]{uri.getLastPathSegment()}); break; case ALL_INFO: break; default: throw new IllegalArgumentException("Unknown URI " + uri); } final Cursor cursor = builder.query(db, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); MyLog.exit(); return cursor; }
Example 11
Source File: NotesProvider.java From diva-android with GNU General Public License v3.0 | 5 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); // The table to query queryBuilder.setTables(TABLE); switch (urimatcher.match(uri)) { // maps all database column names case PATH_TABLE: break; case PATH_ID: queryBuilder.appendWhere( C_ID + "=" + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Divanotes(query): Unknown URI " + uri); } if (sortOrder == null || sortOrder == "") { // If no sorting specified by called then sort on title by default sortOrder = C_TITLE; } Cursor cursor = queryBuilder.query(mDB, projection, selection, selectionArgs, null, null, sortOrder); // register to watch a content URI for changes and notify the content resolver cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 12
Source File: MultiChatRoomManager.java From yiim_v2 with GNU General Public License v2.0 | 5 votes |
public Cursor query(SQLiteDatabase db, int type, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(TABLE_NAME); if (type == UriType.MULTI_ROOM.getCode()) { qb.setProjectionMap(mProjectionMap); } else if (type == UriType.MULTI_ROOM_ID.getCode()) { qb.setProjectionMap(mProjectionMap); qb.appendWhere(MultiChatRoomColumns._ID + "=" + uri.getPathSegments().get(1)); } else if (type == UriType.LIVE_FOLDER_MULTI_ROOM.getCode()) { qb.setProjectionMap(mLiveFolderProjectionMap); } else { throw new IllegalArgumentException("Unknown URI " + uri); } // If no sort order is specified use the default String orderBy; if (TextUtils.isEmpty(sortOrder)) { orderBy = MultiChatRoomColumns.DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } // Get the database and run the query Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy); return c; }
Example 13
Source File: RecipeContentProvider.java From search-samples with Apache License 2.0 | 5 votes |
public Cursor getInstructionsByRecipe(Uri uri) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(RecipeTable.TABLE + ", " + RecipeInstructionsTable.TABLE); queryBuilder.appendWhere(RecipeTable.ID + "='" + uri.getLastPathSegment() + "' AND " + RecipeInstructionsTable.RECIPE_ID + "=" + RecipeTable.ID + ""); String[] projection = {RecipeInstructionsTable.NUM, RecipeInstructionsTable.DESCRIPTION, RecipeInstructionsTable.PHOTO}; SQLiteDatabase db = database.getReadableDatabase(); Cursor cursor = queryBuilder.query(db, projection, null, null, null, null, null); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 14
Source File: BinaryProvider.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * {@inheritDoc} */ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Log.i(TAG, "query() uri=" + uri.toString() + " projection=" + TextUtils.join(",", projection)); SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(TABLE); switch (sUriMatcher.match(uri)) { case ITEMS: break; case ITEM_ID: qb.appendWhere(BinarySQLFormat._ID + "=" + uri.getPathSegments().get(1)); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } String orderBy; if (TextUtils.isEmpty(sortOrder)) { orderBy = BinarySQLFormat.DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } SQLiteDatabase db = mOpenHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
Example 15
Source File: FavoritesContentProvider.java From android with Apache License 2.0 | 5 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Using SQLiteQueryBuilder instead of query() method SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); // Check if the caller has requested a column which does not exists checkColumns(projection); // Set the table queryBuilder.setTables(FavoritesTable.TABLE_FAVORITES); int uriType = sURIMatcher.match(uri); switch (uriType) { case FAVORITES: break; case FAVORITE_ID: // Adding the ID to the original query queryBuilder.appendWhere(FavoritesTable.COLUMN_ID + "=" + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } SQLiteDatabase db = database.getWritableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); // Make sure that potential listeners are getting notified cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 16
Source File: UserDictionaryProvider.java From Chimee with MIT License | 5 votes |
@Override public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (sUriMatcher.match(uri)) { case WORDS: qb.setTables(USERDICT_TABLE_NAME); qb.setProjectionMap(sDictProjectionMap); break; case WORD_ID: qb.setTables(USERDICT_TABLE_NAME); qb.setProjectionMap(sDictProjectionMap); qb.appendWhere("_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 = UserDictionary.Words.DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } // Get the database and run the query SQLiteDatabase db = mOpenHelper.getReadableDatabase(); Cursor cursor = qb.query(db, projection, selection, selectionArgs, null, null, orderBy); // Tell the cursor what uri to watch, so it knows when its source data changes Context context = getContext(); if (context != null) cursor.setNotificationUri(context.getContentResolver(), uri); return cursor; }
Example 17
Source File: RecipeContentProvider.java From search-samples with Apache License 2.0 | 5 votes |
public Cursor getNoteByRecipe(Uri uri) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(RecipeTable.TABLE + ", " + RecipeNoteTable.TABLE); queryBuilder.appendWhere(RecipeTable.ID + "='" + uri.getLastPathSegment() + "' AND " + RecipeNoteTable.RECIPE_ID + "=" + RecipeTable.ID); String[] projection = {RecipeNoteTable.TEXT}; SQLiteDatabase db = database.getReadableDatabase(); Cursor cursor = queryBuilder.query(db, projection, null, null, null, null, null); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 18
Source File: FeedContentProvider.java From AnotherRSS with The Unlicense | 5 votes |
@Nullable @Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder ) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(FeedContract.Feeds.TABLE_NAME); int uriType = sURIMatcher.match(uri); switch (uriType) { case FEEDS: break; case FEED_ID: queryBuilder.appendWhere( FeedContract.Feeds._ID + "=" + uri.getLastPathSegment() ); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } SQLiteDatabase db = _database.getWritableDatabase(); Cursor cursor = queryBuilder.query( db, projection, selection, selectionArgs, null, null, sortOrder ); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 19
Source File: DbMigration.java From LibreTasks with Apache License 2.0 | 5 votes |
private static void generalizeAttribute(String attributeName, String newAttributeName, long newAttributeDbID, RegisteredEventAttributeDbAdapter eventAttributeDbAdapter, RuleFilterDbAdapter ruleFilterDbAdapter, RuleActionParameterDbAdapter ruleActionParamDbAdapter) { Cursor cursor = eventAttributeDbAdapter.fetchAll(attributeName, null, null); while (cursor.moveToNext()) { // Delete the entry in the Event Attribute Table long primaryKey = CursorHelper.getLongFromCursor(cursor, RegisteredEventAttributeDbAdapter.KEY_EVENTATTRIBUTEID); eventAttributeDbAdapter.delete(primaryKey); // Update the Event Attribute ID on existing rule filters to the more general version ContentValues values = new ContentValues(); values.put(RuleFilterDbAdapter.KEY_EVENTATTRIBUTEID, newAttributeDbID); ruleFilterDbAdapter.sqlUpdate(values, RuleFilterDbAdapter.KEY_EVENTATTRIBUTEID + " = " + primaryKey); // Update all attribute tags in existing rule parameters to the general version SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.appendWhere(RuleActionParameterDbAdapter.KEY_RULEACTIONPARAMETERDATA + " LIKE \"%<" + attributeName + ">%\""); Cursor paramCursor = ruleActionParamDbAdapter.sqlQuery(queryBuilder); while (paramCursor.moveToNext()) { long paramID = CursorHelper.getLongFromCursor(paramCursor, RuleActionParameterDbAdapter.KEY_RULEACTIONPARAMETERID); String newParamData = CursorHelper.getStringFromCursor(paramCursor, RuleActionParameterDbAdapter.KEY_RULEACTIONPARAMETERDATA).replaceAll( "<" + attributeName + ">", "<" + newAttributeName + ">"); ruleActionParamDbAdapter.update(paramID, null, null, newParamData); } paramCursor.close(); } cursor.close(); }
Example 20
Source File: AndroidSql.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | 4 votes |
public void sampleSQLiteQueryBuilder(SQLiteQueryBuilder builder, String input) { builder.appendWhere(input); //buildQueryString builder.buildQueryString(false, null, null, input, null, null, null, null); builder.buildQueryString(false, null, null, null, input, null, null, null); builder.buildQueryString(false, null, null, null, null, input, null, null); builder.buildQueryString(false, null, null, null, null, null, input,null); builder.buildQueryString(false, null, null, null, null, null,null, input); //query no limit builder.query(null, null, input, null, null, null,null); builder.query(null, null, null, null, input, null,null); builder.query(null, null, null, null,null,input,null); builder.query(null, null, null, null,null,null,input); //query with limit builder.query(null, null, input, null, null, null,null, null); builder.query(null, null, null, null, input, null,null, null); builder.query(null, null, null, null,null,input,null, null); builder.query(null, null, null, null,null,null,input, null); builder.query(null, null, null, null,null,null,null, input); //query with limit with cancellation system builder.query(null, null, input, null, null, null,null, null, new CancellationSignal()); builder.query(null, null, null, null, input, null,null, null, new CancellationSignal()); builder.query(null, null, null, null,null,input,null, null, new CancellationSignal()); builder.query(null, null, null, null,null,null,input, null, new CancellationSignal()); builder.query(null, null, null, null,null,null,null, input, new CancellationSignal()); //buildQuery builder.buildQuery(null, input, null, null, null, null); builder.buildQuery(null, null, input,null, null, null); builder.buildQuery(null, null, null, input, null, null); builder.buildQuery(null, null, null, null, input, null); builder.buildQuery(null, null, null, null, null, input); //buildQuery with selectionArgs builder.buildQuery(null, input, new String[0], null, null, null, null); builder.buildQuery(null, null, new String[0], input, null, null, null); builder.buildQuery(null, null, new String[0],null, input,null, null); builder.buildQuery(null, null, new String[0],null, null, input,null); builder.buildQuery(null, null, new String[0],null, null, null, input); //buildUnionQuery builder.buildUnionQuery(new String[] {input}, null, null); builder.buildUnionQuery(null, input, null); builder.buildUnionQuery(null, null, input); //buildUnionSubQuery builder.buildUnionSubQuery(null, null, null,0, null, input, null, null); builder.buildUnionSubQuery(null, null, null,0, null, null, input, null); builder.buildUnionSubQuery(null, null, null,0, null, null, null, input); //buildUnionSubQuery with selectionArgs builder.buildUnionSubQuery(null, null, null,0, null, input, new String[0],null, null); builder.buildUnionSubQuery(null, null, null,0, null, null, new String[0], input, null); builder.buildUnionSubQuery(null, null, null,0, null, null, new String[0], null, input); }