[chronojump] 0.95 db 0.83 starting sql encoder



commit f4d96951dc87001cf7228fc15181854d1eca3fbd
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Apr 10 17:54:21 2012 +0200

    0.95 db 0.83 starting sql encoder

 diagrams/sqlite/chronojump_sqlite.dia |  Bin 12611 -> 12855 bytes
 diagrams/sqlite/chronojump_sqlite.png |  Bin 173663 -> 157843 bytes
 encoder/pyserial_pyper.py             |    2 +-
 src/Makefile.am                       |    1 +
 src/constants.cs                      |    1 +
 src/sqlite/encoder.cs                 |   93 +++++++++++++++++++++++++++++++++
 src/sqlite/main.cs                    |   24 +++++++-
 7 files changed, 117 insertions(+), 4 deletions(-)
---
diff --git a/diagrams/sqlite/chronojump_sqlite.dia b/diagrams/sqlite/chronojump_sqlite.dia
index 4b21b52..554b1ac 100644
Binary files a/diagrams/sqlite/chronojump_sqlite.dia and b/diagrams/sqlite/chronojump_sqlite.dia differ
diff --git a/diagrams/sqlite/chronojump_sqlite.png b/diagrams/sqlite/chronojump_sqlite.png
index 50e7381..475d98f 100644
Binary files a/diagrams/sqlite/chronojump_sqlite.png and b/diagrams/sqlite/chronojump_sqlite.png differ
diff --git a/encoder/pyserial_pyper.py b/encoder/pyserial_pyper.py
index d71f335..ceb732b 100644
--- a/encoder/pyserial_pyper.py
+++ b/encoder/pyserial_pyper.py
@@ -19,7 +19,7 @@
 # 
 # encoding=utf-8
 #
-# This program is for reading data form Chronopic.
+# This program is for reading data from Chronopic.
 
 
 
diff --git a/src/Makefile.am b/src/Makefile.am
index e6c1363..25d5dc2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -140,6 +140,7 @@ FILES = \
 	sqlite/main.cs\
  	sqlite/preferences.cs\
  	sqlite/session.cs\
+ 	sqlite/encoder.cs\
  	sqlite/jump.cs\
  	sqlite/jumpRj.cs\
  	sqlite/jumpType.cs\
diff --git a/src/constants.cs b/src/constants.cs
index b97168b..424fb45 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -97,6 +97,7 @@ public class Constants
 	public const string ReactionTimeTable = "reactionTime";
 	public const string MultiChronopicTable = "multiChronopic";
 	public const string TempMultiChronopicTable = "tempMultiChronopic"; //TODO
