I have used this example to create a database that I copy over on a fresh install
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
Problem I have now is I have now done some updates to the database and I asummed I also do this updates to the master file within the build so the users always get the most update version on new install
I have a different class that deals with all the db calls query statements.
I have set this line
private static final int DATABASE_VERSION = 5;
On a fresh install now the database is copied over correctly but when the query class calls the databasehelper again the onupgrade() method is called and tries to update to the latest version and the app crashes as it is trying to do upgrades that cannot be done
I was under the understanding that the following set the database version on fresh installs or is this wrong. If so how do I set the database version for new installs
public DatabaseHelper(Context context) {
super(context, DB_NAME, null, DATABASE_VERSION);
this.context = context;
}
just for completness here is a sample of the onupgrade()
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
dbUpgrade = new DatabaseUpgrades(context);
Log.d(DEBUG_TAG, "Calling onupgrade db");
Log.d(DEBUG_TAG + " : " + DatabaseHelper.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion);
if (oldVersion == 1) {
Log.d(DEBUG_TAG, "Updating to Version 2");
dbUpgrade.upgradeDB2(db);
oldVersion++;
}
}
Question what version is the new database set to on a fresh install and how can you overwrite it if it is not version 5
Thanks
This is correct:
I put below
getWritableDatabase()source code and as you see it won’t callonUpgrade()unless the version in the db file is not equal to current new version which you pass in the constructor(version != mNewVersionline). So either your database file is not overwritten or version number in your new database is wrong. Please check it.EDIT
You can check version in your new database file with the following query:
It should return
5in your case.