Reputation: 912
Room 1.1.0 version.
I am getting this error on the first run after migration.
It runs well if I close the app and start it again.
ROOM: Cannot run invalidation tracker. Is the db closed?
java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:1182)
at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:792)
at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:518)
Caused By : SQL(query) error or missing database.
(no such table: room_table_modification_log (code 1): , while compiling: DELETE FROM proposals WHERE hotel_id = ?)
#################################################################
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1095)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:660)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1417)
at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.compileStatement(FrameworkSQLiteDatabase.java:64)
at android.arch.persistence.room.RoomDatabase.compileStatement(RoomDatabase.java:244)
at android.arch.persistence.room.SharedSQLiteStatement.createNewStatement(SharedSQLiteStatement.java:65)
at android.arch.persistence.room.SharedSQLiteStatement.getStmt(SharedSQLiteStatement.java:77)
at android.arch.persistence.room.SharedSQLiteStatement.acquire(SharedSQLiteStatement.java:87)
at com.hotellook.db.dao.FavoritesDao_Impl.removeProposals(FavoritesDao_Impl.java:723)
The DB initialization code looks like this (Dagger AppModule)
@Provides
@Singleton
fun provideDataBase(app: Application): AppDatabase =
Room.databaseBuilder(app, AppDatabase::class.java, DATABASE_NAME)
.addMigrations(MIGRATION_1_2)
.addMigrations(MIGRATION_2_3)
.build()
private companion object {
const val DATABASE_NAME = "app.db"
val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE table1 ADD COLUMN column0 TEXT;")
database.execSQL("ALTER TABLE table2 ADD COLUMN column0 TEXT;")
}
}
val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE table0 (column1 INTEGER NOT NULL, column2 TEXT NOT NULL, PRIMARY KEY(column1))")
database.execSQL("ALTER TABLE table1 ADD COLUMN column1 TEXT;")
database.execSQL("ALTER TABLE table1 ADD COLUMN column2 TEXT;")
database.execSQL("ALTER TABLE table1 ADD COLUMN column3 REAL;")
database.execSQL("ALTER TABLE table2 ADD COLUMN column1 TEXT;")
database.execSQL("ALTER TABLE table2 ADD COLUMN column2 REAL;")
database.execSQL("ALTER TABLE table3 ADD COLUMN column1 INTEGER DEFAULT 0;")
database.execSQL("ALTER TABLE table3 ADD COLUMN column2 TEXT;")
}
}
The app upgrades from version 2 to 3. How can I fix it?
Upvotes: 16
Views: 6164
Reputation: 61
in my case, i failed with this bug when I used LiveData and overrided onOpen(db: SupportSQLiteDatabase) when i created instance of RoomDatabse
Room.databaseBuilder(context.applicationContext, AppDatabase::class.java, DATABASE_NAME)
.addMigrations(MIGRATION_1_2)
.addCallback(object : Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)
initTypeDataFirstTime(context)
}
override fun onOpen(db: SupportSQLiteDatabase) {
super.onOpen(db)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
db.disableWriteAheadLogging()
}
}
})
.build()
Upvotes: 0
Reputation: 1221
i fixed this crash. my private key type and foreign key type is not equal ,
after set equal type, crash not happen
Upvotes: -1
Reputation: 1858
Bump up the version to 1.1.1-rc1 and this nonsensical error that stems from Google's own code will not happen anymore, I've tested the same scenario on numerous devices.
Also see my question/answer here
Upvotes: 16