[chronojump] Fixed import to import correctly forceSensor files from old versions



commit ab39269797ba2b7f12a4f93f306a92fca9b193cc
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Nov 11 12:38:46 2019 +0100

    Fixed import to import correctly forceSensor files from old versions

 src/forceSensor.cs        |  5 +--
 src/sqlite/forceSensor.cs | 84 ++++++++++++++++++++++++++++++-----------------
 src/sqlite/main.cs        |  4 +--
 3 files changed, 56 insertions(+), 37 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index aa242e0d..46c3758a 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -357,9 +357,7 @@ public class ForceSensorExercise
                        Util.BoolToInt(elastic).ToString();
        }
 
-       /*
-        * is there any need of this?
-        *
+       // to be able to import
        public string ToSQLInsertString_DB_1_68()
        {
                string uniqueIDStr = "NULL";
@@ -371,7 +369,6 @@ public class ForceSensorExercise
                        resistance + "\", " + angleDefault + ", \"" + description + "\", " +
                        Util.BoolToInt(tareBeforeCapture).ToString();
        }
-       */
 
        public bool Changed(ForceSensorExercise newEx)
        {
diff --git a/src/sqlite/forceSensor.cs b/src/sqlite/forceSensor.cs
index df40929c..a1394ace 100644
--- a/src/sqlite/forceSensor.cs
+++ b/src/sqlite/forceSensor.cs
@@ -266,6 +266,11 @@ class SqliteForceSensor : Sqlite
                return array;
        }
 
+       /*
+        * this import converts all the forceSensor files into SQL rows with a column pointing the file
+        * persons have to be recognized/created (if is not possible to get the person then an Unknown person 
is created)
+        * forceSensorExercises created (if is not possible to assign the exercise, or there are no 
exercises, a Unknown exercise is created
+        */
        protected internal static void import_from_1_68_to_1_69() //database is opened
        {
                //LogB.PrintAllThreads = true; //TODO: remove this
@@ -344,8 +349,7 @@ class SqliteForceSensor : Sqlite
                                        {
                                                ForceSensorExercise fse = new ForceSensorExercise (-1, 
Catalog.GetString("Unknown"), 0, "", 0, "", false, false, false);
                                                //note we are on 1_68 so we need this import method
-                                               //unknownExerciseID = 
SqliteForceSensorExercise.InsertAtDB_1_68(true, fse);
-                                               unknownExerciseID = SqliteForceSensorExercise.Insert(true, 
fse);
+                                               unknownExerciseID = 
SqliteForceSensorExerciseImport.InsertAtDB_1_68(true, fse);
                                        }
 
                                        exerciseID = unknownExerciseID;
@@ -359,8 +363,7 @@ class SqliteForceSensor : Sqlite
                                {
                                        ForceSensorExercise fse = new ForceSensorExercise (-1, fslt.Exercise, 
0, "", 0, "", false, false, false);
                                        //note we are on 1_68 so we need this import method
-                                       //unknownExerciseID = SqliteForceSensorExercise.InsertAtDB_1_68(true, 
fse);
-                                       unknownExerciseID = SqliteForceSensorExercise.Insert(true, fse);
+                                       unknownExerciseID = 
SqliteForceSensorExerciseImport.InsertAtDB_1_68(true, fse);
                                }
 
                                //laterality (in English)
@@ -413,7 +416,7 @@ class SqliteForceSensor : Sqlite
 
 class SqliteForceSensorExercise : Sqlite
 {
-       private static string table = Constants.ForceSensorExerciseTable;
+       protected static string table = Constants.ForceSensorExerciseTable;
 
        public SqliteForceSensorExercise() {
        }
@@ -465,32 +468,6 @@ class SqliteForceSensorExercise : Sqlite
                return myLast;
        }
 
