I have an DB migration:
val MIGRATION_8_9 = object : Migration(8, 9) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE RideEntity RENAME frontVideoPresent TO frontVideoState")
database.execSQL("ALTER TABLE RideEntity RENAME rearVideoPresent TO rearVideoState")
}
}
When testing this migration on local Samsung phones it worked fine. The in production with help of craslytics I seen this crash:
Fatal Exception: java.lang.RuntimeException
Exception while computing database live data.
Caused by android.database.sqlite.SQLiteException
near "frontVideoPresent": syntax error (Sqlite code 1 SQLITE_ERROR): , while
compiling: ALTER TABLE RideEntity RENAME frontVideoPresent TO frontVideoState, (OS
error - 11:Try again)
This is happened on Huawei Mate 20 phone. How to understand better this crash? This is OS related?
I can not remove the rename now, because many users that updated the app the column renaming worked, but users with Huawei phones may suffer this crash.
I am open to your suggestions...
Looks like version of sqlite on some devices doesn't support column renaming because android app use build-in version on sqlite library to android OS. That's why version of sqlite depends on android's api level version (where app running). According to sqlite release notes (paragraph 2) the support for renaming columns was added in version 3.25.0 and according to google docs (and other answer on stackoverflow)the column's renaming on android supports since android api level 30.
To solve the problem of fragmentation of slqlite library you can use android-requery which allows to use last version of sqlile in all android versions(since API level 14). It's easy to use this library with room.
Related
I have been getting this error as of lately while using room database. It tells me to upgrader the room version, but when I do this I get another error.
java.lang.IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
This is what I get when changing the database version number from: version = 1 -> version = 2.
java.lang.IllegalStateException: A migration from 1 to 2 was required but not found. Please provide the necessary Migration path via RoomDatabase.Builder.addMigration(Migration ...) or allow for destructive migrations via one of the RoomDatabase.Builder.fallbackToDestructiveMigration* methods.
How can I solve this ?
In my app I'm using `ActiveAndroid'.
During the app version I'm using migration files and increasing the db version as in documentation.
Assume:
1. There is a device with app version 1 (user doesn't update).
2. In app version 2 I add a new table "myNewTable".
3. In app version 3 I add a new column "myNewColumn" to "myNewTable".
4. In app version 4 the is now change in the db.
migration script:
alter table myNewTable add column myNewColumn text;
The user with app version 1 upgrade to version 4 and getting the following exception:
android.database.sqlite.SQLiteException: duplicate column name: myNewColumn (code 1): , while compiling: alter table myNewTable add column myNewColumn text
Similar to the that problem.
Does someone know to resolve that issue?
Everything was working fine before I added some "big" tables to my file.
I have a table that weights about 2Mo, and now I am getting this error :
07-19 00:47:51.210 4703-4703/com.lectem.gecharacters
W/SQLiteAssetHelper﹕ copying database from assets... 07-19
00:47:51.280 4703-4705/com.lectem.gecharacters E/Database﹕ close()
was never explicitly called on database
'/data/data/com.lectem.gecharacters/databases/gechar2.sqlite'
android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was
opened here
at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1810)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.returnDatabase(SQLiteAssetHelper.java:408)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.createOrOpenDatabase(SQLiteAssetHelper.java:386)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.getWritableDatabase(SQLiteAssetHelper.java:182)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.getReadableDatabase(SQLiteAssetHelper.java:254)
I tried to empty the table, and it works again after this...
I am using the SQLite Manager plugin for Firefox, and the SQLiteAssetHelper library.
Can't open database with SQLiteAssetHelper didn't help.
EDIT: I forgot to mention that it works fine on my phone (android 4.1) but the error occurs on my Tablet (android 2.2.1)
The answer was in the readme... https://github.com/jgilfelt/android-sqlite-asset-helper
I was compressing my database using gzip, but it seems you really need to use zip for old devices.
Earlier versions of this library required the database asset to be
compressed within a ZIP archive. This is no longer a requirement, but
is still supported. Applications still targeting Gingerbread (API 10)
or lower should continue to provide a compressed archive to ensure
large database files are not corrupted during the packaging process.
The more Linux friendly GZIP format is also supported. The naming
conventions using the above example are as follows:
ZIP: assets/databases/northwind.db.zip (a single SQLite database file must be the only file within the archive)
GZIP: assets/databases/northwind.db.gz
You all have probably seen that ActiveAndroid has schema migrations which are specified as <db_version>.sql files in the assets/migrations folder.
I have a db version 2, with a migration file 2.sql
Does my next version have to be 3 and migration 3.sql, or can I do something like:
DB version - 2.1
Migration file: 2.1.sql ?
I just tested it, it throw's an exception:
java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.Integer
So I guess it has to be an integer.
But that raises another question, can I increment the version by two points instead of just one?
For e.g. migration1: 2.sql
Migration2: 4.sql ?
I found some articles with the same error but solution did not work, I tried the following:
Can't downgrade database from version 2 to 1
solution: "you need to override onDowngrade" that does not apply to my code , because my database class does not extend anything.