I know this question was asked a long time ago, but I had a similar problem, and I wanted to share my solution, it seems to have helped. I am a newbie, so feel free to contribute -
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { //code to keep table data List<obj> objList = new ArrayList<obj>(); String selectQuery = "SELECT score,list_name,quiz_length FROM obj_table"; Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { obj o = new obj(); o.final_score = cursor.getInt(0); o.quiz_name = cursor.getString(1); o.quiz_length = cursor.getInt(2); objList.add(o); } while (cursor.moveToNext()); } //done storing data, now upgrade DB from asset file try { //my db file is upgraded here copyDataBase(); } catch (IOException e) { } //now insert our saved table data for (Score obj_rec: objList){ ContentValues values = new ContentValues(); values.put("score", obj_rec.final_score); values.put("list_name", obj_rec.quiz_name); values.put("quiz_length", obj_rec.quiz_length); db.insert("obj_table", null, values); } }
source share