views:

46

answers:

1

I am using a ContentProvider for caching results from a web-service query. It is an HTTP request and the response content is XML. Most of the data is cached, so I simply query the DB, if not found, request from webservice, insert in DB and requery the DB. Thus the response is always a Cursor from SQLiteDatabaseHelper.

I have one result set that is not stored in the DB and since it is 100% transient, but I would like to provide the appearance of it coming from the DB's Cursor. Is there an easy way to do this? For example, if I could project it onto the cursor with a cursor.setValue("string", objectValue) or some other existing implementation.

If not, I will either bypass the DB for this content result, or stuff it into a trivial table that is constantly reused.

+2  A: 

Depending on how you use it, it might not be too hard to write your own cursor class. For convenience, derive your class from AbstractCursor class which takes care of a lot of the details for you.

You may also be able to make use of MatrixCursor.

dhaag23
+1 for pointing out MatrixCursor.
bhups
Before I make my own subclass, I will try MatrixCursor - that is one of the indirect subclasses that I did not try.
mobibob
The MatrixCursor was EXACTLY what I was looking for. The implementation was about a half-dozen lines of code. I wrote a cursor interfaced object and it was miserable amount of work and lots of debugging of methods for a single time usage. I will revisit subclassing in the future when I think I will reuse in multiple projects (or with other developers).
mobibob
NB - I am reusing the MatrixCursor many places now. This allows an elegant way to hide behind the ContentProvider with a web service. I have been sharing this with colleagues and I have a very positive reaction.
mobibob
Cool ... yes, it's a very powerful class for simple queries. Mostly I've been doing database work so deal with real database cursors but on occasion I fill in with a MatrixCursor.
dhaag23