0

Am making an app, which contains a database in the assets folder, say the database as db1. When I open the app, am again creating a db using the API'S. Both the db names are similar.

When copying the db I see that the db1 created using api`s is getting over written by db1 in assets. Here I have a solution that first to copy the db from assets then followed by open the same in java. In assets folder db it contains tables namely A,B,C and the db created using code am making tables A,B,C,D,E,F.

Now what I want is:

When I give an upgrade for the app, I cannot blindly copy the database in the assets will overwrite all the existing data in the db1( All tables ). I want to know can I copy the database with some other name say db2. Then open and copy all the tables in db2 and overwrite those tables in db1 with the newly copied tables; i,e tables A,B,C tables in db1 has to be replaced with with the tables in db2.

I want know if it is possible or not? If possible some give me some samples are references.

1 Answer 1

1

Upgrading the app doesn't force the database to be upgraded. So unless you actually change the DB's version number, that you pass to the constructor of SQLiteOpenHelper, the old database won't change.

If you do change the DB's version number because you have changed the database schema, then you have to override the onUpgrade method, copy the necessary information from the existing DB to some temporary location (or memory), copy the DB file from assets and insert the data back.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.