Search code examples
androidsqlitecursorandroid-contentprovider

Create cursor from SQLiteStatement


I would like to use SQLiteStatement in my ContentProvider instead of the rawQuery or one of the other standard methods. I think using SQLiteStatement would give a more natural, native, efficient and less error prone approach to doing queries.

The problem is that I don't see a way to generate and return a Cursor. I realize I can use "call" and return a Bundle, but that approach requires that I cache and return all selected rows at the same time - this could be huge.

I will start looking at Android source code - I presume that "query" ultimately uses SQLiteStatement and somehow generates a Cursor. However, if anyone has any pointers or knowledge of this, I would greatly appreciate your sharing.


Solution

  • I would like to use SQLiteStatement in my ContentProvider instead of the rawQuery or one of the other standard methods. I think using SQLiteStatement would give a more natural, native, efficient and less error prone approach to doing queries.

    Quoting the documentation for SQLiteStatement:

    The statement cannot return multiple rows or columns, but single value (1 x 1) result sets are supported.

    I fail to see why you would bother with a ContentProvider for single row, single column results, but, hey, it's your app...

    The problem is that I don't see a way to generate and return a Cursor

    Create a MatrixCursor and fill in the single result.