2

I understood that the GROUP BY clause is no longer supported in Android ICS (https://stackoverflow.com/questions/8837544/android-ics-sqlite-error). Anyone with an idea what to use instead? I'm using a ContentProvider, not querying the DB directly.

Here is a sample query that used to work on Android versions lower than ICS. Any ideas how to rewrite it?

Cursor cursor = activity.getContentResolver().query(Data.CONTENT_URI, // from
    new String[] { StructuredPostal._ID, StructuredPostal.CITY, StructuredPostal.COUNTRY }, // select
    Data.MIMETYPE + "='" + StructuredPostal.CONTENT_ITEM_TYPE + "' AND " 
    + StructuredPostal.CITY + " <> '' "  // where 
    + ") GROUP BY (" + StructuredPostal.CITY 
    , null, // args
    StructuredPostal.CITY + " ASC, " + StructuredPostal.COUNTRY + " ASC"); // sort by

EDIT: The error is Caused by: android.database.sqlite.SQLiteException: near "GROUP": syntax error:...

Community
  • 1
  • 1
Eir
  • 1,003
  • 9
  • 24
  • Are you sure that ICS doesn't support GROUP BY? I've seen no mention of this other than that question. – David Snabel-Caunt Feb 25 '12 at 15:03
  • David, I guess that the GROUP BY was a hack, and not something "officially" supported, so I suppose that's why I saw no special notification in regard to this. – Eir Feb 25 '12 at 17:31
  • Waqas, I pasted the error message. Do you think I'd be able to use the `GROUP BY` in a RawQuery, when the ContentProvider fails? I doubt. Other than that, could I use RawQuery for this content source? – Eir Feb 25 '12 at 17:33

1 Answers1

0

The solution that works for me: Group By in ContentResolver in Ice Cream Sandwich

Not the most elegant, but does the job.

Community
  • 1
  • 1
Eir
  • 1,003
  • 9
  • 24