Close cursor in retrieveConfigLastUpdateTimestamp (#1692)

This commit is contained in:
SessionHero01 2024-10-14 14:24:48 +11:00 committed by GitHub
parent ed1bddd10b
commit ecfa5d346a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,10 +44,14 @@ class ConfigDatabase(context: Context, helper: SQLCipherOpenHelper): Database(co
}
fun retrieveConfigLastUpdateTimestamp(variant: String, publicKey: String): Long {
val db = readableDatabase
val cursor = db.query(TABLE_NAME, arrayOf(TIMESTAMP), VARIANT_AND_PUBKEY_WHERE, arrayOf(variant, publicKey),null, null, null)
if (cursor == null) return 0
if (!cursor.moveToFirst()) return 0
return (cursor.getLongOrNull(cursor.getColumnIndex(TIMESTAMP)) ?: 0)
return readableDatabase
.query(TABLE_NAME, arrayOf(TIMESTAMP), VARIANT_AND_PUBKEY_WHERE, arrayOf(variant, publicKey), null, null, null)
?.use { cursor ->
if (cursor.moveToFirst()) {
cursor.getLongOrNull(cursor.getColumnIndex(TIMESTAMP))
} else {
null
}
} ?: 0L
}
}