[chronojump] Less dbcon open/close on upload session



commit 20150cbdebb9da64b1f9d9701e3e3d9ff53d1f58
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Apr 28 14:58:19 2011 +0200

    Less dbcon open/close on upload session

 src/chronojump.cs            |    4 +-
 src/execute/run.cs           |    2 +-
 src/exportSession.cs         |    2 +-
 src/gui/chronojump.cs        |   50 +++++++++++++++++++++---------------------
 src/gui/jump.cs              |    2 +-
 src/gui/person.cs            |    2 +-
 src/gui/queryServer.cs       |    2 +-
 src/gui/run.cs               |    2 +-
 src/server.cs                |   38 +++++++++++++++++++++----------
 src/sqlite/jump.cs           |   10 ++++++--
 src/sqlite/jumpRj.cs         |    8 ++++--
 src/sqlite/jumpType.cs       |   16 ++++++++-----
 src/sqlite/multiChronopic.cs |    8 ++++--
 src/sqlite/pulse.cs          |    8 ++++--
 src/sqlite/reactionTime.cs   |    8 ++++--
 src/sqlite/run.cs            |    8 ++++--
 src/sqlite/runInterval.cs    |    8 ++++--
 src/sqlite/runType.cs        |   16 ++++++++-----
 src/treeViewRun.cs           |    4 +-
 19 files changed, 118 insertions(+), 80 deletions(-)
