Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android update SQLite DB schema?

Tags:

android

sqlite

What is the best practice for updating the DB schema? I could send a text file with the SQL commands. The app could check the text file and execute the commands needed. I am guessing then I will have a flag to indicate that the update has been done. I havent found a way to delete a file in the asset folder from the app, which would be the best thing to do after the DB was updated.

Any thoughts on this?

like image 395
Mark Worsnop Avatar asked Feb 18 '11 00:02

Mark Worsnop


2 Answers

You will probably want to override

onUpdate(SQLiteDatabase db,int old Version,int newVerison)

The following tutorial can walk you through the process: http://www.codeproject.com/KB/android/AndroidSQLite.aspx

like image 79
cagreen Avatar answered Sep 30 '22 02:09

cagreen


What is the best practice for updating the DB schema?

Use SQLiteOpenHelper. The only time you will be updating your schema is when you update the application. Whether you have the SQL commands in a file that you read in or just in your Java code is up to you.

I am guessing then I will have a flag to indicate that the update has been done.

That is part of what SQLiteOpenHelper gives you.

I havent found a way to delete a file in the asset folder from the app, which would be the best thing to do after the DB was updated.

That is not possible, sorry.

like image 24
CommonsWare Avatar answered Sep 30 '22 02:09

CommonsWare