[chronojump] person with sportID out of sport table will be "undefined sport". Fixes crash maybe caused after imp



commit d379591f00280bbeee9651fbc1c3e9900a43e46c
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Mar 29 16:22:27 2017 +0200

    person with sportID out of sport table will be "undefined sport". Fixes crash maybe caused after import 
database

 src/sqlite/sport.cs |   33 ++++++++++++++++++++++++---------
 1 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/src/sqlite/sport.cs b/src/sqlite/sport.cs
index a01142f..e52f05f 100644
--- a/src/sqlite/sport.cs
+++ b/src/sqlite/sport.cs
@@ -115,17 +115,32 @@ class SqliteSport : Sqlite
 
                SqliteDataReader reader;
                reader = dbcmd.ExecuteReader();
-               reader.Read();
 
-               Sport mySport = new Sport(
-                               uniqueID,
-                               reader[1].ToString(), //name
-                               Util.IntToBool(Convert.ToInt32(reader[2])), //userDefined
-                               Util.IntToBool(Convert.ToInt32(reader[3])), //hasSpeciallities
-                               reader[4].ToString() //graphLink
-                               );
-       
+               Sport mySport = null;
+               while(reader.Read())
+                       mySport = new Sport(
+                                       uniqueID,
+                                       reader[1].ToString(), //name
+                                       Util.IntToBool(Convert.ToInt32(reader[2])), //userDefined
+                                       Util.IntToBool(Convert.ToInt32(reader[3])), //hasSpeciallities
+                                       reader[4].ToString() //graphLink
+                                       );
+
                reader.Close();
+
+               //manage problem if sport was deleted, return 1st sport: "undefined"
+               if(mySport == null)
+               {
+                       //sportsChronojump[0] is "undefined"
+                       string [] sportsFull = sportsChronojump[0].Split(new char[] {':'});
+                       mySport = new Sport(
+                                       1,                                      //uniqueID
+                                       sportsFull[0],                          //name
+                                       false,                                  //userDefined
+                                       Util.StringToBool(sportsFull[2]),       //hasSpeciallities
+                                       sportsFull[3]                           //graphLink
+                                       );
+               }
                
                if(! dbconOpened)
                        Sqlite.Close();


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