[chronojump] Fixed a migration bug from DB <= 1.68 (ForceSensor table) (2 years ago)



commit c1ee1df437a58a4df0f523432d3da665613e2ef3
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Jan 18 16:34:04 2022 +0100

    Fixed a migration bug from DB <= 1.68 (ForceSensor table) (2 years ago)

 src/sqlite/main.cs | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index b80f7ca37..ba8c9855f 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -2971,7 +2971,6 @@ class Sqlite
                                        executeSQL("ALTER TABLE " + Constants.EncoderExerciseTable + " ADD 
COLUMN type TEXT DEFAULT \"ALL\";");
                                } catch {
                                        LogB.SQL("Catched at Doing alter table encoderExercise ADD COLUMN 
type TEXT ...");
-
                                }
                                LogB.SQL("Done!");
 
@@ -3068,8 +3067,12 @@ class Sqlite
                        if(currentVersion == "2.28")
                        {
                                LogB.SQL("ForceSensor ALTER TABLE added maxForceRaw, maxAvgForce1s");
-                               executeSQL("ALTER TABLE " + Constants.ForceSensorTable + " ADD COLUMN 
maxForceRAW FLOAT DEFAULT -1;");
-                               executeSQL("ALTER TABLE " + Constants.ForceSensorTable + " ADD COLUMN 
maxAvgForce1s FLOAT DEFAULT -1;");
+                               try {
+                                       executeSQL("ALTER TABLE " + Constants.ForceSensorTable + " ADD COLUMN 
maxForceRaw FLOAT DEFAULT -1;"); //this should be Raw
+                                       executeSQL("ALTER TABLE " + Constants.ForceSensorTable + " ADD COLUMN 
maxAvgForce1s FLOAT DEFAULT -1;");
+                               } catch {
+                                       LogB.SQL("Catched at Doing ALTER TABLE added maxForceRaw, 
maxAvgForce1s. Probably forceSensorTable has been created with this columns already added.");
+                               }
                                currentVersion = updateVersion("2.29");
                        }
                        if(currentVersion == "2.29")
@@ -3524,6 +3527,12 @@ class Sqlite
 
                return exists;
        }
+       /*
+               TODO: create a columnExists method with sqlite command:
+               SELECT * FROM sqlite_master WHERE type = 'table' AND name = 'forceSensor' AND sql LIKE 
'%maxForceRaw%';
+               can be implemented on the future, previous to any ALTER TABLE ADD COLUMN,
+               but at the moment we are using try{}catch{} blocks and it is working great
+               */
 
        public static bool Exists(bool dbconOpened, string tableName, string findName)
        {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]