+	public const string EncoderTable = "encoder";
 
 	//tests types
 	public const string JumpTypeTable = "jumpType";
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
new file mode 100644
index 0000000..e14bb05
--- /dev/null
+++ b/src/sqlite/encoder.cs
@@ -0,0 +1,93 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or   
+ *    (at your option) any later version.
+ *    
+ * ChronoJump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ *  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-2012   Xavier de Blas <xaviblas gmail com> 
+ */
+
+using System;
+using System.Data;
+using System.IO;
+using System.Collections; //ArrayList
+using Mono.Data.Sqlite;
+
+
+class SqliteEncoder : Sqlite
+{
+	public SqliteEncoder() {
+	}
+	
+	~SqliteEncoder() {}
+
+	/*
+	 * create and initialize tables
+	 */
+	
+	protected internal static void createTable()
+	{
+		dbcmd.CommandText = 
+			"CREATE TABLE " + Constants.EncoderTable + " ( " +
+			"uniqueID INTEGER PRIMARY KEY, " +
+			"personID INT, " +
+			"sessionID INT, " +
+			"name TEXT, " +
+			"url TEXT, " +
+			"type TEXT, " +		//"bar" or "jump"
+			"extraWeight TEXT, " +	//string because can contain "33%" or "50Kg"
+			"eccon TEXT, " +	//"c" or "ec"
+			"time INT, " +
+			"minHeight INT, " +
+			"smooth FLOAT, " +  
+			"description TEXT )";
+		dbcmd.ExecuteNonQuery();
+	}
+	
+	
+	/*
+	 * Encoder class methods
+	 */
+	
+	public static int Insert(bool dbconOpened, string tableName, string uniqueID, int personID, int sessionID, string name, string url, string type, string extraWeight, string eccon, int time, int minHeight, float smooth, string description)
+	{
+		if(! dbconOpened)
+			dbcon.Open();
+
+		if(uniqueID == "-1")
+			uniqueID = "NULL";
+
+		dbcmd.CommandText = "INSERT INTO " + tableName +  
+				" (uniqueID, personID, sessionID, name, url, type, extraWeight, econ, time, minHeight, smooth, description)" +
+				" VALUES (" + uniqueID + ", "
+				+ personID + ", " + sessionID + ", '" + name + "', '" + url + "', '" + type + "', '" 
+				+ extraWeight + "', '" + eccon + "', " + time + ", " + minHeight + ", " 
+				+ Util.ConvertToPoint(smooth) + ", '" + description + "')" ;
+		Log.WriteLine(dbcmd.CommandText.ToString());
+		dbcmd.ExecuteNonQuery();
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
+
+		if(! dbconOpened)
+			dbcon.Close();
+
+		return myLast;
+	}
+	
+
+}
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 9212842..76363a3 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.82";
+	static string lastChronojumpDatabaseVersion = "0.83";
 
 	public Sqlite() {
 	}
@@ -1119,6 +1119,19 @@ class Sqlite
 				dbcon.Close();
 				currentVersion = "0.82";
 			}
+			if(currentVersion == "0.82") {
+				dbcon.Open();
+				conversionRateTotal = 2;
+				
+				conversionRate = 1;
+				SqliteEncoder.createTable();
+				conversionRate = 2;
+				Log.WriteLine("Created encoder tables.");
+
+				SqlitePreferences.Update ("databaseVersion", "0.83", true); 
+				dbcon.Close();
+				currentVersion = "0.83";
+			}
 		}
 
 		//if changes are made here, remember to change also in CreateTables()
@@ -1154,7 +1167,7 @@ class Sqlite
 	{
 		dbcon.Open();
 
-		creationTotal = 13;
+		creationTotal = 14;
 		creationRate = 1;
 
 		SqliteServer sqliteServerObject = new SqliteServer();
@@ -1230,6 +1243,10 @@ class Sqlite
 		SqliteMultiChronopic sqliteMultiChronopicObject = new SqliteMultiChronopic();
 		sqliteMultiChronopicObject.createTable(Constants.MultiChronopicTable);
 	
+		//encoder	
+		creationRate ++;
+		SqliteEncoder.createTable();
+
 		//sports
 		creationRate ++;
 		SqliteSport.createTable();
@@ -1237,7 +1254,7 @@ class Sqlite
 		SqliteSpeciallity.createTable();
 		SqliteSpeciallity.initialize();
 		SqliteSpeciallity.InsertUndefined(true);
-
+				
 		creationRate ++;
 		SqlitePersonSession sqlitePersonSessionObject = new SqlitePersonSession();
 		sqlitePersonSessionObject.createTable(Constants.PersonSessionTable);
@@ -1251,6 +1268,7 @@ class Sqlite
 		SqliteCountry.initialize();
 		
 		//changes [from - to - desc]
+		//0.82 - 0.83 Converted DB to 0.83 Created encoder table
 		//0.81 - 0.82 Converted DB to 0.82 Added videoOn 
 		//0.80 - 0.81 Converted DB to 0.81 Added tempRunInterval initial speed
 		//0.79 - 0.80 Converted DB to 0.80 Added run and runInterval initial speed (if not done in 0.56 conversion)



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