4this
4this

Reputation: 759

android - How to use getContentResolver().query for multiple columns?

Im using the next code to get info about a row in the db by the _ID -

Cursor c = getActivity().getContentResolver().query(PlacesContract.Places.CONTENT_URI, null,PlacesContract.Places._ID + " = " + id, null, null);

Now i'm trying to use this query in order to check if a item is already exists in the db, and i want the check will also ignore case sensitive.

So i understand that i need to use spme where this segment - ? COLLATE NOCASE.

And i guess that the row i want to check will be like this -

String [] projection = {PlacesContract.Favourites.NAME, PlacesContract.Favourites.ADDRESS};

and i know that somewhere i nedd to chek if each one is equal to a term, but what i don't understand how should i apply it into the query.

Cursor c = getActivity().getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder)

so if anyone can help me understand it - it will be great Thanks in advance for any kind of help

Upvotes: 1

Views: 9925

Answers (1)

Givi
Givi

Reputation: 3283

OK. It goes like this: (example for a simple contacts query)

String[] PROJECTION = { ContactsContract.Data._ID, ContactsContract.Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.Contacts._ID,
                        ContactsContract.Contacts.IN_VISIBLE_GROUP, ContactsContract.CommonDataKinds.Phone.TYPE };
String SELECTION = ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "'" + " AND "
                            + ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'" + " AND " + ContactsContract.CommonDataKinds.Phone.TYPE + " = '"
                            + ContactsContract.CommonDataKinds.Phone.TYPE_MAIN + "'";

Instead of '1' of the other values in the SELECTION, you can add selectionArgs accordingly.

Upvotes: 1

Related Questions