[chronojump] Better migration 1.34 -> 1.36
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Better migration 1.34 -> 1.36
- Date: Fri, 19 May 2017 12:29:10 +0000 (UTC)
commit 50c74f4b93c459468449777dbeb0eaf8d000fd96
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri May 19 14:28:33 2017 +0200
Better migration 1.34 -> 1.36
src/encoder.cs | 5 ++++-
src/sqlite/encoderConfiguration.cs | 4 ++++
src/sqlite/main.cs | 22 ++++++++++++++++++++++
3 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/src/encoder.cs b/src/encoder.cs
index 9a15542..d85d395 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -1582,7 +1582,10 @@ public class EncoderConfiguration
this.extraWeightN = Convert.ToInt32(strFull[8]);
this.extraWeightGrams = Convert.ToInt32(strFull[9]);
this.extraWeightLength = Convert.ToDouble(Util.ChangeDecimalSeparator(strFull[10]));
- this.list_d.ReadFromSQL(strFull[11]);
+
+ //check needed when updating DB to 1.36
+ if(strFull.Length == 12)
+ this.list_d.ReadFromSQL(strFull[11]);
}
public enum Outputs { ROPTIONS, RCSV, SQL, SQLECWINCOMPARE}
diff --git a/src/sqlite/encoderConfiguration.cs b/src/sqlite/encoderConfiguration.cs
index 41b7440..67e7398 100644
--- a/src/sqlite/encoderConfiguration.cs
+++ b/src/sqlite/encoderConfiguration.cs
@@ -39,6 +39,10 @@ class SqliteEncoderConfiguration : Sqlite
protected internal static void createTableEncoderConfiguration()
{
+ //only create it, if not exists (could be a problem updating database, specially from 1.34 -
1.36)
+ if(tableExists(true, Constants.EncoderConfigurationTable))
+ return;
+
dbcmd.CommandText =
"CREATE TABLE " + Constants.EncoderConfigurationTable + " ( " +
"uniqueID INTEGER PRIMARY KEY, " +
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 364d6d7..1fda14d 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -2519,6 +2519,28 @@ class Sqlite
creationRate ++;
}
+ protected static bool tableExists(bool dbconOpened, string tableName)
+ {
+ openIfNeeded(dbconOpened);
+
+ dbcmd.CommandText = "SELECT name FROM sqlite_master WHERE type=\"table\" AND name=\"" +
tableName + "\"";
+ LogB.SQL(dbcmd.CommandText.ToString());
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ bool exists = false;
+ if (reader.Read())
+ exists = true;
+ //LogB.SQL(string.Format("name exists = {0}", exists.ToString()));
+
+ reader.Close();
+
+ closeIfNeeded(dbconOpened);
+
+ return exists;
+ }
+
public static bool Exists(bool dbconOpened, string tableName, string findName)
{
if(!dbconOpened)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]