开发者

Store object into SQLite database best practices

I would like to store an object into a SQLlite database. I am looking for how to best do it in order to ensure that if I need to updata/change this object in the future that users of the new and old object layout will be minimally impacted. In other words I want to ensu开发者_StackOverflowre that making changes to the object will have minimum affect on clients that do not update their software on the old database format. I want to also ensure an easy update from the old record style to the new format.

I was thinking that I could add an element in the SQL row to identify the object type with a unique name, and to identify the object version number. That way I could read the row and use the object number to control the deserializer to use the correct version of the class.

I would greatly appreciate best practices on the subject.


The info to start with is here.

Basically you will need to create a subclass of the SQLiteOpenHelper. Doing this way you will get useful callbacks to create/update your DB schema or even change data.

The SQLiteOpenHelper.onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) callback is called by OS automatically and accepts version params so you will be able to detect whether there is an upgrade or downgrade and thus to undertake needed DB changes. This way you'll be able to arrange some sort of DB migrations (in a way Rails do it).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