I have a SQLite Database file in assets which I copy to a local Sqlite Database. The SQlite Database file has more than 600 entrys and I do not know which entrys get updated exactly.
When I get the new SQLite file I change the Databaseversion number, delete the local database and copy the new Database into a new local database.
In the SQLite Database are two tables where the user can change things in the local database.
Now I want to upgrade the whole database without loosing the data from the two user tables.
I thought I could read the data from the two tables (into corresponding object lists) , upgrade the database and add the objects again.
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
List[] savedlist = savebeforeUpgrading();
myContext.deleteDatabase(DATABASE_NAME);
onCreate(db);
}
Up to this point everything is working fine. I get a List with my objects. Now there is the problem.
When I try to add the objects back into the new Database inside the onUpgrade method I get either "IllegalStateException: getDatabase called recursively" or "SQLiteReadOnlyDatabaseException: attempt to write a readonly database " when I use the SQLiteDatabase from the onUpgrade method.
How can I get around this problem and save the two tables during the onUpgrade process?
Aucun commentaire:
Enregistrer un commentaire