[chronojump] Fixing loosing of encoder videoURL after recalculate



commit 50d0d600662c41d27050b393f4bfd2816e35259f
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Feb 10 22:11:11 2015 +0100

    Fixing loosing of encoder videoURL after recalculate

 src/sqlite/main.cs       |   16 +++++++++++++++-
 src/sqlite/oldConvert.cs |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 59 insertions(+), 2 deletions(-)
---
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 8039b9c..0ce6121 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -73,7 +73,7 @@ class Sqlite
        /*
         * Important, change this if there's any update to database
         */
-       static string lastChronojumpDatabaseVersion = "1.20";
+       static string lastChronojumpDatabaseVersion = "1.21";
 
        public Sqlite() {
        }
@@ -1751,6 +1751,19 @@ class Sqlite
 
                                currentVersion = "1.20";
                        }
+                       if(currentVersion == "1.20") {
+                               LogB.SQL("Fixing loosing of encoder videoURL after recalculate");
+                               
+                               Sqlite.Open();
+                               
+                               SqliteOldConvert.ConvertAbsolutePathsToRelative(); //videoURLs got absolute 
again
+                               SqliteOldConvert.FixLostVideoURLAfterEncoderRecalculate();
+
+                               SqlitePreferences.Update ("databaseVersion", "1.21", true); 
+                               Sqlite.Close();
+
+                               currentVersion = "1.21";
+                       }
        
                }
 
@@ -1895,6 +1908,7 @@ class Sqlite
                SqliteExecuteAuto.addChronojumpProfileAndBilateral();
                
                //changes [from - to - desc]
+               //1.20 - 1.21 Converted DB to 1.21 Fixing loosing of encoder videoURL after recalculate
                //1.19 - 1.20 Converted DB to 1.20 Preferences: added user email
                //1.18 - 1.19 Converted DB to 1.19 Preferences deleted showHeight, added showStiffness
                //1.17 - 1.18 Converted DB to 1.18 deleted Negative runInterval runs (bug from last version)
diff --git a/src/sqlite/oldConvert.cs b/src/sqlite/oldConvert.cs
index 8b769f9..b8c9788 100644
--- a/src/sqlite/oldConvert.cs
+++ b/src/sqlite/oldConvert.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-2014   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -29,6 +29,49 @@ using Mono.Data.Sqlite;
 class SqliteOldConvert : Sqlite
 {
 
+       /*
+        * DB 1.20 -> 1.21
+        * "Fixing loosing of encoder videoURL after recalculate"
+        * each encoder signal can have saved some encoder curves
+        * both are records on encoder table
+        * connection between them is found in encoderSignalCurve table.
+        * Problem since chronojump 1.4.9 and maybe earlier is on recalculate: videoURL is deleted on signal
+        * but hopefully not in curve
+        * Now this problem has been fixed in new code and it does not get deleted.
+        *
+        * Following  method: is to restore signals that lost their videoURL value
+        */
+
+       public static void FixLostVideoURLAfterEncoderRecalculate()
+       {
+               dbcmd.CommandText = "SELECT eSignal.uniqueID, eCurve.videoURL " + 
+                       "FROM encoder AS eSignal, encoder AS eCurve, encoderSignalCurve " + 
+                       "WHERE eSignal.signalOrCurve = 'signal' AND eCurve.signalOrCurve = 'curve' " + 
+                       "AND eSignal.videoURL = '' AND eCurve.videoURL != '' " + 
+                       "AND encoderSignalCurve.signalID = eSignal.uniqueID " +
+                       "AND encoderSignalCurve.curveID = eCurve.uniqueID";
+
+               LogB.SQL(dbcmd.CommandText.ToString());
+               SqliteDataReader reader = dbcmd.ExecuteReader();
+
+               IDNameList idnamelist = new IDNameList();
+               while(reader.Read()) {
+                       idnamelist.Add(new IDName(
+                                               Convert.ToInt32(reader[0].ToString()), //encoder signal 
uniqueID (this signal has lost his videoURL)
+                                               reader[1].ToString()    //videoURL of encoder curve
+                                          ));
+               }
+               reader.Close();
+
+               foreach(IDName idname in idnamelist.l) 
+               {
+                       dbcmd.CommandText = "UPDATE encoder SET videoURL = '" + idname.Name + "' " + 
+                               "WHERE uniqueID = " + idname.UniqueID.ToString();
+                       LogB.SQL(dbcmd.CommandText.ToString());
+                       dbcmd.ExecuteNonQuery();
+               }
+       }
+       
        //to be easier to move data between computers, absolute paths have to be converted to relative
        //DB 1.11 -> 1.12
        //dbcon is already opened


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