Android: SQLite query with selection WHERE clause is not processed
Ok, so it seems query()
method of your provider is causing problems.Make sure it looks like following.
@Overridepublic abstract Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {...// run the querydb.query(db, projection, selection, selectionArgs, groupBy, having, sortOrder, limit);
You are not forced to use selectionArgs
parameter, but with it code is more readable.To debug a query you can use
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();Log.e(TAG, qb.buildQuery(projection, selection, selectionArgs, groupBy, having, sortOrder, limit);
EDIT:If you have a ContentProvider
implemented you don't need to expose getLocations()
method as you/users can use ContentProvider's
query()
method.You should pass at least those arguments whose can be passed in query()
method and those are projection
, selection
, selectionArgs
and sortOrder
.
Shouldn't that line be:
Cursor cursor = getContentResolver().query(uri, null, getSelectionString(), null, null);
Note the added parens after getSelectionString
to indicate it's a method call, not a string (although I do wonder why that wouldn't throw an error as getSelectionString
wouldn't exist as a string if my theory is correct...).