Hesham Saeed
Hesham Saeed

Reputation: 5378

Updating android database

I have like 400 records on my database, suppose this is the first version of my application. In the next version I added like more 15 records, and changed 20 of the 400 already there. In this case, do I need to change the version of the database? and if so, do I need to do something in onUpgrade() function or just change the commands where i'm inserting and everything will be fine?

Thank you.

Upvotes: 1

Views: 168

Answers (2)

Mitya Kours
Mitya Kours

Reputation: 51

Update()

is called when you change already existed columns data.

onUpgrade()

is called when the structure of your table is changed. for example if you add a column.

Upvotes: 1

Seva Alekseyev
Seva Alekseyev

Reputation: 61331

I guess, you have a database with pre-filled records. Is the DB updatable by users? If not, you can just ship the new database file in the upgraded APK and be done with it. If the app logic allows for user-driven database changes, you cannot throw away the old one on upgrade. You'll have to keep track of preset record changes, keep the installed database version somewhere (i. e. in preferences), and upgrade the records when the app is upgraded. Also, you might have to deal with schema changes.

Upvotes: 3

Related Questions