views:

48

answers:

2

Hiya folks,

I have a question about when you distribute your app with an existing DB.

Right now I've created a basic app, and from my understanding, the .db file should be in the assets folder, and when the user first runs your app it should check if the DB exists in the \data\data\ folder, if it's not there it should copy it over...correct?

My question is, what about updates? When the user downloads an update to said app, we'll need to insert a more rows into a couple specific tables (I think there's about 8 tables in total). How should this be handled? Should the DB be overwritten completely or is there a way copy over the differences?

Thanks for your help! Sorry if it sounds a bit confusing.

+1  A: 

This can be handled for you by SQLiteOpenHelper.onUpgrade.

You can read the Notepad tutorial if you want to see an example in action.

JRL
Damn, that was a fast response! Thanks so much!
dagonal
I'm at work right now, so I can't check...but how does the application know what version the DB is? There's no field in the DB to alter...
dagonal
The database version is stored as a pragma value: for example, type `PRAGMA user_version` in a sqlite3 prompt to see the current version of the database.
Veeti
A: 

I have some data that I distribute with my app. Instead of shipping a binary DB, I just ship a static JSON file that is included in the app and load the data into a blank DB on the first run. That way I can more easily update the initial values that are stored in the database.

Steve Pomeroy