Add extra transaction protections.

This commit is contained in:
Greyson Parrelli 2024-09-12 14:44:09 -04:00 committed by Cody Henthorne
parent 0d37013481
commit 5c6644d1a1

View file

@ -17,12 +17,16 @@ inline fun <T : SupportSQLiteDatabase, R> T.withinTransaction(block: (T) -> R):
beginTransaction() beginTransaction()
try { try {
val toReturn = block(this) val toReturn = block(this)
if (inTransaction()) {
setTransactionSuccessful() setTransactionSuccessful()
}
return toReturn return toReturn
} finally { } finally {
if (inTransaction()) {
endTransaction() endTransaction()
} }
} }
}
fun SupportSQLiteDatabase.getTableRowCount(table: String): Int { fun SupportSQLiteDatabase.getTableRowCount(table: String): Int {
return this.query("SELECT COUNT(*) FROM $table").use { return this.query("SELECT COUNT(*) FROM $table").use {