[chronojump] Fixed crash since 1.4.8 on creating multiple persons in blank database. Also could fail before on sa



commit c5f094451d1b933fdaedc7927bac1960884e95c5
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Nov 28 17:00:42 2014 +0100

    Fixed crash since 1.4.8 on creating multiple persons in blank database. Also could fail before on saving 
encoder curves fo the first time

 src/gui/encoder.cs |    8 +++++++-
 src/gui/person.cs  |   24 ++++++++++++++++++++----
 src/sqlite/main.cs |    1 +
 3 files changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 5229393..1525fef 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1697,7 +1697,13 @@ public partial class ChronoJumpWindow
                        desc = "";
 
                        Log.WriteLine(curveStart + "->" + duration);
-                       int curveIDMax = Sqlite.Max(Constants.EncoderTable, "uniqueID", false);
+               
+                       int curveIDMax;
+                       int countCurveIDs = Sqlite.Count(Constants.EncoderTable, false);
+                       if(countCurveIDs == 0)
+                               curveIDMax = 0;
+                       else
+                               curveIDMax = Sqlite.Max(Constants.EncoderTable, "uniqueID", false);
                        
                        //save raw file to hard disk
                        fileSaved = UtilEncoder.EncoderSaveCurve(UtilEncoder.GetEncoderDataTempFileName(), 
diff --git a/src/gui/person.cs b/src/gui/person.cs
index 5a8395c..607bd3e 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -2252,10 +2252,26 @@ public class PersonAddMultipleWindow {
        //all this names doesn't match with other in the database, and the weights are > 0 ( checked in 
checkEntries() )
        void processAllNonBlankRows() 
        {
-               int maxPUniqueID = Sqlite.Max(Constants.PersonTable, "uniqueID", false);
-               int pID = maxPUniqueID + 1;
-               int maxPSUniqueID = Sqlite.Max(Constants.PersonSessionTable, "uniqueID", false);
-               int psID = maxPSUniqueID + 1;
+               int pID;
+               int countPersons = Sqlite.Count(Constants.PersonTable, false);
+               if(countPersons == 0)
+                       pID = 1;
+               else {
+                       //Sqlite.Max will return NULL if there are no values, for this reason we use the 
Sqlite.Count before
+                       int maxPUniqueID = Sqlite.Max(Constants.PersonTable, "uniqueID", false);
+                       pID = maxPUniqueID + 1;
+               }
+
+               int psID;
+               int countPersonSessions = Sqlite.Count(Constants.PersonSessionTable, false);
+               if(countPersonSessions == 0)
+                       psID = 1;
+               else {
+                       //Sqlite.Max will return NULL if there are no values, for this reason we use the 
Sqlite.Count before
+                       int maxPSUniqueID = Sqlite.Max(Constants.PersonSessionTable, "uniqueID", false);
+                       psID = maxPSUniqueID + 1;
+               }
+               
                string sex = "";
                double weight = 0;
                                
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index e7db3d3..54b0537 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -2631,6 +2631,7 @@ Console.WriteLine("5" + tableName);
                reader = dbcmd.ExecuteReader();
                
                int myReturn = 0;
+               //caution because it there are no values, a whiteline or NULL can be returned and can fail in 
this Convert.ToInt32
                if(reader.Read()) 
                        myReturn = Convert.ToInt32(reader[0].ToString());
                reader.Close();


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