Java Code Examples for android.database.sqlite.SQLiteQueryBuilder#query()
The following examples show how to use
android.database.sqlite.SQLiteQueryBuilder#query() .
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: RegisteredActionParameterDbAdapter.java From LibreTasks with Apache License 2.0 | 6 votes |
/** * Return a Cursor contains all RegisteredActionParameter records which matches the parameters. * * @param parameterName * is the parameter name, or null to fetch any parameterName. * @param actionID * is the action id, or null to fetch any actionID. * @param dataTypeID * is the dataType id, or null to fetch any dataTypeID. * @return a Cursor contains all RegisteredActionParameter records which matches the parameters. */ public Cursor fetchAll(String parameterName, Long actionID, Long dataTypeID) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(DATABASE_TABLE); qb.appendWhere("1=1"); if (parameterName != null) { qb.appendWhere(" AND " + KEY_ACTIONPARAMETERNAME + " = "); qb.appendWhereEscapeString(parameterName); } if (actionID != null) { qb.appendWhere(" AND " + KEY_ACTIONID + " = " + actionID); } if (dataTypeID != null) { qb.appendWhere(" AND " + KEY_DATATYPEID + " = " + dataTypeID); } // Not using additional selections, selectionArgs, groupBy, having, orderBy, set them to null. return qb.query(database, KEYS, null, null, null, null, null); }
Example 2
Source File: DownloadProvider.java From letv with Apache License 2.0 | 6 votes |
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (URI_MATCHER.match(uri)) { case 100: qb.setTables(DownloadAlbumTable.TABLE_NAME); break; case 101: qb.setTables(DownloadVideoTable.TABLE_NAME); break; case 102: qb.setTables(ThreadInfoTable.TABLE_NAME); break; default: throw new IllegalStateException("Unknown URL: " + uri.toString()); } Cursor c = qb.query(this.mDownloadDBHelper.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder); if (c != null) { c.setNotificationUri(getContext().getContentResolver(), uri); } return c; }
Example 3
Source File: LogsProvider.java From GeoLog with Apache License 2.0 | 6 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(Database.Location.TABLE_NAME); int uriType = URIMatcher.match(uri); switch (uriType) { case LOCATIONS: break; case LOCATION: queryBuilder.appendWhere(Database.Location._ID + " = " + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } SQLiteDatabase db = databaseHelper.getReadableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 4
Source File: PlacesProvider.java From protrip with MIT License | 6 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(sqLiteOpenHelper.TABLE_NAME); switch (uriMatcher.match(uri)){ case PLACES_ID: queryBuilder.setProjectionMap(PlaceMap); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } if (sortOrder == null || sortOrder == ""){ sortOrder = sqLiteOpenHelper.ID; } Cursor cursor = queryBuilder.query(database, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 5
Source File: ProfilesProvider.java From GeoLog with Apache License 2.0 | 6 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(Database.Profile.TABLE_NAME); int uriType = URIMatcher.match(uri); switch (uriType) { case PROFILES: break; case PROFILE: queryBuilder.appendWhere(Database.Location._ID + " = " + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } SQLiteDatabase db = databaseHelper.getReadableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 6
Source File: SearchDB.java From moviedb-android with Apache License 2.0 | 6 votes |
public int getSuggestionSize() { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setProjectionMap(mAliasMap); queryBuilder.setTables(TABLE2_NAME); Cursor c = queryBuilder.query(mSearchDBOpenHelper.getReadableDatabase(), new String[]{"_ID", SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2, SearchManager.SUGGEST_COLUMN_ICON_1, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA}, null, null, null, null, null, "10" ); return c.getCount(); }
Example 7
Source File: DataProvider.java From AndroidRecyclerViewDemo with Apache License 2.0 | 6 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { synchronized (obj) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(matchTable(uri)); SQLiteDatabase db = getDBHelper().getReadableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; } }
Example 8
Source File: MemoProvider.java From EverMemo with MIT License | 6 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(MemoDB.MEMO_TABLE_NAME); int uriType = sURIMatcher.match(uri); switch (uriType) { case ALL_MEMOS_WITH_DELETED: break; case MEMOS: queryBuilder.appendWhere(MemoDB.STATUS + "!='" + Memo.STATUS_DELETE + "'"); break; case MEMO_ID: queryBuilder .appendWhere(MemoDB.ID + "=" + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI"); } Cursor cursor = queryBuilder.query(memoDB.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 9
Source File: RuleActionDbAdapter.java From LibreTasks with Apache License 2.0 | 5 votes |
/** * Return a Cursor that contains all RuleAction records which matches the parameters. * * @param ruleID * is id of the rule it belongs to, or null to fetch any. * @param actionID * is id of its action type, or null to fetch any. * @return a Cursor that contains all RuleAction records which matches the parameters. */ public Cursor fetchAll(Long ruleID, Long actionID) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(DATABASE_TABLE); qb.appendWhere("1=1"); if (ruleID != null) { qb.appendWhere(" AND " + KEY_RULEID + " = " + ruleID); } if (actionID != null) { qb.appendWhere(" AND " + KEY_ACTIONID + " = " + actionID); } // Not using additional selections, selectionArgs, groupBy, having, orderBy, set them to null. return qb.query(database, KEYS, null, null, null, null, null); }
Example 10
Source File: SearchDB.java From moviedb-android with Apache License 2.0 | 5 votes |
/** * Returns Suggestions */ public synchronized Cursor getSuggestions(String[] selectionArgs) { String selection = FIELD_title + " like ? "; if (selectionArgs != null) { if (!selectionArgs[0].isEmpty()) { selectionArgs[0].replaceAll("'", ""); selectionArgs[0] = "%" + selectionArgs[0] + "%"; } else { selection = null; selectionArgs = null; } } SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setProjectionMap(mAliasMap); queryBuilder.setTables(TABLE2_NAME); SQLiteDatabase db = mSearchDBOpenHelper.getReadableDatabase(); Cursor c = null; if (db.isOpen()) { c = queryBuilder.query(db, new String[]{"_ID", SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2, SearchManager.SUGGEST_COLUMN_ICON_1, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA}, selection, selectionArgs, null, null, FIELD_title + " asc ", "10" ); } return c; }
Example 11
Source File: LoaderThrottleSupport.java From V.FlyoutTest with MIT License | 5 votes |
/** * Handle incoming queries. */ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Constructs a new query builder and sets its table name SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(MainTable.TABLE_NAME); switch (mUriMatcher.match(uri)) { case MAIN: // If the incoming URI is for main table. qb.setProjectionMap(mNotesProjectionMap); break; case MAIN_ID: // The incoming URI is for a single row. qb.setProjectionMap(mNotesProjectionMap); qb.appendWhere(MainTable._ID + "=?"); selectionArgs = DatabaseUtilsCompat.appendSelectionArgs(selectionArgs, new String[] { uri.getLastPathSegment() }); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } if (TextUtils.isEmpty(sortOrder)) { sortOrder = MainTable.DEFAULT_SORT_ORDER; } SQLiteDatabase db = mOpenHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null /* no group */, null /* no filter */, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
Example 12
Source File: SettingsProvider.java From earth with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteDatabase db = dbHelper.getReadableDatabase(); SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); builder.setTables(SettingsContract.TABLE); Cursor cursor = builder.query(db, projection, null, null, null, null, null, "1"); //noinspection ConstantConditions cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 13
Source File: ServerDatabaseHandler.java From an2linuxclient with GNU General Public License v3.0 | 5 votes |
public BluetoothServer getBluetoothServer(long id){ SQLiteDatabase db = this.getReadableDatabase(); BluetoothServer bluetoothServer = new BluetoothServer(); bluetoothServer.setId(id); SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(TABLE_SERVERS + " JOIN " + TABLE_BLUETOOTH_SERVERS + " USING(" + COLUMN_ID + ")"); Cursor c = qb.query(db, new String[]{COLUMN_IS_ENABLED, COLUMN_CERTIFICATE_ID, COLUMN_BLUETOOTH_MAC_ADDRESS, COLUMN_BLUETOOTH_NAME}, COLUMN_ID + "=?", new String[]{String.valueOf(id)}, null, null, null); if (c.moveToFirst()){ bluetoothServer.setIsEnabled(intToBool(c.getInt(0))); bluetoothServer.setCertificateId(c.getLong(1)); bluetoothServer.setBluetoothMacAddress(c.getString(2)); bluetoothServer.setBluetoothName(c.getString(3)); } c.close(); db.close(); return bluetoothServer; }
Example 14
Source File: PadContentProvider.java From padland with Apache License 2.0 | 5 votes |
/** * Query to the the db * @param uri * @param projection * @param selection * @param selectionArgs * @param sortOrder * @return */ @Override public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (uriMatcher.match(uri)) { case PADLIST: qb.setTables(PAD_TABLE_NAME); qb.setProjectionMap( PROJECTION_MAP ); break; case PAD_ID: qb.setTables(PAD_TABLE_NAME); qb.appendWhere(_ID + "=" + DatabaseUtils.sqlEscapeString(uri.getPathSegments().get(1))); break; case PADGROUP_LIST: qb.setTables(PADGROUP_TABLE_NAME); qb.setProjectionMap( PROJECTION_MAP ); break; default: throw new IllegalArgumentException( "Unknown URI " + uri ); } if (sortOrder == null || sortOrder.isEmpty()){ /** * By default sort */ sortOrder = LAST_USED_DATE + " DESC "; } Cursor c = qb.query( db, projection, selection, selectionArgs, null, null, sortOrder ); /** * register to watch a content URI for changes */ c.setNotificationUri( getContext().getContentResolver(), uri ); return c; }
Example 15
Source File: TestContentProvider.java From understand-plugin-framework with Apache License 2.0 | 5 votes |
@Nullable @Override public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); SQLiteDatabase db = mDb.getReadableDatabase(); qb.setTables(TABLE_NAME); Cursor c = qb.query(db, projection, selection, null, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
Example 16
Source File: SudokuDatabase.java From opensudoku with GNU General Public License v3.0 | 5 votes |
/** * Returns list of puzzle folders. * * @return */ public Cursor getFolderList() { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(FOLDER_TABLE_NAME); SQLiteDatabase db = mOpenHelper.getReadableDatabase(); return qb.query(db, null, null, null, null, null, "created ASC"); }
Example 17
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 18
Source File: LauncherProvider.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SqlArguments args = new SqlArguments(uri, selection, selectionArgs); SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(args.table); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); Cursor result = qb.query(db, projection, args.where, args.args, null, null, sortOrder); result.setNotificationUri(getContext().getContentResolver(), uri); return result; }
Example 19
Source File: MyTracksProvider.java From mytracks with Apache License 2.0 | 4 votes |
@Override public Cursor query( Uri url, String[] projection, String selection, String[] selectionArgs, String sort) { if (!canAccess()) { return null; } SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); String sortOrder = null; switch (getUrlType(url)) { case TRACKPOINTS: queryBuilder.setTables(TrackPointsColumns.TABLE_NAME); sortOrder = sort != null ? sort : TrackPointsColumns.DEFAULT_SORT_ORDER; break; case TRACKPOINTS_ID: queryBuilder.setTables(TrackPointsColumns.TABLE_NAME); queryBuilder.appendWhere("_id=" + url.getPathSegments().get(1)); break; case TRACKS: queryBuilder.setTables(TracksColumns.TABLE_NAME); sortOrder = sort != null ? sort : TracksColumns.DEFAULT_SORT_ORDER; break; case TRACKS_ID: queryBuilder.setTables(TracksColumns.TABLE_NAME); queryBuilder.appendWhere("_id=" + url.getPathSegments().get(1)); break; case WAYPOINTS: queryBuilder.setTables(WaypointsColumns.TABLE_NAME); sortOrder = sort != null ? sort : WaypointsColumns.DEFAULT_SORT_ORDER; break; case WAYPOINTS_ID: queryBuilder.setTables(WaypointsColumns.TABLE_NAME); queryBuilder.appendWhere("_id=" + url.getPathSegments().get(1)); break; default: throw new IllegalArgumentException("Unknown url " + url); } Cursor cursor = queryBuilder.query( db, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), url); return cursor; }
Example 20
Source File: CapturedPlayerFriendProvider.java From PADListener with GNU General Public License v2.0 | 4 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 CapturedPlayerFriendDescriptor.Paths path = CapturedPlayerFriendDescriptor.matchUri(uri); final SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); switch (path) { case ALL: builder.setTables(CapturedPlayerFriendDescriptor.TABLE_NAME); break; case ALL_WITH_INFO: final Map<String, String> columnMap = new HashMap<String, String>(); fillColumnMapWithPrefix(columnMap, CapturedPlayerFriendDescriptor.TABLE_NAME, "", CapturedPlayerFriendDescriptor.Fields.values()); final StringBuilder tableBuilder = new StringBuilder(CapturedPlayerFriendDescriptor.TABLE_NAME); final String leader1TableAlias = "L1"; fillColumnMapWithPrefix(columnMap, leader1TableAlias, CapturedPlayerFriendDescriptor.ALL_WITH_INFO_LEADER1_PREFIX, CapturedPlayerFriendLeaderDescriptor.Fields.values()); tableBuilder.append(" LEFT OUTER JOIN ").append(CapturedPlayerFriendLeaderDescriptor.TABLE_NAME).append(" ").append(leader1TableAlias); tableBuilder.append(" ON "); tableBuilder.append(CapturedPlayerFriendDescriptor.TABLE_NAME).append(".").append(CapturedPlayerFriendDescriptor.Fields.LEADER1_ID.getColName()); tableBuilder.append(" = "); tableBuilder.append(leader1TableAlias).append(".").append(CapturedPlayerFriendLeaderDescriptor.Fields._ID.getColName()); tableBuilder.append(""); final String leader1InfoTableAlias = "L1_INFO"; fillColumnMapWithPrefix(columnMap, leader1InfoTableAlias, CapturedPlayerFriendDescriptor.ALL_WITH_INFO_LEADER1_INFO_PREFIX, MonsterInfoDescriptor.Fields.values()); tableBuilder.append(" LEFT OUTER JOIN ").append(MonsterInfoDescriptor.TABLE_NAME).append(" ").append(leader1InfoTableAlias); tableBuilder.append(" ON "); tableBuilder.append(leader1TableAlias).append(".").append(CapturedPlayerFriendLeaderDescriptor.Fields.ID_JP.getColName()); tableBuilder.append(" = "); tableBuilder.append(leader1InfoTableAlias).append(".").append(MonsterInfoDescriptor.Fields.ID_JP.getColName()); tableBuilder.append(""); final String leader2TableAlias = "L2"; fillColumnMapWithPrefix(columnMap, leader2TableAlias, CapturedPlayerFriendDescriptor.ALL_WITH_INFO_LEADER2_PREFIX, CapturedPlayerFriendLeaderDescriptor.Fields.values()); tableBuilder.append(" LEFT OUTER JOIN ").append(CapturedPlayerFriendLeaderDescriptor.TABLE_NAME).append(" ").append(leader2TableAlias); tableBuilder.append(" ON "); tableBuilder.append(CapturedPlayerFriendDescriptor.TABLE_NAME).append(".").append(CapturedPlayerFriendDescriptor.Fields.LEADER2_ID.getColName()); tableBuilder.append(" = "); tableBuilder.append(leader2TableAlias).append(".").append(CapturedPlayerFriendLeaderDescriptor.Fields._ID.getColName()); tableBuilder.append(""); final String leader2InfoTableAlias = "L2_INFO"; fillColumnMapWithPrefix(columnMap, leader2InfoTableAlias, CapturedPlayerFriendDescriptor.ALL_WITH_INFO_LEADER2_INFO_PREFIX, MonsterInfoDescriptor.Fields.values()); tableBuilder.append(" LEFT OUTER JOIN ").append(MonsterInfoDescriptor.TABLE_NAME).append(" ").append(leader2InfoTableAlias); tableBuilder.append(" ON "); tableBuilder.append(leader2TableAlias).append(".").append(CapturedPlayerFriendLeaderDescriptor.Fields.ID_JP.getColName()); tableBuilder.append(" = "); tableBuilder.append(leader2InfoTableAlias).append(".").append(MonsterInfoDescriptor.Fields.ID_JP.getColName()); tableBuilder.append(""); builder.setTables(tableBuilder.toString()); builder.setProjectionMap(columnMap); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } final Cursor cursor = builder.query(db, projection, selection, null, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); MyLog.exit(); return cursor; }