-       /*
-        * is there any need of this?
-        *
-       public static int InsertAtDB_1_68 (bool dbconOpened, ForceSensorExercise ex)
-       {
-               if(! dbconOpened)
-                       Sqlite.Open();
-
-               dbcmd.CommandText = "INSERT INTO " + table +
-                               " (uniqueID, name, percentBodyWeight, resistance, angleDefault, " +
-                               " description, tareBeforeCapture)" +
-                               " VALUES (" + ex.ToSQLInsertString_DB_1_68() + ")";
-               LogB.SQL(dbcmd.CommandText.ToString());
-               dbcmd.ExecuteNonQuery();
-
-               string myString = @"select last_insert_rowid()";
-               dbcmd.CommandText = myString;
-               int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since 
`ExecuteScalar` returns an object.
-
-               if(! dbconOpened)
-                       Sqlite.Close();
-
-               return myLast;
-       }
-       */
-
        public static void Update (bool dbconOpened, ForceSensorExercise ex)
        {
                if(! dbconOpened)
@@ -578,6 +555,51 @@ class SqliteForceSensorExercise : Sqlite
 
                return array;
        }
+}
+
+class SqliteForceSensorExerciseImport : SqliteForceSensorExercise
+{
+       public SqliteForceSensorExerciseImport() {
+       }
+
+       ~SqliteForceSensorExerciseImport() {}
+
+       protected internal static void createTable_v_1_58()
+       {
+               dbcmd.CommandText =
+                       "CREATE TABLE " + table + " ( " +
+                       "uniqueID INTEGER PRIMARY KEY, " +
+                       "name TEXT, " +
+                       "percentBodyWeight INT NOT NULL, " +
+                       "resistance TEXT, " +                           //unused
+                       "angleDefault INT, " +
+                       "description TEXT, " +
+                       "tareBeforeCapture INT)";
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+       }
+
+       public static int InsertAtDB_1_68 (bool dbconOpened, ForceSensorExercise ex)
+       {
+               if(! dbconOpened)
+                       Sqlite.Open();
+
+               dbcmd.CommandText = "INSERT INTO " + table +
+                               " (uniqueID, name, percentBodyWeight, resistance, angleDefault, " +
+                               " description, tareBeforeCapture)" +
+                               " VALUES (" + ex.ToSQLInsertString_DB_1_68() + ")";
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               string myString = @"select last_insert_rowid()";
+               dbcmd.CommandText = myString;
+               int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since 
`ExecuteScalar` returns an object.
+
+               if(! dbconOpened)
+                       Sqlite.Close();
+
+               return myLast;
+       }
 
        //database is opened
        protected internal static void import_partially_from_1_73_to_1_74_unify_resistance_and_description()
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index e5c18d93..036eb846 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -2362,7 +2362,7 @@ class Sqlite
                        {
                                LogB.SQL("Created ForceSensorExercise");
 
-                               SqliteForceSensorExercise.createTable(); //now this createTable has the 
tareBeforeCapture column
+                               SqliteForceSensorExerciseImport.createTable_v_1_58(); //now this createTable 
has the tareBeforeCapture column
                                //do not use this because if update fails and is done on different Chronojump 
executions,
                                //we will arrive to 1.66 having  this as false:
                                //createdForceSensorExerciseWith_tareBeforeCapture
@@ -2498,7 +2498,7 @@ class Sqlite
                                        executeSQL("ALTER TABLE " + Constants.ForceSensorExerciseTable + " 
ADD COLUMN forceResultant INT NOT NULL DEFAULT 0;");
                                        executeSQL("ALTER TABLE " + Constants.ForceSensorExerciseTable + " 
ADD COLUMN elastic INT NOT NULL DEFAULT 0;");
 
-                                       
SqliteForceSensorExercise.import_partially_from_1_73_to_1_74_unify_resistance_and_description();
+                                       
SqliteForceSensorExerciseImport.import_partially_from_1_73_to_1_74_unify_resistance_and_description();
                                } catch {
                                        LogB.SQL("Catched. forceResultant or elastic already exists, or at 
unify resitance and desc.");
 


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