I am using SQLiteAssetHelper utility to manage the copying of the database from my asset folder. In the app, the user enters some data into the database and as soon as I upgrade the db, all the data gets deleted cause I have set setForcedUpgrade();
. I heard you can use upgrade scripts, but I think they do not help me in this case as the data is unique for each user. How can I solve this?
Asked
Active
Viewed 136 times
0

qwertz
- 6,206
- 9
- 40
- 62
1 Answers
1
all the data gets deleted cause I have set setForcedUpgrade();
Then do not call setForcedUpgrade()
.
I heard you can use upgrade scripts, but I think they do not help me in this case as the data is unique for each user.
The primary point of upgrade scripts is to allow you to upgrade the schema without harming existing data, "as the data is unique for each user".
How can I solve this?
Use upgrade scripts. Or, override onUpgrade()
, as you would with a regular SQLiteOpenHelper
, as onUpgrade()
is not final
.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
I would prefer to use setForcedUpgrade(), so I don't have to use upgrade scripts for all the db upgrades. – qwertz Jun 30 '15 at 13:38
-
1@qwertz: "I would prefer to use setForcedUpgrade()" -- then do not allow the user to modify the data, or do not complain about the loss of user data. This behavior of `setForcedUpgrade()` is [clearly documented](https://github.com/jgilfelt/android-sqlite-asset-helper#upgrades-via-overwrite). "so I don't have to use upgrade scripts for all the db upgrades" -- as I noted in my answer, you are welcome to override `onUpgrade()` as an alternative to using upgrade scripts in `assets/`. – CommonsWare Jun 30 '15 at 13:45