Android: consulta sql a CONTENT_URI
Frecuentes
Visto 1,039 veces
1
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. ( https://stackoverflow.com/questions/8837544/android-ics-sqlite-error )
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!
1 Respuestas
1
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
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas android sqlite android-4.0-ice-cream-sandwich android-contentresolver or haz tu propia pregunta.
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