SQLiteDatabase Error, unhelpful Log

▼魔方 西西 提交于 2019-12-01 09:30:44

I have faced the same issue in one of my app, and how i solved that issue is through removing the cursor.close(). Hope it will help :)

I could not recreate issue because in testing, I was upgrading from DB version 3 to version 4. Many of my users were upgrading from version 2 to version 4. Some of the code for upgrading from 2 to 3 was method-based. I ended up changing some of those methods for version 4, which broke the version 3 upgrade. I then was getting a caught exception from a cursorToObject() method I had, which caused the database.close to be skipped and then I got the sqlite exception

Obviously we need to see the on-upgrade method seems to be the root cause of your issue. I use the Adams Upgrade method I named it for the blog I found it oun.

note: Each upgrade is done in the upgradeTo <= newVersion loop. Maybe someday I'll put a progress bar on this loop.

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    int upgradeTo = oldVersion + 1;
    while (upgradeTo <= newVersion) {
        switch (upgradeTo) {
        // update old resrawid's to constants
        // this was caused when I saved R values in the database
        // and then later realized they would change.
        // the old resrawid is changed to a constant.
        case 42:
            ContentValues values;
            @SuppressWarnings("unused")
            // used for debugging so I can see the value of the update.
            int res;
            int rs;
            rs = 2130968576;
            values = new ContentValues();
            values.put(
                    KEY_RESRAWID,
                    com.gosylvester.bestrides.ImageTextListViewActivity.SAMPLE_DRAGON);
            res = db.update(TABLE_RIDES, values, KEY_RESRAWID + " = ?",
                    new String[] { String.valueOf(rs) });

            rs = 2130968577;
            values = new ContentValues();
            values.put(
                    KEY_RESRAWID,
                    com.gosylvester.bestrides.ImageTextListViewActivity.SAMPLE_M119);
            res = db.update(TABLE_RIDES, values, KEY_RESRAWID + " = ?",
                    new String[] { String.valueOf(rs) });

            rs = 2130968578;
            values = new ContentValues();
            values.put(
                    KEY_RESRAWID,
                    com.gosylvester.bestrides.ImageTextListViewActivity.SAMPLE_MEDINA);
            res = db.update(TABLE_RIDES, values, KEY_RESRAWID + " = ?",
                    new String[] { String.valueOf(rs) });
            break;
        case 43:
            // new column added for last_viewed.
            db.execSQL(VERSION_43_ALTER);
            break;

        case 44:
            // new index on KEY_DATE_UPDATE DESC
            db.execSQL(VERSION_44_CREATE_INDEX);
        }
        upgradeTo++;
    }
}

Good Luck Danny117

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!