android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY): , while compiling: PRAGMA journal_mode
the stacktrace has some mentions of Sentry (the crash reporting tool) and it also points me to this block of code.
1. Does it seem like sentry could be the culprit?
Copy code
at io.sentry.android.sqlite.SentrySupportSQLiteOpenHelper$sentryWritableDatabase$2.invoke(SentrySupportSQLiteOpenHelper.kt:40)
2. or is my code here somehow bad?
Copy code
suspend fun itemExists(id: String): Boolean {
var result = false
withContext(myIoDispatcher) {
val foo = myQueries.selectById(id).executeAsOneOrNull()
if (foo != null) {
result = true
}
}
return result
}
Colton Idle
10/11/2023, 6:38 PM
According to the only google search result hit. This could be from reading and writing to the database at one time. That seems weird though.
My other method (that adds like 100k records at one time) is written like this
Copy code
suspend fun deleteAllThenInsertAll(bufferedReader: BufferedReader) =
withContext(myIoDispatcher) {
myQueries.transaction {
myQueries.deleteAll()
// read bufferedReader line by line and insert in the transaction
Colton Idle
10/11/2023, 6:49 PM
Could it be... my provider was missing Singleton annotation?
Copy code
@Provides
fun provideDelight(@ApplicationContext context: Context): DbService {
val driver = AndroidSqliteDriver(The.Schema, context, "the.db")
return DbService(driver)
}
d
Daniel Perez
10/12/2023, 2:08 AM
That's what I was thinking. I'm under the impression your DB should be a singleton in your app.
c
Colton Idle
10/12/2023, 5:12 PM
I thought it was already. so definitely a "me" problem. lol
p
Paul Woitaschek
10/13/2023, 5:11 AM
We have this on iOS, and it's definitely a singleton
m
Matt Nelson
10/14/2023, 8:32 AM
Don't think I'll ever go back to using the
AndroidSqliteDriver
and all that android glue being used under the hood (and needing
Context
). sqlite-jdbc is where it's at, and loads the latest version of