From 36373b7d565acb47d13a3d3dabbceae9dd03405e Mon Sep 17 00:00:00 2001 From: Florent CHAMPIGNY Date: Wed, 19 Nov 2025 11:08:31 +0100 Subject: [PATCH] Update FloconAndroid/flocon/src/androidMain/kotlin/io/github/openflocon/flocon/plugins/database/FloconDatabasePlugin.android.kt Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .../database/FloconDatabasePlugin.android.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/FloconAndroid/flocon/src/androidMain/kotlin/io/github/openflocon/flocon/plugins/database/FloconDatabasePlugin.android.kt b/FloconAndroid/flocon/src/androidMain/kotlin/io/github/openflocon/flocon/plugins/database/FloconDatabasePlugin.android.kt index f1baa77d..b0f6187d 100644 --- a/FloconAndroid/flocon/src/androidMain/kotlin/io/github/openflocon/flocon/plugins/database/FloconDatabasePlugin.android.kt +++ b/FloconAndroid/flocon/src/androidMain/kotlin/io/github/openflocon/flocon/plugins/database/FloconDatabasePlugin.android.kt @@ -278,15 +278,13 @@ private fun getObjectFromColumnIndex(cursor: Cursor, column: Int): String? { private fun getDatabaseVersion( path: String, ): Int { - val db = android.database.sqlite.SQLiteDatabase.openDatabase( + return android.database.sqlite.SQLiteDatabase.openDatabase( path, null, android.database.sqlite.SQLiteDatabase.OPEN_READONLY - ) - val cursor = db.rawQuery("PRAGMA user_version", null) - var version = 0 - if (cursor.moveToFirst()) version = cursor.getInt(0) - cursor.close() - db.close() - return version + ).use { db -> + db.rawQuery("PRAGMA user_version", null).use { cursor -> + if (cursor.moveToFirst()) cursor.getInt(0) else 0 + } + } }