I'm trying to get all Contacts
from ContactsContract.CommonDataKinds.Email.CONTENT_URI
table
grouped by their ContactID
and Name
using CursorLoader
.
So for example, if contact have 2 emails, I will get only one row regarding this contact.
Basically, it should go like that:
SELECT ContactID, Name
FROM Table
GROUP BY ContactID, Name
My code:
String filter = ContactsContract.CommonDataKinds.Email.DATA + " NOT LIKE ''))
GROUP BY ((" + ContactsContract.CommonDataKinds.Email.CONTACT_ID + ", display_name";
final static String[] PROJECTION =
{
Utils.hasHoneycomb() ? Contacts.DISPLAY_NAME_PRIMARY : Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Email.CONTACT_ID,
};
return new CursorLoader(getActivity(),
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
ContactsQuery.PROJECTION,
filter,
null,
ContactsQuery.SORT_ORDER);
I'm getting next SQLite error:
"Caused by: android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling: SELECT DISTINCT display_name, contact_id FROM view_data_restricted data WHERE (1 AND mimetype_id = 1) AND ((data1 NOT LIKE '')) GROUP BY ((contact_id, display_name)) ORDER BY sort_key"
So this is my query:
SELECT DISTINCT display_name, contact_id FROM view_data_restricted data
WHERE (1 AND mimetype_id = 1) AND ((data1 NOT LIKE ''))
GROUP BY ((contact_id, display_name)) ORDER BY sort_key
- "DISTINCT" added by the cursorLoader. Why?
- I know there are multiple
"(" / ")"
signs, It's the best way I found to handle the adding of the "GROUP_BY". any other ideas will help. - I can't find the problem near
","
as the error said.