[chronojump/FS-TFT-Menu] DB:2.38 alter table runInterval, tempRunInterval add photocellStr



commit 5d8536e9459058807bdc4bc69423d1a1a023d79c
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Apr 14 17:34:57 2022 +0200

    DB:2.38 alter table runInterval, tempRunInterval add photocellStr

 src/sqlite/main.cs        | 18 +++++++++++++++++-
 src/sqlite/runInterval.cs | 22 +++++++++++++---------
 2 files changed, 30 insertions(+), 10 deletions(-)
---
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 0860dc3ba..7b20e8e4f 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -131,7 +131,7 @@ class Sqlite
        /*
         * Important, change this if there's any update to database
         */
-       static string lastChronojumpDatabaseVersion = "2.37";
+       static string lastChronojumpDatabaseVersion = "2.38";
 
        public Sqlite()
        {
@@ -3239,6 +3239,21 @@ class Sqlite
 
                                currentVersion = updateVersion("2.37");
                        }
+                       if(currentVersion == "2.37")
+                       {
+                               LogB.SQL("Doing alter table runInterval, tempRunInterval add photocellStr");
+                               try {
+                                       //sqlite does not have drop column
+                                       executeSQL("ALTER TABLE " + Constants.RunIntervalTable + " ADD COLUMN 
photocellStr TEXT;");
+                                       executeSQL("ALTER TABLE " + Constants.TempRunIntervalTable + " ADD 
COLUMN photocellStr TEXT;");
+                               } catch {
+                                       LogB.SQL("Catched at Doing alter table runInterval, tempRunInterval 
add photocellStr.");
+
+                               }
+                               LogB.SQL("Done!");
+
+                               currentVersion = updateVersion("2.38");
+                       }
 
                        /*
                        if(currentVersion == "1.79")
@@ -3460,6 +3475,7 @@ class Sqlite
                //changes [from - to - desc]
 //just testing: 1.79 - 1.80 Converted DB to 1.80 Created table ForceSensorElasticBandGlue and moved 
stiffnessString records there
 
+               //2.37 - 2.38 Converted DB to 2.38 Doing alter table runInterval, tempRunInterval add 
photocellStr
                //2.36 - 2.37 Converted DB to 2.37 Doing ALTER TABLE encoder add repCriteria.
                //2.35 - 2.36 Converted DB to 2.36 Inserted into preferences: 
encoderRepetitionCriteriaGravitatory, encoderRepetitionCriteriaInertial
                //2.34 - 2.35 Converted DB to 2.35 Ensure maxForceRAW is converted to maxForceRaw
diff --git a/src/sqlite/runInterval.cs b/src/sqlite/runInterval.cs
index b5858a10e..b5d2e69a0 100644
--- a/src/sqlite/runInterval.cs
+++ b/src/sqlite/runInterval.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2017   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2022   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -52,11 +52,12 @@ class SqliteRunInterval : SqliteRun
                        "limited TEXT, " +
                        "simulated INT, " +
                        "initialSpeed INT, " +
-                       "datetime TEXT )";
+                       "datetime TEXT, " +
+                       "photocellStr TEXT )";
                dbcmd.ExecuteNonQuery();
        }
 
-       public static int Insert(bool dbconOpened, string tableName, string uniqueID, int personID, int 
sessionID, string type, double distanceTotal, double timeTotal, double distanceInterval, string 
intervalTimesString, double tracks, string description, string limited, int simulated, bool initialSpeed, 
string datetime)
+       public static int Insert(bool dbconOpened, string tableName, string uniqueID, int personID, int 
sessionID, string type, double distanceTotal, double timeTotal, double distanceInterval, string 
intervalTimesString, double tracks, string description, string limited, int simulated, bool initialSpeed, 
string datetime, List<int> photocell_l)
        {
                if(! dbconOpened)
                        Sqlite.Open();
@@ -65,7 +66,7 @@ class SqliteRunInterval : SqliteRun
                        uniqueID = "NULL";
 
                dbcmd.CommandText = "INSERT INTO "+ tableName + 
-                               " (uniqueID, personID, sessionID, type, distanceTotal, timeTotal, 
distanceInterval, intervalTimesString, tracks, description, limited, simulated, initialSpeed, datetime)" +
+                               " (uniqueID, personID, sessionID, type, distanceTotal, timeTotal, 
distanceInterval, intervalTimesString, tracks, description, limited, simulated, initialSpeed, datetime, 
photocellStr)" +
                                "VALUES (" + uniqueID + ", " +
                                personID + ", " + sessionID + ", \"" + type + "\", " +
                                Util.ConvertToPoint(distanceTotal) + ", " + 
@@ -75,7 +76,8 @@ class SqliteRunInterval : SqliteRun
                                Util.ConvertToPoint(tracks) + ", \"" + 
                                description + "\", \"" + limited + "\", " + simulated + ", " +
                                Util.BoolToInt(initialSpeed) + ", \"" +
-                               datetime + "\")";
+                               datetime + "\", \"" +
+                               Util.ListIntToSQLString (photocell_l, ";") + "\")";
                                
                LogB.SQL(dbcmd.CommandText.ToString());
                dbcmd.ExecuteNonQuery();
@@ -130,7 +132,8 @@ class SqliteRunInterval : SqliteRun
                                        reader[11].ToString(),  //limited
                                        Convert.ToInt32(reader[12].ToString()), //simulated
                                        Util.IntToBool(Convert.ToInt32(reader[13])), //initialSpeed
-                                       reader[14].ToString()           //datetime
+                                       reader[14].ToString(),          //datetime
+                                       Util.SQLStringToListInt(reader[15].ToString(), ";")
                                        );
 
                        //runs previous to DB 2.13 have no datetime on run
@@ -204,7 +207,8 @@ class SqliteRunInterval : SqliteRun
                                        reader[11].ToString() + ":" +   //limited
                                        reader[12].ToString() + ":" +   //simulated
                                        Util.IntToBool(Convert.ToInt32(reader[13])) + ":" + //initialSpeed
-                                       reader[14].ToString()           //datetime
+                                       reader[14].ToString() + ":" +           //datetime
+                                       Util.SQLStringToListInt(reader[15].ToString(), ";")
                                        );
                        count ++;
                }
@@ -246,9 +250,9 @@ class SqliteRunInterval : SqliteRun
                reader = dbcmd.ExecuteReader();
                reader.Read();
 
-               RunInterval myRun = new RunInterval(DataReaderToStringArray(reader, 14));
+               RunInterval myRun = new RunInterval(DataReaderToStringArray(reader, 15));
                if(personNameInComment)
-                       myRun.Description = reader[14].ToString(); //person.Name
+                       myRun.Description = reader[15].ToString(); //person.Name
 
                reader.Close();
                if(!dbconOpened)


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