Reputation: 73
I am trying to run a simple query on the android Browser Content Provider. The bookmarks are mixed with history items, so to get the bookmarks only one needs to select "Browser.BookmarkColumns.BOOKMARK = 1". Using
String mSelectionClause = Browser.BookmarkColumns.BOOKMARK + " = 1";
with
Cursor cursor = getContentResolver().query(Browser.BOOKMARKS_URI, null, mSelectionClause, null, null);
works fine. But all my attempts to get the same result with a placeholder fail:
String mSelectionClause = Browser.BookmarkColumns.BOOKMARK + " = ?";
The query:
Cursor cursor = getContentResolver().query(Browser.BOOKMARKS_URI, null, mSelectionClause, mSelectinArgs, null);
returns an empty Cursor in all these cases:
mSelectionArgs[0] = "1"
mSelectionArgs[0] = '1'
mSelectionArgs[0] = String.valueOf(1)
mSelectionArgs[0] = Integer.toString(1)
mSelectionArgs[0] = 1 + "" (idea picked up on this site)
Am I doing something wrong or should I give up the hope of using a placeholder?
Cheers.
Upvotes: 3
Views: 563
Reputation: 5696
The Android database API was designed for Strings and not Integers. Some people says it was a mistake in the design of the API.
Anyway, in your example String mSelectionClause = Browser.BookmarkColumns.BOOKMARK + " = 1";
you are using an integer (= 1). This is the best and only way to deal with Integers. It is also safe to do so. If you were to use strings, your second solution would be the safest.
Upvotes: 4