[chronojump/77] sqlite gets converted to 77
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/77] sqlite gets converted to 77
- Date: Thu, 4 Mar 2010 06:54:57 +0000 (UTC)
commit ae6f1f9620562a0a89067b0ec961644887e2e68b
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Mar 4 14:54:19 2010 +0800
sqlite gets converted to 77
src/oldCodeNeedToDBConvert/personSession.cs | 16 ++++
src/oldCodeNeedToDBConvert/sqlite/person.cs | 33 +++++++++
src/oldCodeNeedToDBConvert/sqlite/personSession.cs | 24 ++++++-
src/sqlite/main.cs | 76 +++++++++++++++++++-
src/sqlite/personSession.cs | 1 +
5 files changed, 148 insertions(+), 2 deletions(-)
---
diff --git a/src/oldCodeNeedToDBConvert/personSession.cs b/src/oldCodeNeedToDBConvert/personSession.cs
index d89b159..ecf31c8 100644
--- a/src/oldCodeNeedToDBConvert/personSession.cs
+++ b/src/oldCodeNeedToDBConvert/personSession.cs
@@ -84,6 +84,22 @@ public partial class PersonSessionOld {
//return "[uniqueID: " + uniqueID + "]" + name + ", " + ", " + sex + ", " + dateBorn.ToShortDateString() + ", " + description;
}
+ public int UniqueID {
+ get { return uniqueID; }
+ }
+
+ public int PersonID {
+ get { return personID; }
+ }
+
+ public int SessionID {
+ get { return sessionID; }
+ }
+
+ public double Weight {
+ get { return weight; }
+ }
+
~PersonSessionOld() {}
}
diff --git a/src/oldCodeNeedToDBConvert/sqlite/person.cs b/src/oldCodeNeedToDBConvert/sqlite/person.cs
index 7ecca71..f732ec5 100644
--- a/src/oldCodeNeedToDBConvert/sqlite/person.cs
+++ b/src/oldCodeNeedToDBConvert/sqlite/person.cs
@@ -83,6 +83,39 @@ class SqlitePersonOld : Sqlite
return myReturn;
}
+ //used on Sqlite main convertPersonAndPersonSessionTo77()
+ public ArrayList SelectAllPersons()
+ {
+ dbcmd.CommandText = "SELECT * FROM " + Constants.PersonOldTable + " ORDER BY uniqueID";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ ArrayList myArray = new ArrayList(1);
+
+ while(reader.Read()) {
+ PersonOld p = new PersonOld(
+ Convert.ToInt32(reader[0].ToString()), //uniqueID
+ reader[1].ToString(), //name
+ reader[2].ToString(), //sex
+ UtilDate.FromSql(reader[3].ToString()),//dateBorn
+ Convert.ToDouble(Util.ChangeDecimalSeparator(reader[4].ToString())), //height
+ Convert.ToDouble(Util.ChangeDecimalSeparator(reader[5].ToString())), //weight
+
+ Convert.ToInt32(reader[6].ToString()), //sportID
+ Convert.ToInt32(reader[7].ToString()), //speciallityID
+ Convert.ToInt32(reader[8].ToString()), //practice
+ reader[9].ToString(), //description
+ Convert.ToInt32(reader[10].ToString()), //race
+ Convert.ToInt32(reader[11].ToString()), //countryID
+ Convert.ToInt32(reader[12].ToString()) //serverUniqueID
+ );
+ myArray.Add(p);
+ }
+ reader.Close();
+ return myArray;
+ }
+
/*
from SqlitePersonSessionWeight.DeletePersonFromSessionAndTests()
if person is not in other sessions, delete it from DB
diff --git a/src/oldCodeNeedToDBConvert/sqlite/personSession.cs b/src/oldCodeNeedToDBConvert/sqlite/personSession.cs
index ea21341..9129d50 100644
--- a/src/oldCodeNeedToDBConvert/sqlite/personSession.cs
+++ b/src/oldCodeNeedToDBConvert/sqlite/personSession.cs
@@ -61,7 +61,29 @@ class SqlitePersonSessionOld : Sqlite
dbcon.Close();
return myReturn;
}
-
+
+ //used on Sqlite main convertPersonAndPersonSessionTo77()
+ public ArrayList SelectAllPersonSessionsOfAPerson(int personID)
+ {
+ dbcmd.CommandText = "SELECT * FROM " + Constants.PersonSessionOldWeightTable + " WHERE personID == " + personID + " ORDER BY uniqueID";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ ArrayList myArray = new ArrayList(1);
+ while(reader.Read()) {
+ PersonSessionOld ps = new PersonSessionOld(
+ Convert.ToInt32(reader[0].ToString()), //uniqueID
+ Convert.ToInt32(reader[1].ToString()), //personID
+ Convert.ToInt32(reader[2].ToString()), //sessionID
+ Convert.ToDouble(Util.ChangeDecimalSeparator(reader[3].ToString())) //weight
+ );
+ myArray.Add(ps);
+ }
+ reader.Close();
+ return myArray;
+ }
+
/*
* conversion from database 0.52 to 0.53 (add weight into personSession)
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 0693b22..11eabee 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -72,7 +72,7 @@ class Sqlite
* Important, change this if there's any update to database
* Important2: if database version get numbers higher than 1, check if the comparisons with currentVersion works ok
*/
- static string lastChronojumpDatabaseVersion = "0.76";
+ static string lastChronojumpDatabaseVersion = "0.77";
public Sqlite() {
}
@@ -1011,6 +1011,20 @@ class Sqlite
dbcon.Close();
currentVersion = "0.76";
}
+ if(currentVersion == "0.76") {
+ conversionRateTotal = 3;
+ conversionRate = 1;
+ dbcon.Open();
+
+ convertPersonAndPersonSessionTo77();
+
+ SqlitePreferences.Update ("databaseVersion", "0.77", true);
+ conversionRate++;
+
+ Log.WriteLine("Converted DB to 0.77 (person77, personSession77)");
+ dbcon.Close();
+ currentVersion = "0.77";
+ }
}
//if changes are made here, remember to change also in CreateTables()
@@ -1143,6 +1157,7 @@ class Sqlite
SqliteCountry.initialize();
//changes [from - to - desc]
+ //0.76 - 0.77 Converted DB to 0.77 (person77, personSession77)
//0.75 - 0.76 Converted DB to 0.76 (jump & jumpRj falls as double)
//0.74 - 0.75 Converted DB to 0.75 (person, and personSessionWeight have height and weight as double)
//0.73 - 0.74 Converted DB to 0.74 (All DJ converted to DJna)
@@ -1252,6 +1267,65 @@ class Sqlite
dbcmd.CommandText = "DROP TABLE " + tableName;
dbcmd.ExecuteNonQuery();
}
+
+ protected static void convertPersonAndPersonSessionTo77() {
+ //create person77
+ SqlitePerson sqlitePersonObject = new SqlitePerson();
+ sqlitePersonObject.createTable(Constants.PersonTable);
+
+ //create personSession77
+ SqlitePersonSession sqlitePersonSessionObject = new SqlitePersonSession();
+ sqlitePersonSessionObject.createTable(Constants.PersonSessionTable);
+
+ //select all personOld data
+ SqlitePersonOld sqlitePersonOldObject = new SqlitePersonOld();
+ ArrayList personsOld = sqlitePersonOldObject.SelectAllPersons();
+
+ conversionRateTotal = personsOld.Count;
+ conversionRate = 1;
+ foreach (PersonOld pOld in personsOld) {
+ Person p = new Person(
+ pOld.UniqueID,
+ pOld.Name,
+ pOld.Sex,
+ pOld.DateBorn,
+ pOld.Race,
+ pOld.CountryID,
+ pOld.Description,
+ pOld.ServerUniqueID
+ );
+ p.InsertAtDB(true, Constants.PersonTable);
+
+ //select all personSessionOld data of this person
+ SqlitePersonSessionOld sqlitePersonSessionOldObject = new SqlitePersonSessionOld();
+ ArrayList personSessionsOld = sqlitePersonSessionOldObject.SelectAllPersonSessionsOfAPerson(p.UniqueID);
+ conversionSubRateTotal = personSessionsOld.Count;
+ conversionSubRate = 1;
+ foreach (PersonSessionOld psOld in personSessionsOld) {
+ PersonSession ps = new PersonSession(
+ psOld.UniqueID,
+ psOld.PersonID,
+ psOld.SessionID,
+ pOld.Height,
+ psOld.Weight,
+ pOld.SportID,
+ pOld.SpeciallityID,
+ pOld.Practice,
+ "" //comments
+ );
+ ps.InsertAtDB(true, Constants.PersonSessionTable);
+ conversionSubRate ++;
+ }
+ conversionRate ++;
+ }
+
+ //drop old tables
+ Sqlite.dropTable(Constants.PersonOldTable);
+ Sqlite.dropTable(Constants.PersonSessionOldWeightTable);
+
+ }
+
+
//to convert to sqlite 0.72
protected internal static void datesToYYYYMMDD()
diff --git a/src/sqlite/personSession.cs b/src/sqlite/personSession.cs
index 1bc8921..4018047 100644
--- a/src/sqlite/personSession.cs
+++ b/src/sqlite/personSession.cs
@@ -69,6 +69,7 @@ class SqlitePersonSession : Sqlite
Util.ConvertToPoint(height) + ", " + Util.ConvertToPoint(weight) + ", " +
sportID + ", " + speciallityID + ", " + practice + ", '" +
comments + "', '', '')";
+ Log.WriteLine(dbcmd.CommandText.ToString());
dbcmd.ExecuteNonQuery();
int myReturn = dbcon.LastInsertRowId;
if(!dbconOpened)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]