---
diff --git a/src/chronojump.cs b/src/chronojump.cs
index c880639..09f537f 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -608,7 +608,7 @@ Console.WriteLine("--6--");
 		int existsTempData = Sqlite.TempDataExists(tableName);
 		if(existsTempData > 0)
 		{
-			JumpRj myJumpRj = SqliteJumpRj.SelectJumpData("tempJumpRj", existsTempData);
+			JumpRj myJumpRj = SqliteJumpRj.SelectJumpData("tempJumpRj", existsTempData, false);
 			try {
 				myJumpRj.InsertAtDB (true, Constants.JumpRjTable);
 			} catch {} //pitty, cannot insert
@@ -621,7 +621,7 @@ Console.WriteLine("--6--");
 		existsTempData = Sqlite.TempDataExists(tableName);
 		if(existsTempData > 0)
 		{
-			RunInterval myRun = SqliteRunInterval.SelectRunData("tempRunInterval", existsTempData);
+			RunInterval myRun = SqliteRunInterval.SelectRunData("tempRunInterval", existsTempData, false);
 			try {
 				myRun.InsertAtDB (true, Constants.RunIntervalTable);
 			} catch {} //pitty, cannot insert
diff --git a/src/execute/run.cs b/src/execute/run.cs
index edbd875..132224f 100644
--- a/src/execute/run.cs
+++ b/src/execute/run.cs
@@ -393,7 +393,7 @@ public class RunIntervalExecute : RunExecute
 		//if distances are variable
 		distancesString = "";
 		if(distanceInterval == -1) {
-			RunType runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(type);
+			RunType runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(type, false);
 			distancesString = runType.DistancesString;
 		}
 
diff --git a/src/exportSession.cs b/src/exportSession.cs
index 83db7b8..1c6bb8a 100644
--- a/src/exportSession.cs
+++ b/src/exportSession.cs
@@ -559,7 +559,7 @@ public class ExportSession
 			string myRunTypeString = myStr[4];
 			string myRunDistanceInterval = myStr[7];
 			if(myRunDistanceInterval == "-1" || myRunDistanceInterval == "-1.0") {
-				myRunType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(myRunTypeString);
+				myRunType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(myRunTypeString, false);
 			}
 			myData.Add (
 					myStr[2] + ":" +    			//personID
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index a3739cc..531fb59 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -906,37 +906,37 @@ public partial class ChronoJumpWindow
 				treeviewPersonsContextMenu(currentPerson);
 			} else if(myTv == treeview_jumps) {
 				if (myTreeViewJumps.EventSelectedID > 0) {
-					Jump myJump = SqliteJump.SelectJumpData( myTreeViewJumps.EventSelectedID );
+					Jump myJump = SqliteJump.SelectJumpData( myTreeViewJumps.EventSelectedID, false );
 					treeviewJumpsContextMenu(myJump);
 				}
 			} else if(myTv == treeview_jumps_rj) {
 				if (myTreeViewJumpsRj.EventSelectedID > 0) {
-					JumpRj myJump = SqliteJumpRj.SelectJumpData( "jumpRj", myTreeViewJumpsRj.EventSelectedID );
+					JumpRj myJump = SqliteJumpRj.SelectJumpData( "jumpRj", myTreeViewJumpsRj.EventSelectedID, false );
 					treeviewJumpsRjContextMenu(myJump);
 				}
 			} else if(myTv == treeview_runs) {
 				if (myTreeViewRuns.EventSelectedID > 0) {
-					Run myRun = SqliteRun.SelectRunData( myTreeViewRuns.EventSelectedID );
+					Run myRun = SqliteRun.SelectRunData( myTreeViewRuns.EventSelectedID, false );
 					treeviewRunsContextMenu(myRun);
 				}
 			} else if(myTv == treeview_runs_interval) {
 				if (myTreeViewRunsInterval.EventSelectedID > 0) {
-					RunInterval myRun = SqliteRunInterval.SelectRunData( Constants.RunIntervalTable, myTreeViewRunsInterval.EventSelectedID );
+					RunInterval myRun = SqliteRunInterval.SelectRunData( Constants.RunIntervalTable, myTreeViewRunsInterval.EventSelectedID, false );
 					treeviewRunsIntervalContextMenu(myRun);
 				}
 			} else if(myTv == treeview_reaction_times) {
 				if (myTreeViewReactionTimes.EventSelectedID > 0) {
-					ReactionTime myRt = SqliteReactionTime.SelectReactionTimeData( myTreeViewReactionTimes.EventSelectedID );
+					ReactionTime myRt = SqliteReactionTime.SelectReactionTimeData( myTreeViewReactionTimes.EventSelectedID, false );
 					treeviewReactionTimesContextMenu(myRt);
 				}
 			} else if(myTv == treeview_pulses) {
 				if (myTreeViewPulses.EventSelectedID > 0) {
-					Pulse myPulse = SqlitePulse.SelectPulseData( myTreeViewPulses.EventSelectedID );
+					Pulse myPulse = SqlitePulse.SelectPulseData( myTreeViewPulses.EventSelectedID, false );
 					treeviewPulsesContextMenu(myPulse);
 				}
 			} else if(myTv == treeview_multi_chronopic) {
 				if (myTreeViewMultiChronopic.EventSelectedID > 0) {
-					MultiChronopic mc = SqliteMultiChronopic.SelectMultiChronopicData( myTreeViewMultiChronopic.EventSelectedID );
+					MultiChronopic mc = SqliteMultiChronopic.SelectMultiChronopicData( myTreeViewMultiChronopic.EventSelectedID, false );
 					treeviewMultiChronopicContextMenu(mc);
 				}
 			} else
@@ -3982,7 +3982,7 @@ Console.WriteLine("X");
 					if(lastRunIsSimple) 
 						PrepareRunSimpleGraph(currentRun.Time, currentRun.Speed);
 					else {
-						RunType runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(currentRunInterval.Type);
+						RunType runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(currentRunInterval.Type, false);
 						double distanceTotal = Util.GetRunITotalDistance(currentRunInterval.DistanceInterval, 
 								runType.DistancesString, currentRunInterval.Tracks);
 
@@ -4045,7 +4045,7 @@ Console.WriteLine("X");
 		//2.- check that this line is a jump and not a person (check also if it's not a individual RJ, the pass the parent RJ)
 		if (myTreeViewJumps.EventSelectedID > 0) {
 			//3.- obtain the data of the selected jump
-			Jump myJump = SqliteJump.SelectJumpData( myTreeViewJumps.EventSelectedID );
+			Jump myJump = SqliteJump.SelectJumpData( myTreeViewJumps.EventSelectedID, false );
 			eventOldPerson = myJump.PersonID;
 		
 			//4.- edit this jump
@@ -4061,7 +4061,7 @@ Console.WriteLine("X");
 		//2.- check that this line is a jump and not a person (check also if it's not a individual RJ, the pass the parent RJ)
 		if (myTreeViewJumpsRj.EventSelectedID > 0) {
 			//3.- obtain the data of the selected jump
-			JumpRj myJump = SqliteJumpRj.SelectJumpData( "jumpRj", myTreeViewJumpsRj.EventSelectedID );
+			JumpRj myJump = SqliteJumpRj.SelectJumpData( "jumpRj", myTreeViewJumpsRj.EventSelectedID, false );
 			eventOldPerson = myJump.PersonID;
 		
 			//4.- edit this jump
@@ -4073,7 +4073,7 @@ Console.WriteLine("X");
 	private void on_edit_selected_jump_accepted (object o, EventArgs args) {
 		Log.WriteLine("edit selected jump accepted");
 	
-		Jump myJump = SqliteJump.SelectJumpData( myTreeViewJumps.EventSelectedID );
+		Jump myJump = SqliteJump.SelectJumpData( myTreeViewJumps.EventSelectedID, false );
 
 		//if person changed, fill treeview again, if not, only update it's line
 		if(eventOldPerson == myJump.PersonID) {
@@ -4096,7 +4096,7 @@ Console.WriteLine("X");
 	private void on_edit_selected_jump_rj_accepted (object o, EventArgs args) {
 		Log.WriteLine("edit selected jump RJ accepted");
 	
-		JumpRj myJump = SqliteJumpRj.SelectJumpData( "jumpRj", myTreeViewJumpsRj.EventSelectedID );
+		JumpRj myJump = SqliteJumpRj.SelectJumpData( "jumpRj", myTreeViewJumpsRj.EventSelectedID, false );
 		
 		//if person changed, fill treeview again, if not, only update it's line
 		if(eventOldPerson == myJump.PersonID) {
@@ -4123,7 +4123,7 @@ Console.WriteLine("X");
 		//2.- check that this line is a jump and not a person (check also if it's not a individual RJ, the pass the parent RJ)
 		if (myTreeViewRuns.EventSelectedID > 0) {
 			//3.- obtain the data of the selected run
-			Run myRun = SqliteRun.SelectRunData( myTreeViewRuns.EventSelectedID );
+			Run myRun = SqliteRun.SelectRunData( myTreeViewRuns.EventSelectedID, false );
 			myRun.MetersSecondsPreferred = metersSecondsPreferred;
 			eventOldPerson = myRun.PersonID;
 		
@@ -4140,7 +4140,7 @@ Console.WriteLine("X");
 		//2.- check that this line is a run and not a person (check also if it's not a individual subrun, the pass the parent run)
 		if (myTreeViewRunsInterval.EventSelectedID > 0) {
 			//3.- obtain the data of the selected run
-			RunInterval myRun = SqliteRunInterval.SelectRunData( Constants.RunIntervalTable, myTreeViewRunsInterval.EventSelectedID );
+			RunInterval myRun = SqliteRunInterval.SelectRunData( Constants.RunIntervalTable, myTreeViewRunsInterval.EventSelectedID, false );
 			eventOldPerson = myRun.PersonID;
 		
 			//4.- edit this run
@@ -4152,7 +4152,7 @@ Console.WriteLine("X");
 	private void on_edit_selected_run_accepted (object o, EventArgs args) {
 		Log.WriteLine("edit selected run accepted");
 		
-		Run myRun = SqliteRun.SelectRunData( myTreeViewRuns.EventSelectedID );
+		Run myRun = SqliteRun.SelectRunData( myTreeViewRuns.EventSelectedID, false );
 		
 		//if person changed, fill treeview again, if not, only update it's line
 		if(eventOldPerson == myRun.PersonID)
@@ -4169,7 +4169,7 @@ Console.WriteLine("X");
 	private void on_edit_selected_run_interval_accepted (object o, EventArgs args) {
 		Log.WriteLine("edit selected run interval accepted");
 		
-		RunInterval myRun = SqliteRunInterval.SelectRunData( Constants.RunIntervalTable, myTreeViewRunsInterval.EventSelectedID );
+		RunInterval myRun = SqliteRunInterval.SelectRunData( Constants.RunIntervalTable, myTreeViewRunsInterval.EventSelectedID, false );
 
 		//if person changed, fill treeview again, if not, only update it's line
 		if(eventOldPerson == myRun.PersonID)
@@ -4190,7 +4190,7 @@ Console.WriteLine("X");
 		//2.- check that this line is a event and not a person
 		if (myTreeViewReactionTimes.EventSelectedID > 0) {
 			//3.- obtain the data of the selected event
-			ReactionTime myRT = SqliteReactionTime.SelectReactionTimeData( myTreeViewReactionTimes.EventSelectedID );
+			ReactionTime myRT = SqliteReactionTime.SelectReactionTimeData( myTreeViewReactionTimes.EventSelectedID, false );
 			eventOldPerson = myRT.PersonID;
 		
 			//4.- edit this event
@@ -4202,7 +4202,7 @@ Console.WriteLine("X");
 	private void on_edit_selected_reaction_time_accepted (object o, EventArgs args) {
 		Log.WriteLine("edit selected reaction time accepted");
 		
-		ReactionTime myRT = SqliteReactionTime.SelectReactionTimeData( myTreeViewReactionTimes.EventSelectedID );
+		ReactionTime myRT = SqliteReactionTime.SelectReactionTimeData( myTreeViewReactionTimes.EventSelectedID, false);
 
 		//if person changed, fill treeview again, if not, only update it's line
 		if(eventOldPerson == myRT.PersonID)
@@ -4220,7 +4220,7 @@ Console.WriteLine("X");
 		//2.- check that this line is a event and not a person
 		if (myTreeViewPulses.EventSelectedID > 0) {
 			//3.- obtain the data of the selected event
-			Pulse myPulse = SqlitePulse.SelectPulseData( myTreeViewPulses.EventSelectedID );
+			Pulse myPulse = SqlitePulse.SelectPulseData( myTreeViewPulses.EventSelectedID, false );
 			eventOldPerson = myPulse.PersonID;
 		
 			//4.- edit this event
@@ -4232,7 +4232,7 @@ Console.WriteLine("X");
 	private void on_edit_selected_pulse_accepted (object o, EventArgs args) {
 		Log.WriteLine("edit selected pulse accepted");
 		
-		Pulse myPulse = SqlitePulse.SelectPulseData( myTreeViewPulses.EventSelectedID );
+		Pulse myPulse = SqlitePulse.SelectPulseData( myTreeViewPulses.EventSelectedID, false );
 
 		//if person changed, fill treeview again, if not, only update it's line
 		if(eventOldPerson == myPulse.PersonID)
@@ -4250,7 +4250,7 @@ Console.WriteLine("X");
 		//2.- check that this line is a jump and not a person (check also if it's not a individual RJ, the pass the parent RJ)
 		if (myTreeViewMultiChronopic.EventSelectedID > 0) {
 			//3.- obtain the data of the selected test
-			MultiChronopic mc = SqliteMultiChronopic.SelectMultiChronopicData( myTreeViewMultiChronopic.EventSelectedID );
+			MultiChronopic mc = SqliteMultiChronopic.SelectMultiChronopicData( myTreeViewMultiChronopic.EventSelectedID, false );
 			eventOldPerson = mc.PersonID;
 		
 			//4.- edit this jump
@@ -4262,7 +4262,7 @@ Console.WriteLine("X");
 	private void on_edit_selected_multi_chronopic_accepted (object o, EventArgs args) {
 		Log.WriteLine("edit selected multi chronopic accepted");
 	
-		MultiChronopic mc = SqliteMultiChronopic.SelectMultiChronopicData( myTreeViewMultiChronopic.EventSelectedID );
+		MultiChronopic mc = SqliteMultiChronopic.SelectMultiChronopicData( myTreeViewMultiChronopic.EventSelectedID, false );
 		
 		//if person changed, fill treeview again, if not, only update it's line
 		if(eventOldPerson == mc.PersonID) 
@@ -4830,7 +4830,7 @@ Console.WriteLine("X");
 		//2.- check that this line is a jump and not a person (check also if it's not a individual RJ, the pass the parent RJ)
 		if (myTreeViewJumpsRj.EventSelectedID > 0) {
 			//3.- obtain the data of the selected jump
-			JumpRj myJump = SqliteJumpRj.SelectJumpData( "jumpRj", myTreeViewJumpsRj.EventSelectedID );
+			JumpRj myJump = SqliteJumpRj.SelectJumpData( "jumpRj", myTreeViewJumpsRj.EventSelectedID, false );
 		
 			//4.- edit this jump
 			repairJumpRjWin = RepairJumpRjWindow.Show(app1, myJump, prefsDigitsNumber);
@@ -4857,7 +4857,7 @@ Console.WriteLine("X");
 		//(check also if it's not a individual run interval, then pass the parent run interval)
 		if (myTreeViewRunsInterval.EventSelectedID > 0) {
 			//3.- obtain the data of the selected run
-			RunInterval myRun = SqliteRunInterval.SelectRunData( Constants.RunIntervalTable, myTreeViewRunsInterval.EventSelectedID );
+			RunInterval myRun = SqliteRunInterval.SelectRunData( Constants.RunIntervalTable, myTreeViewRunsInterval.EventSelectedID, false );
 		
 			//4.- edit this run
 			repairRunIntervalWin = RepairRunIntervalWindow.Show(app1, myRun, prefsDigitsNumber);
@@ -4884,7 +4884,7 @@ Console.WriteLine("X");
 		//(check also if it's not a individual pulse, then pass the parent pulse)
 		if (myTreeViewPulses.EventSelectedID > 0) {
 			//3.- obtain the data of the selected pulse
-			Pulse myPulse = SqlitePulse.SelectPulseData( myTreeViewPulses.EventSelectedID );
+			Pulse myPulse = SqlitePulse.SelectPulseData( myTreeViewPulses.EventSelectedID, false );
 		
 			//4.- edit this pulse
 			repairPulseWin = RepairPulseWindow.Show(app1, myPulse, prefsDigitsNumber);
diff --git a/src/gui/jump.cs b/src/gui/jump.cs
index 7e706ec..f84a691 100644
--- a/src/gui/jump.cs
+++ b/src/gui/jump.cs
@@ -434,7 +434,7 @@ public class RepairJumpRjWindow
 		label_header.Text = string.Format(Catalog.GetString("Use this window to repair this test.\nDouble clic any cell to edit it (decimal separator: '{0}')"), localeInfo.NumberDecimalSeparator);
 	
 		
-		jumpType = SqliteJumpType.SelectAndReturnJumpRjType(myJump.Type);
+		jumpType = SqliteJumpType.SelectAndReturnJumpRjType(myJump.Type, false);
 		
 		TextBuffer tb = new TextBuffer (new TextTagTable());
 		tb.Text = createTextForTextView(jumpType);
diff --git a/src/gui/person.cs b/src/gui/person.cs
index 7e15f40..8f977b4 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -1625,7 +1625,7 @@ public class PersonAddModifyWindow
 		string [] myMargarias = SqliteRun.SelectRuns(currentSession.UniqueID, currentPerson.UniqueID, "Margaria");
 		foreach(string myStr in myMargarias) {
 			string [] margaria = myStr.Split(new char[] {':'});
-			Run mRun = SqliteRun.SelectRunData(Convert.ToInt32(margaria[1]));
+			Run mRun = SqliteRun.SelectRunData(Convert.ToInt32(margaria[1]), false);
 			double distanceMeters = mRun.Distance / 1000;
 			mRun.Description = "P = " + Util.TrimDecimals ( (weight * 9.8 * distanceMeters / mRun.Time).ToString(), pDN) + " (Watts)";
 			SqliteRun.Update(mRun.UniqueID, mRun.Type, mRun.Distance.ToString(), mRun.Time.ToString(), mRun.PersonID, mRun.Description);
diff --git a/src/gui/queryServer.cs b/src/gui/queryServer.cs
index 61ff250..04e1328 100644
--- a/src/gui/queryServer.cs
+++ b/src/gui/queryServer.cs
@@ -419,7 +419,7 @@ public class QueryServerWindow
 		if (UtilGtk.ComboGetActive(combo_test_types) == Catalog.GetString(Constants.UndefinedDefault)) 
 			UtilGtk.ComboUpdate(combo_variables, Util.StringToStringArray(Constants.UndefinedDefault), "");
 		else if (UtilGtk.ComboGetActive(combo_test_types) == Catalog.GetString(Constants.JumpSimpleName)) {
-			JumpType jt = SqliteJumpType.SelectAndReturnJumpType(UtilGtk.ComboGetActive(combo_tests));
+			JumpType jt = SqliteJumpType.SelectAndReturnJumpType(UtilGtk.ComboGetActive(combo_tests), false);
 			if(jt.StartIn)
 				UtilGtk.ComboUpdate(combo_variables, variablesJumpSimple, "");
 			else
diff --git a/src/gui/run.cs b/src/gui/run.cs
index 55527a0..3aa5c51 100644
--- a/src/gui/run.cs
+++ b/src/gui/run.cs
@@ -599,7 +599,7 @@ public class RepairRunIntervalWindow
 		label_header.Text = string.Format(Catalog.GetString("Use this window to repair this test.\nDouble clic any cell to edit it (decimal separator: '{0}')"), localeInfo.NumberDecimalSeparator);
 	
 		
-		type = SqliteRunIntervalType.SelectAndReturnRunIntervalType(myRun.Type);
+		type = SqliteRunIntervalType.SelectAndReturnRunIntervalType(myRun.Type, false);
 		
 		TextBuffer tb = new TextBuffer (new TextTagTable());
 		tb.Text = createTextForTextView(type);
diff --git a/src/server.cs b/src/server.cs
index f591337..6687701 100644
--- a/src/server.cs
+++ b/src/server.cs
@@ -253,10 +253,11 @@ public class Server
 				int countS = 0;					
 
 				string [] jumps = SqliteJump.SelectJumps(currentSession.UniqueID, person.UniqueID, "", "");
+				Sqlite.Open();
 				foreach(string myJump in jumps) {
 					string [] js = myJump.Split(new char[] {':'});
 					//select jump
-					Jump test = SqliteJump.SelectJumpData(Convert.ToInt32(js[1])); //uniqueID
+					Jump test = SqliteJump.SelectJumpData(Convert.ToInt32(js[1]), true); //uniqueID
 					//fix it to server person, session keys
 					test.PersonID = person.ServerUniqueID;
 					test.SessionID = currentSession.ServerUniqueID;
@@ -267,7 +268,7 @@ public class Server
 					if(test.Simulated == 0) {
 						//upload jumpType if is user defined and doesn't exists in server database
 						//JumpType type = new JumpType(test.Type);
-						JumpType type = SqliteJumpType.SelectAndReturnJumpType(test.Type);
+						JumpType type = SqliteJumpType.SelectAndReturnJumpType(test.Type, true);
 						if( ! type.IsPredefined) {
 							//Console.WriteLine("USER DEFINED TEST: " + test.Type);
 							//
@@ -308,6 +309,7 @@ public class Server
 					else //SIMULATED
 						countS ++;
 				}
+				Sqlite.Close();
 
 				//other thread updates the gui:
 				sessionUploadPersonData.jumpsU = countU;
@@ -320,16 +322,17 @@ public class Server
 				countS = 0;					
 
 				string [] jumpsRj = SqliteJumpRj.SelectJumps(currentSession.UniqueID, person.UniqueID, "", "");
+				Sqlite.Open();
 				foreach(string myJump in jumpsRj) {
 					string [] js = myJump.Split(new char[] {':'});
 					//select jump
-					JumpRj test = SqliteJumpRj.SelectJumpData(Constants.JumpRjTable, Convert.ToInt32(js[1])); //uniqueID
+					JumpRj test = SqliteJumpRj.SelectJumpData(Constants.JumpRjTable, Convert.ToInt32(js[1]), true); //uniqueID
 					//fix it to server person, session keys
 					test.PersonID = person.ServerUniqueID;
 					test.SessionID = currentSession.ServerUniqueID;
 					
 					if(test.Simulated == 0) {
-						JumpType type = SqliteJumpType.SelectAndReturnJumpRjType(test.Type);
+						JumpType type = SqliteJumpType.SelectAndReturnJumpRjType(test.Type, true);
 						if( ! type.IsPredefined) {
 							string insertedType = myServer.UploadJumpRjType(type, evalSID);
 							if(insertedType != "-1") {
@@ -350,6 +353,7 @@ public class Server
 					else //SIMULATED
 						countS ++;
 				}
+				Sqlite.Close();
 
 				//other thread updates the gui:
 				sessionUploadPersonData.jumpsRjU = countU;
@@ -362,16 +366,17 @@ public class Server
 				countS = 0;					
 
 				string [] runs = SqliteRun.SelectRuns(currentSession.UniqueID, person.UniqueID, "");
+				Sqlite.Open();
 				foreach(string myRun in runs) {
 					string [] js = myRun.Split(new char[] {':'});
 					//select run
-					Run test = SqliteRun.SelectRunData(Convert.ToInt32(js[1])); //uniqueID
+					Run test = SqliteRun.SelectRunData(Convert.ToInt32(js[1]), true); //uniqueID
 					//fix it to server person, session keys
 					test.PersonID = person.ServerUniqueID;
 					test.SessionID = currentSession.ServerUniqueID;
 
 					if(test.Simulated == 0) {
-						RunType type = SqliteRunType.SelectAndReturnRunType(test.Type);
+						RunType type = SqliteRunType.SelectAndReturnRunType(test.Type, true);
 						if( ! type.IsPredefined) {
 							string insertedType = myServer.UploadRunType(type, evalSID);
 							if(insertedType != "-1") {
@@ -392,6 +397,7 @@ public class Server
 					else //SIMULATED
 						countS ++;
 				}
+				Sqlite.Close();
 
 				//other thread updates the gui:
 				sessionUploadPersonData.runsU = countU;
@@ -404,16 +410,17 @@ public class Server
 				countS = 0;					
 
 				string [] runsI = SqliteRunInterval.SelectRuns(currentSession.UniqueID, person.UniqueID, "");
+				Sqlite.Open();
 				foreach(string myRun in runsI) {
 					string [] js = myRun.Split(new char[] {':'});
 					//select run
-					RunInterval test = SqliteRunInterval.SelectRunData(Constants.RunIntervalTable, Convert.ToInt32(js[1])); //uniqueID
+					RunInterval test = SqliteRunInterval.SelectRunData(Constants.RunIntervalTable, Convert.ToInt32(js[1]), true); //uniqueID
 					//fix it to server person, session keys
 					test.PersonID = person.ServerUniqueID;
 					test.SessionID = currentSession.ServerUniqueID;
 					
 					if(test.Simulated == 0) {
-						RunType type = SqliteRunIntervalType.SelectAndReturnRunIntervalType(test.Type);
+						RunType type = SqliteRunIntervalType.SelectAndReturnRunIntervalType(test.Type, true);
 						if( ! type.IsPredefined) {
 							string insertedType = myServer.UploadRunIntervalType(type, evalSID);
 							if(insertedType != "-1") {
@@ -433,6 +440,7 @@ public class Server
 					else //SIMULATED
 						countS ++;
 				}
+				Sqlite.Close();
 
 				//other thread updates the gui:
 				sessionUploadPersonData.runsIU = countU;
@@ -445,10 +453,11 @@ public class Server
 				countS = 0;					
 
 				string [] rts = SqliteReactionTime.SelectReactionTimes(currentSession.UniqueID, person.UniqueID);
+				Sqlite.Open();
 				foreach(string myRt in rts) {
 					string [] js = myRt.Split(new char[] {':'});
 					//select rt
-					ReactionTime test = SqliteReactionTime.SelectReactionTimeData(Convert.ToInt32(js[1])); //uniqueID
+					ReactionTime test = SqliteReactionTime.SelectReactionTimeData(Convert.ToInt32(js[1]), true); //uniqueID
 					//fix it to server person, session keys
 					test.PersonID = person.ServerUniqueID;
 					test.SessionID = currentSession.ServerUniqueID;
@@ -462,6 +471,7 @@ public class Server
 					else //SIMULATED
 						countS ++;
 				}
+				Sqlite.Close();
 
 				//other thread updates the gui:
 				sessionUploadPersonData.rtsU = countU;
@@ -474,10 +484,11 @@ public class Server
 				countS = 0;					
 
 				string [] pulses = SqlitePulse.SelectPulses(currentSession.UniqueID, person.UniqueID);
+				Sqlite.Open();
 				foreach(string myPulse in pulses) {
 					string [] js = myPulse.Split(new char[] {':'});
 					//select pulse
-					Pulse test = SqlitePulse.SelectPulseData(Convert.ToInt32(js[1])); //uniqueID
+					Pulse test = SqlitePulse.SelectPulseData(Convert.ToInt32(js[1]), true); //uniqueID
 					//fix it to server person, session keys
 					test.PersonID = person.ServerUniqueID;
 					test.SessionID = currentSession.ServerUniqueID;
@@ -491,6 +502,7 @@ public class Server
 					else //SIMULATED
 						countS ++;
 				}
+				Sqlite.Close();
 
 				//other thread updates the gui:
 				sessionUploadPersonData.pulsesU = countU;
@@ -503,10 +515,11 @@ public class Server
 				countS = 0;					
 
 				string [] mcs = SqliteMultiChronopic.SelectTests(currentSession.UniqueID, person.UniqueID);
+				Sqlite.Open();
 				foreach(string mc in mcs) {
 					string [] js = mc.Split(new char[] {':'});
 					//select mc
-					MultiChronopic test = SqliteMultiChronopic.SelectMultiChronopicData(Convert.ToInt32(js[1])); //uniqueID
+					MultiChronopic test = SqliteMultiChronopic.SelectMultiChronopicData(Convert.ToInt32(js[1]), true); //uniqueID
 					//fix it to server person, session keys
 					test.PersonID = person.ServerUniqueID;
 					test.SessionID = currentSession.ServerUniqueID;
@@ -520,6 +533,7 @@ public class Server
 					else //SIMULATED
 						countS ++;
 				}
+				Sqlite.Close();
 
 				//other thread updates the gui:
 				sessionUploadPersonData.mcsU = countU;
@@ -619,7 +633,7 @@ public class Server
 			
 			//update test (simulated) on client database
 			myTest.Simulated = idAtServer;
-			SqliteEvent.UpdateSimulated(false, tableName, myTest.UniqueID, idAtServer);
+			SqliteEvent.UpdateSimulated(true, tableName, myTest.UniqueID, idAtServer);
 			
 			uCode = Constants.UploadCodes.OK;
 		}
diff --git a/src/sqlite/jump.cs b/src/sqlite/jump.cs
index fd9a211..b7ec0e2 100644
--- a/src/sqlite/jump.cs
+++ b/src/sqlite/jump.cs
@@ -173,9 +173,10 @@ class SqliteJump : Sqlite
 		return myJumps;
 	}
 
-	public static Jump SelectJumpData(int uniqueID)
+	public static Jump SelectJumpData(int uniqueID, bool dbconOpened)
 	{
-		dbcon.Open();
+		if(!dbconOpened)
+			dbcon.Open();
 
 		dbcmd.CommandText = "SELECT * FROM jump WHERE uniqueID == " + uniqueID;
 		
@@ -189,7 +190,10 @@ class SqliteJump : Sqlite
 		Jump myJump = new Jump(DataReaderToStringArray(reader, 11));
 	
 		reader.Close();
-		dbcon.Close();
+		
+		if(!dbconOpened)
+			dbcon.Close();
+
 		return myJump;
 	}
 		
diff --git a/src/sqlite/jumpRj.cs b/src/sqlite/jumpRj.cs
index 2f56b9d..1603307 100644
--- a/src/sqlite/jumpRj.cs
+++ b/src/sqlite/jumpRj.cs
@@ -172,11 +172,12 @@ class SqliteJumpRj : SqliteJump
 		return myJumps;
 	}
 
-	public static JumpRj SelectJumpData(string tableName, int uniqueID)
+	public static JumpRj SelectJumpData(string tableName, int uniqueID, bool dbconOpened)
 	{
 		//tableName is jumpRj or tempJumpRj
 
-		dbcon.Open();
+		if(!dbconOpened)
+			dbcon.Open();
 
 		dbcmd.CommandText = "SELECT * FROM " + tableName + " WHERE uniqueID == " + uniqueID;
 		
@@ -190,7 +191,8 @@ class SqliteJumpRj : SqliteJump
 		JumpRj myJump = new JumpRj(DataReaderToStringArray(reader, 18));
 
 		reader.Close();
-		dbcon.Close();
+		if(!dbconOpened)
+			dbcon.Close();
 		return myJump;
 	}
 	
diff --git a/src/sqlite/jumpType.cs b/src/sqlite/jumpType.cs
index f43bdf8..7e1e90f 100644
--- a/src/sqlite/jumpType.cs
+++ b/src/sqlite/jumpType.cs
@@ -306,9 +306,10 @@ class SqliteJumpType : Sqlite
 		return myTypes;
 	}
 	
-	public static JumpType SelectAndReturnJumpType(string typeName) 
+	public static JumpType SelectAndReturnJumpType(string typeName, bool dbconOpened) 
 	{
-		dbcon.Open();
+		if(!dbconOpened)
+			dbcon.Open();
 		dbcmd.CommandText = "SELECT * " +
 			" FROM " + Constants.JumpTypeTable + " " +
 			" WHERE name  = '" + typeName +
@@ -331,14 +332,16 @@ class SqliteJumpType : Sqlite
 		myJumpType.IsPredefined = myJumpType.FindIfIsPredefined();
 
 		reader.Close();
-		dbcon.Close();
+		if(!dbconOpened)
+			dbcon.Close();
 
 		return myJumpType;
 	}
 
-	public static JumpType SelectAndReturnJumpRjType(string typeName) 
+	public static JumpType SelectAndReturnJumpRjType(string typeName, bool dbconOpened) 
 	{
-		dbcon.Open();
+		if(!dbconOpened)
+			dbcon.Open();
 		dbcmd.CommandText = "SELECT * " +
 			" FROM " + Constants.JumpRjTypeTable + " " +
 			" WHERE name  = '" + typeName +
@@ -372,7 +375,8 @@ class SqliteJumpType : Sqlite
 		myJumpType.IsPredefined = myJumpType.FindIfIsPredefined();
 
 		reader.Close();
-		dbcon.Close();
+		if(!dbconOpened)
+			dbcon.Close();
 
 		return myJumpType;
 	}
diff --git a/src/sqlite/multiChronopic.cs b/src/sqlite/multiChronopic.cs
index 2262f80..a56055c 100644
--- a/src/sqlite/multiChronopic.cs
+++ b/src/sqlite/multiChronopic.cs
@@ -179,9 +179,10 @@ class SqliteMultiChronopic : Sqlite
 		return myEvents;
 	}
 
-	public static MultiChronopic SelectMultiChronopicData(int uniqueID)
+	public static MultiChronopic SelectMultiChronopicData(int uniqueID, bool dbconOpened)
 	{
-		dbcon.Open();
+		if(!dbconOpened)
+			dbcon.Open();
 
 		dbcmd.CommandText = "SELECT * FROM " + Constants.MultiChronopicTable + " WHERE uniqueID == " + uniqueID;
 		
@@ -196,7 +197,8 @@ class SqliteMultiChronopic : Sqlite
 		MultiChronopic mc = new MultiChronopic(DataReaderToStringArray(reader, 19));
 	
 		reader.Close();
-		dbcon.Close();
+		if(!dbconOpened)
+			dbcon.Close();
 		return mc;
 	}
 
diff --git a/src/sqlite/pulse.cs b/src/sqlite/pulse.cs
index 6824501..c1b881b 100644
--- a/src/sqlite/pulse.cs
+++ b/src/sqlite/pulse.cs
@@ -141,9 +141,10 @@ class SqlitePulse : Sqlite
 		return myPulses;
 	}
 
-	public static Pulse SelectPulseData(int uniqueID)
+	public static Pulse SelectPulseData(int uniqueID, bool dbconOpened)
 	{
-		dbcon.Open();
+		if(!dbconOpened)
+			dbcon.Open();
 
 		dbcmd.CommandText = "SELECT * FROM " + Constants.PulseTable + " WHERE uniqueID == " + uniqueID;
 		
@@ -157,7 +158,8 @@ class SqlitePulse : Sqlite
 		Pulse myPulse = new Pulse(DataReaderToStringArray(reader, 9));
 
 		reader.Close();
-		dbcon.Close();
+		if(!dbconOpened)
+			dbcon.Close();
 		return myPulse;
 	}
 
diff --git a/src/sqlite/reactionTime.cs b/src/sqlite/reactionTime.cs
index ff88797..a2374c7 100644
--- a/src/sqlite/reactionTime.cs
+++ b/src/sqlite/reactionTime.cs
@@ -136,9 +136,10 @@ class SqliteReactionTime : Sqlite
 		return myEvents;
 	}
 
-	public static ReactionTime SelectReactionTimeData(int uniqueID)
+	public static ReactionTime SelectReactionTimeData(int uniqueID, bool dbconOpened)
 	{
-		dbcon.Open();
+		if(!dbconOpened)
+			dbcon.Open();
 
 		dbcmd.CommandText = "SELECT * FROM " + Constants.ReactionTimeTable + " WHERE uniqueID == " + uniqueID;
 		
@@ -153,7 +154,8 @@ class SqliteReactionTime : Sqlite
 		ReactionTime myRT = new ReactionTime(DataReaderToStringArray(reader, 7));
 	
 		reader.Close();
-		dbcon.Close();
+		if(!dbconOpened)
+			dbcon.Close();
 		return myRT;
 	}
 		
diff --git a/src/sqlite/run.cs b/src/sqlite/run.cs
index d8ae6cf..d78539a 100644
--- a/src/sqlite/run.cs
+++ b/src/sqlite/run.cs
@@ -152,9 +152,10 @@ class SqliteRun : Sqlite
 		return myRuns;
 	}
 
-	public static Run SelectRunData(int uniqueID)
+	public static Run SelectRunData(int uniqueID, bool dbconOpened)
 	{
-		dbcon.Open();
+		if(!dbconOpened)
+			dbcon.Open();
 
 		dbcmd.CommandText = "SELECT * FROM " + Constants.RunTable + " WHERE uniqueID == " + uniqueID;
 		
@@ -169,7 +170,8 @@ class SqliteRun : Sqlite
 		Run myRun = new Run(DataReaderToStringArray(reader, 9));
 	
 		reader.Close();
-		dbcon.Close();
+		if(!dbconOpened)
+			dbcon.Close();
 		return myRun;
 	}
 		
diff --git a/src/sqlite/runInterval.cs b/src/sqlite/runInterval.cs
index 70891e0..096bf7c 100644
--- a/src/sqlite/runInterval.cs
+++ b/src/sqlite/runInterval.cs
@@ -156,11 +156,12 @@ class SqliteRunInterval : SqliteRun
 		return myRuns;
 	}
 
-	public static RunInterval SelectRunData(string tableName, int uniqueID)
+	public static RunInterval SelectRunData(string tableName, int uniqueID, bool dbconOpened)
 	{
 		//tableName can be runInterval or tempRunInterval
 
-		dbcon.Open();
+		if(!dbconOpened)
+			dbcon.Open();
 
 		dbcmd.CommandText = "SELECT * FROM " + tableName + " WHERE uniqueID == " + uniqueID;
 		
@@ -174,7 +175,8 @@ class SqliteRunInterval : SqliteRun
 		RunInterval myRun = new RunInterval(DataReaderToStringArray(reader, 13));
 
 		reader.Close();
-		dbcon.Close();
+		if(!dbconOpened)
+			dbcon.Close();
 		return myRun;
 	}
 
diff --git a/src/sqlite/runType.cs b/src/sqlite/runType.cs
index 2d116d2..92bb3ca 100644
--- a/src/sqlite/runType.cs
+++ b/src/sqlite/runType.cs
@@ -126,9 +126,10 @@ class SqliteRunType : Sqlite
 		return myLast;
 	}
 	
-	public static RunType SelectAndReturnRunType(string typeName) 
+	public static RunType SelectAndReturnRunType(string typeName, bool dbconOpened) 
 	{
-		dbcon.Open();
+		if(!dbconOpened)
+			dbcon.Open();
 		dbcmd.CommandText = "SELECT * " +
 			" FROM " + Constants.RunTypeTable +
 			" WHERE name  = '" + typeName +
@@ -151,7 +152,8 @@ class SqliteRunType : Sqlite
 		myRunType.IsPredefined = myRunType.FindIfIsPredefined();
 
 		reader.Close();
-		dbcon.Close();
+		if(!dbconOpened)
+			dbcon.Close();
 
 		return myRunType;
 	}
@@ -426,9 +428,10 @@ class SqliteRunIntervalType : SqliteRunType
 		return myTypes;
 	}
 
-	public static RunType SelectAndReturnRunIntervalType(string typeName) 
+	public static RunType SelectAndReturnRunIntervalType(string typeName, bool dbconOpened) 
 	{
-		dbcon.Open();
+		if(!dbconOpened)
+			dbcon.Open();
 		dbcmd.CommandText = "SELECT * " +
 			" FROM " + Constants.RunIntervalTypeTable +
 			" WHERE name  = '" + typeName +
@@ -456,7 +459,8 @@ class SqliteRunIntervalType : SqliteRunType
 		myRunType.IsPredefined = myRunType.FindIfIsPredefined();
 
 		reader.Close();
-		dbcon.Close();
+		if(!dbconOpened)
+			dbcon.Close();
 
 		return myRunType;
 	}
diff --git a/src/treeViewRun.cs b/src/treeViewRun.cs
index 518f2d6..24c2761 100644
--- a/src/treeViewRun.cs
+++ b/src/treeViewRun.cs
@@ -157,7 +157,7 @@ public class TreeViewRunsInterval : TreeViewRuns
 		myRunI.Simulated = Convert.ToInt32(myStringOfData[12].ToString());
 		//speed is not needed to define
 			
-		runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(myRunI.Type);
+		runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(myRunI.Type, false);
 		
 		return myRunI;
 	}
@@ -206,7 +206,7 @@ public class TreeViewRunsInterval : TreeViewRuns
 		int count = 0;
 
 		if(newRunI.DistanceInterval == -1) {
-			runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(newRunI.Type);
+			runType = SqliteRunIntervalType.SelectAndReturnRunIntervalType(newRunI.Type, false);
 			myData[count++] = (lineCount + 1).ToString() +  
 				" (" + Util.GetRunIVariableDistancesStringRow(runType.DistancesString, lineCount).ToString() + "m)";
 			



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