Skip to content

Commit

Permalink
[#1434] SQLiteCantOpenDatabaseException
Browse files Browse the repository at this point in the history
  • Loading branch information
HonzaR committed Apr 10, 2024
1 parent 4472790 commit e3d3e98
Showing 1 changed file with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cash.z.ecc.android.sdk.internal.db
import android.database.sqlite.SQLiteDatabase
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteQueryBuilder
import cash.z.ecc.android.sdk.internal.Twig
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
Expand Down Expand Up @@ -49,19 +50,25 @@ internal fun <T> SQLiteDatabase.queryAndMap(
String.format(Locale.ROOT, "%s,%s", offset, limit) // NON-NLS
}

query(
table,
columns,
selection,
mappedSelectionArgs,
groupBy,
having,
orderBy,
limitAndOffset
).use {
it.moveToPosition(-1)
while (it.moveToNext()) {
emit(cursorParser.newObject(it))
runCatching {
query(
table,
columns,
selection,
mappedSelectionArgs,
groupBy,
having,
orderBy,
limitAndOffset
)
}.onFailure { sqLiteCantOpenDatabaseException ->
Twig.error(sqLiteCantOpenDatabaseException) { "Failed to open the database" }
}.onSuccess { cursor ->
cursor.use {
it.moveToPosition(-1)
while (it.moveToNext()) {
emit(cursorParser.newObject(it))
}
}
}
}.flowOn(coroutineContext)
Expand Down Expand Up @@ -104,11 +111,17 @@ internal fun <T> SupportSQLiteDatabase.queryAndMap(
}
}
}

query(qb.create()).use {
it.moveToPosition(-1)
while (it.moveToNext()) {
emit(cursorParser.newObject(it))
sqlitecantopendatabaseexception
runCatching {
query(qb.create())
}.onFailure { sqLiteCantOpenDatabaseException ->
Twig.error(sqLiteCantOpenDatabaseException) { "Failed to open the database" }
}.onSuccess { cursor ->
cursor.use {
it.moveToPosition(-1)
while (it.moveToNext()) {
emit(cursorParser.newObject(it))
}
}
}
}.flowOn(coroutineContext)

0 comments on commit e3d3e98

Please sign in to comment.