views:

466

answers:

2

I have an unfinished application, but I want to address now the future update of it.

Suppose my app was upgraded, so when starts, detects that the database schema is outdated. So for each table has to update according to version number to the new schema while preserving all data.

I've read somewhere that on Android the SQLite database have some version number, and auto update stuff, but I didn't found an example for this specific issue.

How can this be accomplished on an Android app, using SQLite databases?

Is there a specific version number per table stored on Android SQLite databases? If so, how can I read it, and use for my above purpose?

+1  A: 

Have you looked at SQLiteOpenHelper?

mbaird
how do I keep old records? the Notepad onUpgrade method doesn't specify this. Also how do I detect if a particular table needs update only?
Pentium10
+1  A: 

SQLiteOpenHelper is your friend here.

See the source for the Notepad example; you need to supply onCreate and onUpgrade methods.

Christopher
how do I keep old records? the Notepad onUpgrade method doesn't specify this. Also how do I detect if a particular table needs update only?
Pentium10
You keep old record by using ALTER TABLE statements or temp tables, as with any SQL database. Android only assists with telling you if your overall schema changes -- it is up to you to determine which tables and so forth need to be changed.
CommonsWare
(1) Can I create SQLiteOpenHelper for each table separately, then I can keep onCreate and onUpgrade distinctly on those classes, and will the onUpgrade run for each of my class when gets instantiated? (2) Or I shall create only 1 SQLiteOpenHelper class in my whole app, and include all create tables all updates in the same location?(3) How can I transfer my SQLite database from emulator to my PC?(4) Do I need to encrypt the database, or Android stores in safe place?
Pentium10
(1) will not work, but (2) should. Please open new questions for (3) and (4), or, better yet, search SO for the answers, since those questions I am sure have been covered already.
CommonsWare