Search code examples
androidsqliteandroid-4.0-ice-cream-sandwich

Absurd SQLite Error in ICS


I've implemented the code found here with the modifications from the here also.

It all seems to work fine on the Android 2.2 emulator, however on an actual ICS device and also Jellybean emulator, I seem to be getting the following (strange) error:

android.database.sqlite.SQLiteException: Can't downgrade database from version 300300 to 12

There is no way my database version is 300300, and I have tried deleting and re-installing the application but it doesn't seem to make a difference. Any clue as to why this is happening?


Solution

  • I had this same problem not too long ago. It seems to only happen on certain devices, that appear to have compiled the built-in SQLite library with write-ahead logging (WAL) turned on by default.

    This results in a problem whenever you try to open a database in read-only mode, as databases that have WAL enabled cannot be opened in read-only mode. The solution is to avoid using any SQLite API that tries to open the database in read-only mode, such as getReadableDatabase or the SQLiteDatabase.OPEN_READONLY flag. Instead, try use getWritableDatabase, or the SQLiteDatabase.OPEN_READWRITE flag whenever opening SQLite databases on Android.