lundi 7 septembre 2015

How to add timestamp to ContentProvider or SQLite DataBase

I am using a SQLite backed ContentProvider to cache server data locally. I want to attach a timestamp to the entire ContentProvider so that I can very quickly check if data is up-to-date by comparing the timestamp to that of the server. One easy solution is to have an update column. But that is a bad idea since I would be copying the data for each row; whereas I only want the data once. Is there a way to save this data to disk without having to duplicate it every time? I imaging a SharedPreference-Cursor combo can do it. But, instead, is there a way to save such data in the SQLite DB itself? Or at least within the ContentProvider and be able to query it when I need it? From what I understand the contentProvider has a set interface that must match ContentResolver. So how do I save a timestamp inside the content provider and be able to read it from my app: without having to do it in every row?

Creatively I can create a table with one row for the timestamp only. But is that the best answer? Or is there a more standard way of doing this?

I know it seems like I have the answer to my own question (i.e. timestamp table of one row), but I don’t want to hack it if there is a standard or better way of doing this sort of thing.

Aucun commentaire:

Enregistrer un commentaire