Set busy timeout on all connections

pull/3336/head
Alex Baker 10 months ago
parent f72dd1fe74
commit c9c984142e

@ -4,6 +4,7 @@ import android.content.Context
import androidx.room.Room import androidx.room.Room
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import androidx.sqlite.SQLiteConnection import androidx.sqlite.SQLiteConnection
import androidx.sqlite.SQLiteDriver
import androidx.sqlite.driver.bundled.BundledSQLiteDriver import androidx.sqlite.driver.bundled.BundledSQLiteDriver
import androidx.sqlite.execSQL import androidx.sqlite.execSQL
import com.todoroo.andlib.utility.AndroidUtilities.atLeastR import com.todoroo.andlib.utility.AndroidUtilities.atLeastR
@ -79,15 +80,16 @@ fun <T : RoomDatabase> RoomDatabase.Builder<T>.setDriver() =
this this
} }
} else { } else {
// need bundled sqlite for window functions val driver = BundledSQLiteDriver() // need bundled sqlite for window functions
this this
.setDriver(BundledSQLiteDriver()) .setDriver(
.setQueryCoroutineContext(Dispatchers.IO) object : SQLiteDriver by driver {
.addCallback(object : RoomDatabase.Callback() { override fun open(fileName: String): SQLiteConnection {
override fun onOpen(connection: SQLiteConnection) { return driver.open(fileName).also {
super.onOpen(connection) it.execSQL("PRAGMA busy_timeout = 60000")
}
connection.execSQL("PRAGMA busy_timeout = 60000") }
} }
}) )
.setQueryCoroutineContext(Dispatchers.IO)
} }

Loading…
Cancel
Save