[#1440] Db image malformed while scanning blocks
This commit is contained in:
parent
6a96fa3d78
commit
2c09776f9f
|
@ -5,14 +5,13 @@ package cash.z.ecc.android.sdk.internal.db
|
|||
import android.database.sqlite.SQLiteDatabase
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import androidx.sqlite.db.SupportSQLiteQueryBuilder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import cash.z.ecc.android.sdk.internal.SdkDispatchers
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import java.util.Locale
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
/**
|
||||
* Performs a query on a background thread.
|
||||
* Performs a query on a background thread using the dedicated [SdkDispatchers.DATABASE_IO] dispatcher.
|
||||
*
|
||||
* Note that this method is best for small queries, as Cursor has an in-memory window of cached data. If iterating
|
||||
* through a large number of items that exceeds the window, the Cursor may perform additional IO.
|
||||
|
@ -28,7 +27,6 @@ internal fun <T> SQLiteDatabase.queryAndMap(
|
|||
orderBy: String? = null,
|
||||
limit: String? = null,
|
||||
offset: String? = null,
|
||||
coroutineContext: CoroutineContext = Dispatchers.IO,
|
||||
cursorParser: CursorParser<T>
|
||||
) = flow<T> {
|
||||
// TODO [#703]: Support blobs for argument binding
|
||||
|
@ -64,10 +62,10 @@ internal fun <T> SQLiteDatabase.queryAndMap(
|
|||
emit(cursorParser.newObject(it))
|
||||
}
|
||||
}
|
||||
}.flowOn(coroutineContext)
|
||||
}.flowOn(SdkDispatchers.DATABASE_IO)
|
||||
|
||||
/**
|
||||
* Performs a query on a background thread.
|
||||
* Performs a query on a background thread using the dedicated [SdkDispatchers.DATABASE_IO] dispatcher.
|
||||
*
|
||||
* Note that this method is best for small queries, as Cursor has an in-memory window of cached data. If iterating
|
||||
* through a large number of items that exceeds the window, the Cursor may perform additional IO.
|
||||
|
@ -83,7 +81,6 @@ internal fun <T> SupportSQLiteDatabase.queryAndMap(
|
|||
orderBy: String? = null,
|
||||
limit: String? = null,
|
||||
offset: String? = null,
|
||||
coroutineContext: CoroutineContext = Dispatchers.IO,
|
||||
cursorParser: CursorParser<T>
|
||||
) = flow<T> {
|
||||
val qb =
|
||||
|
@ -111,4 +108,4 @@ internal fun <T> SupportSQLiteDatabase.queryAndMap(
|
|||
emit(cursorParser.newObject(it))
|
||||
}
|
||||
}
|
||||
}.flowOn(coroutineContext)
|
||||
}.flowOn(SdkDispatchers.DATABASE_IO)
|
||||
|
|
|
@ -6,10 +6,8 @@ import cash.z.ecc.android.sdk.internal.model.EncodedTransaction
|
|||
import cash.z.ecc.android.sdk.model.BlockHeight
|
||||
import cash.z.ecc.android.sdk.model.FirstClassByteArray
|
||||
import cash.z.ecc.android.sdk.model.ZcashNetwork
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.Locale
|
||||
|
||||
internal class TransactionTable(
|
||||
|
@ -57,13 +55,11 @@ internal class TransactionTable(
|
|||
}
|
||||
|
||||
suspend fun count() =
|
||||
withContext(Dispatchers.IO) {
|
||||
sqliteDatabase.queryAndMap(
|
||||
table = TransactionTableDefinition.TABLE_NAME,
|
||||
columns = PROJECTION_COUNT,
|
||||
cursorParser = { it.getLong(0) }
|
||||
).first()
|
||||
}
|
||||
sqliteDatabase.queryAndMap(
|
||||
table = TransactionTableDefinition.TABLE_NAME,
|
||||
columns = PROJECTION_COUNT,
|
||||
cursorParser = { it.getLong(0) }
|
||||
).first()
|
||||
|
||||
suspend fun countUnmined() =
|
||||
sqliteDatabase.queryAndMap(
|
||||
|
|
Loading…
Reference in New Issue