Skip to content

Conversation

@p-schneider
Copy link

@p-schneider p-schneider commented Feb 2, 2017

I don't always update the bundled .db file when I add a new schema version but instead I add an upgrade script .sql file (e.g. database.db_upgrade_2-3.sql) and accodingly increment (e.g. 2->3) the version parameter when calling the super constructor SQLiteAssetHelper(...).
This way existing installs use the .sql script as usual and new installs copy the bundled database.db (version 2) and then execute the .sql upgrade on top of that.

I found a problem when I use setForcedUpgrade(2), now updates from version 1 to 3 would replace the old version 1 database with the bundled version 2 (like expected), but not apply the version 3 upgrade .sql file and instead just set the version to 3.

I found that the code in getWritableDatabase() blindly overrides the version of the newly copied database to be the latest version mNewVersion that had been defined by calling the super constructor.
I based this PR on top of #87 because that is also related to using setForcedUpgrade().
The main change in this PR is to remove the line db.setVersion(mNewVersion); in order to still trigger the version check and upgrade using .sql files if the bundled sqlite.db file is "outdated".

Kisty and others added 3 commits January 14, 2016 17:12
ranaparamveer pushed a commit to ranaparamveer/android-sqlite-asset-helper that referenced this pull request Jun 26, 2018
@ranaparamveer
Copy link

I'm maintaining the project here:
https://github.com/ranaparamveer/android-sqlite-asset-helper/

Most of the open issues in this original repo are resolved over there. If you still find any issue please feel free to report there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants