CursorLoader with rawQuery

it seems that there isn't a way to just a pass a raw query to the CursorLoader constructor.

That is because CursorLoader works with content providers, and content providers do not support rawQuery().

so if anybody can point me to a simple way to run a raw query with a CursorLoader class I would appreciate it.

That is impossible, sorry. You are welcome to create your own AsyncTaskLoader that hits a SQLite database and supports rawQuery(). In fact, I will probably write one of these later this year, if I don't see where anyone has beaten me to it.


Raw query is not supported directly, but you can do a dirty hack: from your code call getContentResolver().query(RAWQUERY_CONTENT_URI, null, rawquery, args, null); and implement content provider like

@Override
public synchronized Cursor query(Uri uri, String[] projection, String selection,
       String[] selectionArgs, String sortOrder)
{
    int uriType = sURIMatcher.match(uri);
    switch (uriType)
    {
        case RAW_QUERY:
        return dbHelper.getReadableDatabase().rawQuery(selection, selectionArgs);
    }
[...]
}

Tags:

Android