From fc84245555085ac10fad3d0d5edef215a47301e6 Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Thu, 18 Nov 2021 12:50:10 +0100 Subject: [PATCH] fix: Open database on android --- .../fluffybox_database.dart | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/utils/matrix_sdk_extensions.dart/fluffybox_database.dart b/lib/utils/matrix_sdk_extensions.dart/fluffybox_database.dart index 1cb84351..e5e12c37 100644 --- a/lib/utils/matrix_sdk_extensions.dart/fluffybox_database.dart +++ b/lib/utils/matrix_sdk_extensions.dart/fluffybox_database.dart @@ -60,7 +60,6 @@ class FlutterFluffyBoxDatabase extends FluffyBoxDatabase { await db.execute('PRAGMA page_size = 8192'); await db.execute('PRAGMA cache_size = 16384'); await db.execute('PRAGMA temp_store = MEMORY'); - await db.execute('PRAGMA journal_mode = WAL'); } static Future _openSqlDatabase( @@ -69,24 +68,28 @@ class FlutterFluffyBoxDatabase extends FluffyBoxDatabase { ) async { final path = await _findDatabasePath(client); try { + late final sqflite.Database db; if (Platform.isAndroid || Platform.isIOS) { - final db = await sqflite.openDatabase( + db = await sqflite.openDatabase( path, password: password, onConfigure: _onConfigure, ); return db; + } else { + db = await ffi.databaseFactoryFfi.openDatabase( + path, + options: sqflite.SqlCipherOpenDatabaseOptions( + password: password, + onConfigure: _onConfigure, + ), + ); } - final db = await ffi.databaseFactoryFfi.openDatabase( - path, - options: sqflite.SqlCipherOpenDatabaseOptions( - password: password, - onConfigure: _onConfigure, - ), - ); + await db.execute('PRAGMA journal_mode = WAL'); return db; } catch (_) { File(path).delete(); + Logs().w('Failed to open database. Delete file now...'); rethrow; } }