Commit 89d9e93

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-07-05 14:03:10
fix true and false in querries (#342)
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 8e625da
Changed files (2)
health_data_store
health_data_store/lib/src/repositories/medicine_repository_impl.dart
@@ -36,7 +36,7 @@ class MedicineRepositoryImpl extends MedicineRepository {
   Future<List<Medicine>> getAll() async {
     final medData = await _db.query('Medicine',
       columns: ['designation', 'defaultDose', 'color'],
-      where: 'removed = false'
+      where: 'removed = 0'
     );
     final meds = <Medicine>[];
     for (final m in medData) {
health_data_store/lib/src/database_manager.dart
@@ -30,6 +30,12 @@ class DatabaseManager {
   static Future<DatabaseManager> load(Database db) async {
     final dbMngr = DatabaseManager._create(db);
 
+    final tables = await dbMngr._db.query('"main".sqlite_master');
+    if (tables.length <= 3) {
+      // DB has just been created, no version yet.
+      await dbMngr._db.setVersion(2);
+    }
+
     if (await dbMngr._db.getVersion() < 3) {
       await dbMngr._setUpTables();
       await dbMngr._db.setVersion(3);
@@ -100,7 +106,7 @@ class DatabaseManager {
   /// - timestamp entries that have no
   Future<void> performCleanup() => _db.transaction((txn) async {
     await txn.rawDelete('DELETE FROM Medicine '
-      'WHERE removed = true '
+      'WHERE removed = 1 '
       'AND medID NOT IN (SELECT medID FROM Intake);',
     );
     await txn.rawDelete('DELETE FROM Timestamps '