Android: consulta sql a CONTENT_URI

Hello every androids developers! Please would you help with one question. I am trying

Cursor cursor = getContentResolver().query(Contacts.CONTENT_URI,CONTACT_PROJECTION, n" _id = _id ) GROUP BY ("+ Calls.NUMBER, null, "cnt DESC");

and it is work fine in Android 2.3.3, but at the Android 4.03 it is crashed because Android 4.03 do not support anymore GROUP BY queries. ( )

So i decide to form raw sql query to URI Contacts.CONTENT_URI with example code

ContentProviderClient client =  getContentResolver().acquireContentProviderClient(AUTHORITY);
SQLiteDatabase dbHandle= ((MyContentProvider)client.getLocalContentProvider()).getDbHandle();                    
Cursor cursor = dbHandle.rawQuery("SELECT _id, date, duration, number, type, name,   numbertype, COUNT(*) as cnt FROM calls WHERE ( 1=1 ) GROUP BY (number) ORDER BY cnt DESC", null);

o con

SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.query(db, projectionIn, selection, selectionArgs, groupBy, having, sortOrder)

that have groupBy parameter.

But i do not understood how to get dbHandle from CONTENT_URI or db name of CONTENT_URI in second case.

Gracias de antemano!

preguntado el 03 de mayo de 12 a las 14:05

1 Respuestas

Do not do SQL injection in Android. For Google will fix its bug.

The GroupBy Should be called in the ContentProvider. Not the ContentResolver.

contestado el 03 de mayo de 12 a las 14:05

But where here i will get ContentProvider.query(...) if i using CotentReslover.query(...). I must using dbHandle.rawQuery(...) but i do not know how to get dbHandle - Vitaly

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.