Updating an application with pre-installed SQLite

My application uses pre-downloaded and copied from / assets to data / data ( sending an application with a database ) db, which is just one table of product data and read-only, because users do not save to the database. If I add more products to the database table, I need to get this for existing users. If I update my application with a new database, the update process will delete the old database that was copied from the resource directory to data / data, thereby allowing the "DBexists" check to fail the first time the updated version is launched, thereby starting to copy the new database from / assets to data / data?

+1
android sqlite
Aug 05 2018-11-11T00:
source share
2 answers

The short answer is yes, if you put the following snippet of text in the onUpgrade() method:

 try { copyDataBase("database.db"); } catch (IOException e) { Log.w(TAG, e); } 

It might be worth deleting the db file in copyDataBase() before writing over it to reduce the chance of corruption.

NB: this uses the implementation used in the accepted answer of a question related to you.

+1
Aug 05 2018-11-11T00:
source share

At the top of my head, I can only think about slightly abusing the onUpgrade () method in your SQLiteOpenHelper implementation and modifying the database by contacting it with a new version number and having it do everything you need to do in this method .

Speaking of which, I know very little about the process of updating Android applications, so it can be far.

0
Aug 05 2018-11-11T00:
source share



All Articles