https://kotlinlang.org logo
#android
Title
# android
m

Mark

06/06/2019, 2:48 PM
I’ve been getting a strange intermittent error when executing
CREATE INDEX
SQLite statements in a coroutine (not using Room).
Copy code
SQLiteConnectionPool: The connection pool for database '+path+to+my_db' has been unable to grant a connection to thread 2676 (DefaultDispatcher-worker-8) with flags 0x2 for 12.003 seconds.
    Connections: 0 active, 1 idle, 0 available.
It only ever (not always) happens if I call
yield()
in between each
execSQL
. Is it something to do with SQLite not liking being accessed by different threads within the same transaction (which I’m guessing might happen when using
yield()
)?
a

Adam Powell

06/06/2019, 3:11 PM
Probably. You cannot switch threads when using those APIs
m

Mark

06/06/2019, 3:15 PM
Thanks Adam. I guess there are other (than yield) potential ways the thread might be switched while using coroutines. Would it therefore (in the context of SQLite) be more advisable to write mostly non-suspending functions other than at the highest level?
7 Views