[chronojump] Safer load session, export and report with less SQL open/close calls
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Safer load session, export and report with less SQL open/close calls
- Date: Tue, 14 Jul 2015 10:49:13 +0000 (UTC)
commit 6bac3fc4ea864dcacfb009beab047eca8fe3215b
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Jul 14 12:48:28 2015 +0200
Safer load session, export and report with less SQL open/close calls
src/exportSession.cs | 20 +++++++++-----
src/gui/chronojump.cs | 60 ++++++++++++++++++++++++++++++------------
src/gui/jump.cs | 2 +-
src/gui/person.cs | 2 +-
src/gui/run.cs | 2 +-
src/report.cs | 18 ++++++++----
src/server.cs | 8 +++---
src/sqlite/jumpRj.cs | 10 +++++--
src/sqlite/multiChronopic.cs | 10 +++++--
src/sqlite/pulse.cs | 10 +++++--
src/sqlite/runInterval.cs | 10 +++++--
11 files changed, 103 insertions(+), 49 deletions(-)
---
diff --git a/src/exportSession.cs b/src/exportSession.cs
index 3002383..9f8e0e0 100644
--- a/src/exportSession.cs
+++ b/src/exportSession.cs
@@ -150,13 +150,19 @@ public class ExportSession
protected virtual void getData()
{
myPersonsAndPS = SqlitePersonSession.SelectCurrentSessionPersons(mySession.UniqueID, true);
- myJumps= SqliteJump.SelectJumps(false, mySession.UniqueID, -1, "", "");
- myJumpsRj = SqliteJumpRj.SelectJumps(mySession.UniqueID, -1, "", "");
- myRuns= SqliteRun.SelectRuns(false, mySession.UniqueID, -1, "");
- myRunsInterval = SqliteRunInterval.SelectRuns(mySession.UniqueID, -1, "");
- myReactionTimes = SqliteReactionTime.SelectReactionTimes(false, mySession.UniqueID, -1);
- myPulses = SqlitePulse.SelectPulses(mySession.UniqueID, -1);
- myMCs = SqliteMultiChronopic.SelectTests(mySession.UniqueID, -1);
+
+ //Leave SQL opened in all this process
+ Sqlite.Open(); // ------------------------------
+
+ myJumps= SqliteJump.SelectJumps(true, mySession.UniqueID, -1, "", "");
+ myJumpsRj = SqliteJumpRj.SelectJumps(true, mySession.UniqueID, -1, "", "");
+ myRuns= SqliteRun.SelectRuns(true, mySession.UniqueID, -1, "");
+ myRunsInterval = SqliteRunInterval.SelectRuns(true, mySession.UniqueID, -1, "");
+ myReactionTimes = SqliteReactionTime.SelectReactionTimes(true, mySession.UniqueID, -1);
+ myPulses = SqlitePulse.SelectPulses(true, mySession.UniqueID, -1);
+ myMCs = SqliteMultiChronopic.SelectTests(true, mySession.UniqueID, -1);
+
+ Sqlite.Close(); // ------------------------------
}
protected virtual void printTitles(string title) {
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 8b01770..fb82381 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -1422,33 +1422,40 @@ public partial class ChronoJumpWindow
fillTreeView_persons();
}
+ //Leave SQL opened in all this process
+ Sqlite.Open(); // ------------------------------
+
//load the jumps treeview
treeview_jumps_storeReset();
- fillTreeView_jumps(Constants.AllJumpsName);
+ fillTreeView_jumps(Constants.AllJumpsName, true);
//load the jumps_rj treeview_rj
treeview_jumps_rj_storeReset();
- fillTreeView_jumps_rj(Constants.AllJumpsName);
+ fillTreeView_jumps_rj(Constants.AllJumpsName, true);
//load the runs treeview
treeview_runs_storeReset();
- fillTreeView_runs(Constants.AllRunsName);
+ fillTreeView_runs(Constants.AllRunsName, true);
//load the runs_interval treeview
treeview_runs_interval_storeReset();
- fillTreeView_runs_interval(Constants.AllRunsName);
+ fillTreeView_runs_interval(Constants.AllRunsName, true);
//load the pulses treeview
treeview_pulses_storeReset();
- fillTreeView_pulses(Constants.AllPulsesName);
+ fillTreeView_pulses(Constants.AllPulsesName, true);
//load the reaction_times treeview
treeview_reaction_times_storeReset();
- fillTreeView_reaction_times();
+ fillTreeView_reaction_times(true);
//load the multiChronopic treeview
treeview_multi_chronopic_storeReset();
- fillTreeView_multi_chronopic();
+ fillTreeView_multi_chronopic(true);
+
+
+ //close SQL opened in all this process
+ Sqlite.Close(); // ------------------------------
}
@@ -1470,9 +1477,12 @@ public partial class ChronoJumpWindow
}
private void fillTreeView_jumps (string filter) {
+ fillTreeView_jumps(filter, false);
+ }
+ private void fillTreeView_jumps (string filter, bool dbconOpened) {
string [] myJumps;
- myJumps = SqliteJump.SelectJumps(false, currentSession.UniqueID, -1, "", "");
+ myJumps = SqliteJump.SelectJumps(dbconOpened, currentSession.UniqueID, -1, "", "");
myTreeViewJumps.Fill(myJumps, filter);
expandOrMinimizeTreeView((TreeViewEvent) myTreeViewJumps, treeview_jumps);
@@ -1552,8 +1562,11 @@ public partial class ChronoJumpWindow
}
private void fillTreeView_jumps_rj (string filter) {
+ fillTreeView_jumps_rj (filter, false);
+ }
+ private void fillTreeView_jumps_rj (string filter, bool dbconOpened) {
string [] myJumps;
- myJumps = SqliteJumpRj.SelectJumps(currentSession.UniqueID, -1, "", "");
+ myJumps = SqliteJumpRj.SelectJumps(dbconOpened, currentSession.UniqueID, -1, "", "");
myTreeViewJumpsRj.Fill(myJumps, filter);
expandOrMinimizeTreeView((TreeViewEvent) myTreeViewJumpsRj, treeview_jumps_rj);
@@ -1639,11 +1652,13 @@ public partial class ChronoJumpWindow
}
private void fillTreeView_runs (string filter) {
- string [] myRuns = SqliteRun.SelectRuns(false, currentSession.UniqueID, -1, "");
+ fillTreeView_runs (filter, false);
+ }
+ private void fillTreeView_runs (string filter, bool dbconOpened) {
+ string [] myRuns = SqliteRun.SelectRuns(dbconOpened, currentSession.UniqueID, -1, "");
myTreeViewRuns.Fill(myRuns, filter);
expandOrMinimizeTreeView((TreeViewEvent) myTreeViewRuns, treeview_runs);
-
}
private void on_button_runs_zoom_clicked (object o, EventArgs args) {
@@ -1715,7 +1730,10 @@ public partial class ChronoJumpWindow
}
private void fillTreeView_runs_interval (string filter) {
- string [] myRuns = SqliteRunInterval.SelectRuns(currentSession.UniqueID, -1, "");
+ fillTreeView_runs_interval (filter, false);
+ }
+ private void fillTreeView_runs_interval (string filter, bool dbconOpened) {
+ string [] myRuns = SqliteRunInterval.SelectRuns(dbconOpened, currentSession.UniqueID, -1, "");
myTreeViewRunsInterval.Fill(myRuns, filter);
expandOrMinimizeTreeView((TreeViewEvent) myTreeViewRunsInterval, treeview_runs_interval);
}
@@ -1799,9 +1817,11 @@ public partial class ChronoJumpWindow
tv.CursorChanged += on_treeview_reaction_times_cursor_changed;
}
- //private void fillTreeView_reaction_times (string filter) {
private void fillTreeView_reaction_times () {
- string [] myRTs = SqliteReactionTime.SelectReactionTimes(false, currentSession.UniqueID, -1);
+ fillTreeView_reaction_times (false);
+ }
+ private void fillTreeView_reaction_times (bool dbconOpened) {
+ string [] myRTs = SqliteReactionTime.SelectReactionTimes(dbconOpened,
currentSession.UniqueID, -1);
myTreeViewReactionTimes.Fill(myRTs, "");
expandOrMinimizeTreeView((TreeViewEvent) myTreeViewReactionTimes, treeview_reaction_times);
}
@@ -1876,7 +1896,10 @@ public partial class ChronoJumpWindow
}
private void fillTreeView_pulses (string filter) {
- string [] myPulses = SqlitePulse.SelectPulses(currentSession.UniqueID, -1);
+ fillTreeView_pulses (filter, false);
+ }
+ private void fillTreeView_pulses (string filter, bool dbconOpened) {
+ string [] myPulses = SqlitePulse.SelectPulses(dbconOpened, currentSession.UniqueID, -1);
myTreeViewPulses.Fill(myPulses, filter);
expandOrMinimizeTreeView((TreeViewEvent) myTreeViewPulses, treeview_pulses);
}
@@ -1965,7 +1988,10 @@ public partial class ChronoJumpWindow
}
private void fillTreeView_multi_chronopic () {
- string [] mcs = SqliteMultiChronopic.SelectTests(currentSession.UniqueID, -1);
+ fillTreeView_multi_chronopic (false);
+ }
+ private void fillTreeView_multi_chronopic (bool dbconOpened) {
+ string [] mcs = SqliteMultiChronopic.SelectTests(dbconOpened, currentSession.UniqueID, -1);
myTreeViewMultiChronopic.Fill(mcs, "");
expandOrMinimizeTreeView((TreeViewEvent) myTreeViewMultiChronopic, treeview_multi_chronopic);
}
@@ -2513,7 +2539,7 @@ public partial class ChronoJumpWindow
private void on_load_session_accepted ()
{
app1.Title = progName + " - " + currentSession.Name;
-
+
if(createdStatsWin) {
stats_win_initializeSession();
}
diff --git a/src/gui/jump.cs b/src/gui/jump.cs
index 5320570..d29676c 100644
--- a/src/gui/jump.cs
+++ b/src/gui/jump.cs
@@ -1845,7 +1845,7 @@ public class JumpsRjMoreWindow : EventMoreWindow
}
protected override string [] findTestTypesInSessions() {
- return SqliteJumpRj.SelectJumps(-1, -1, "", selectedEventName);
+ return SqliteJumpRj.SelectJumps(false, -1, -1, "", selectedEventName);
}
void on_button_cancel_clicked (object o, EventArgs args)
diff --git a/src/gui/person.cs b/src/gui/person.cs
index 364d815..2740c16 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -1550,7 +1550,7 @@ public class PersonAddModifyWindow
if(!adding && (double) spinbutton_weight.Value != weightIni) {
//see if this person has done jumps with weight
string [] myJumpsNormal = SqliteJump.SelectJumps(false,
currentSession.UniqueID, currentPerson.UniqueID, "withWeight", "");
- string [] myJumpsReactive = SqliteJumpRj.SelectJumps(currentSession.UniqueID,
currentPerson.UniqueID, "withWeight", "");
+ string [] myJumpsReactive = SqliteJumpRj.SelectJumps(false,
currentSession.UniqueID, currentPerson.UniqueID, "withWeight", "");
if(myJumpsNormal.Length > 0 || myJumpsReactive.Length > 0) {
//create the convertWeight Window
diff --git a/src/gui/run.cs b/src/gui/run.cs
index f4f389b..a47b015 100644
--- a/src/gui/run.cs
+++ b/src/gui/run.cs
@@ -1523,7 +1523,7 @@ public class RunsIntervalMoreWindow : EventMoreWindow
}
protected override string [] findTestTypesInSessions() {
- return SqliteRunInterval.SelectRuns(-1, -1, selectedEventName);
+ return SqliteRunInterval.SelectRuns(false, -1, -1, selectedEventName);
}
diff --git a/src/report.cs b/src/report.cs
index 922ba0f..2390599 100644
--- a/src/report.cs
+++ b/src/report.cs
@@ -98,24 +98,30 @@ public class Report : ExportSession
if(ShowCurrentSessionJumpers) {
myPersonsAndPS = SqlitePersonSession.SelectCurrentSessionPersons(sessionID, true);
}
+
+ //Leave SQL opened in all this process
+ Sqlite.Open(); // ------------------------------
+
if(ShowSimpleJumps) {
- myJumps= SqliteJump.SelectJumps(false, sessionID, -1, "", "");
+ myJumps= SqliteJump.SelectJumps(true, sessionID, -1, "", "");
}
if(ShowReactiveJumps) {
- myJumpsRj = SqliteJumpRj.SelectJumps(sessionID, -1, "", "");
+ myJumpsRj = SqliteJumpRj.SelectJumps(true, sessionID, -1, "", "");
}
if(ShowSimpleRuns) {
- myRuns= SqliteRun.SelectRuns(false, sessionID, -1, "");
+ myRuns= SqliteRun.SelectRuns(true, sessionID, -1, "");
}
if (ShowIntervalRuns) {
- myRunsInterval = SqliteRunInterval.SelectRuns(sessionID, -1, "");
+ myRunsInterval = SqliteRunInterval.SelectRuns(true, sessionID, -1, "");
}
if(ShowReactionTimes) {
- myReactionTimes= SqliteReactionTime.SelectReactionTimes(false, sessionID, -1);
+ myReactionTimes= SqliteReactionTime.SelectReactionTimes(true, sessionID, -1);
}
if(ShowPulses) {
- myPulses= SqlitePulse.SelectPulses(sessionID, -1);
+ myPulses= SqlitePulse.SelectPulses(true, sessionID, -1);
}
+
+ Sqlite.Close(); // ------------------------------
}
protected override void printTitles(string title) {
diff --git a/src/server.cs b/src/server.cs
index fc7ae84..b39509f 100644
--- a/src/server.cs
+++ b/src/server.cs
@@ -323,7 +323,7 @@ public class Server
countE = 0;
countS = 0;
- string [] jumpsRj = SqliteJumpRj.SelectJumps(currentSession.UniqueID,
person.UniqueID, "", "");
+ string [] jumpsRj = SqliteJumpRj.SelectJumps(false, currentSession.UniqueID,
person.UniqueID, "", "");
Sqlite.Open();
foreach(string myJump in jumpsRj) {
string [] js = myJump.Split(new char[] {':'});
@@ -411,7 +411,7 @@ public class Server
countE = 0;
countS = 0;
- string [] runsI = SqliteRunInterval.SelectRuns(currentSession.UniqueID,
person.UniqueID, "");
+ string [] runsI = SqliteRunInterval.SelectRuns(false,
currentSession.UniqueID, person.UniqueID, "");
Sqlite.Open();
foreach(string myRun in runsI) {
string [] js = myRun.Split(new char[] {':'});
@@ -485,7 +485,7 @@ public class Server
countE = 0;
countS = 0;
- string [] pulses = SqlitePulse.SelectPulses(currentSession.UniqueID,
person.UniqueID);
+ string [] pulses = SqlitePulse.SelectPulses(false, currentSession.UniqueID,
person.UniqueID);
Sqlite.Open();
foreach(string myPulse in pulses) {
string [] js = myPulse.Split(new char[] {':'});
@@ -516,7 +516,7 @@ public class Server
countE = 0;
countS = 0;
- string [] mcs = SqliteMultiChronopic.SelectTests(currentSession.UniqueID,
person.UniqueID);
+ string [] mcs = SqliteMultiChronopic.SelectTests(false,
currentSession.UniqueID, person.UniqueID);
Sqlite.Open();
foreach(string mc in mcs) {
string [] js = mc.Split(new char[] {':'});
diff --git a/src/sqlite/jumpRj.cs b/src/sqlite/jumpRj.cs
index 9bfedbd..c29cb2b 100644
--- a/src/sqlite/jumpRj.cs
+++ b/src/sqlite/jumpRj.cs
@@ -91,8 +91,11 @@ class SqliteJumpRj : SqliteJump
return myLast;
}
- public new static string[] SelectJumps(int sessionID, int personID, string filterWeight, string
filterType)
+ public new static string[] SelectJumps(bool dbconOpened, int sessionID, int personID, string
filterWeight, string filterType)
{
+ if(!dbconOpened)
+ Sqlite.Open();
+
string tp = Constants.PersonTable;
string tps = Constants.PersonSessionTable;
@@ -112,7 +115,6 @@ class SqliteJumpRj : SqliteJump
if(filterType != "")
filterTypeString = " AND jumpRj.type == '" + filterType + "' ";
- Sqlite.Open();
dbcmd.CommandText = "SELECT " + tp + ".name, jumpRj.*, " + tps + ".weight " +
" FROM " + tp + ", jumpRj, " + tps + " " +
" WHERE " + tp + ".uniqueID == jumpRj.personID" +
@@ -161,7 +163,9 @@ class SqliteJumpRj : SqliteJump
}
reader.Close();
- Sqlite.Close();
+
+ if(!dbconOpened)
+ Sqlite.Close();
string [] myJumps = new string[count];
count =0;
diff --git a/src/sqlite/multiChronopic.cs b/src/sqlite/multiChronopic.cs
index 01abad9..380ac07 100644
--- a/src/sqlite/multiChronopic.cs
+++ b/src/sqlite/multiChronopic.cs
@@ -113,15 +113,17 @@ class SqliteMultiChronopic : Sqlite
}
//if all persons, put -1 in personID
- public static string[] SelectTests(int sessionID, int personID)
+ public static string[] SelectTests(bool dbconOpened, int sessionID, int personID)
{
+ if(!dbconOpened)
+ Sqlite.Open();
+
string tp = Constants.PersonTable;
string filterPersonString = "";
if(personID != -1)
filterPersonString = " AND " + tp + ".uniqueID == " + personID;
- Sqlite.Open();
dbcmd.CommandText = "SELECT " + tp + ".name, multiChronopic.* " +
" FROM " + tp + ", multiChronopic " +
" WHERE " + tp + ".uniqueID == multiChronopic.personID" +
@@ -168,7 +170,9 @@ class SqliteMultiChronopic : Sqlite
}
reader.Close();
- Sqlite.Close();
+
+ if(!dbconOpened)
+ Sqlite.Close();
string [] myEvents = new string[count];
count =0;
diff --git a/src/sqlite/pulse.cs b/src/sqlite/pulse.cs
index 556570a..08b8415 100644
--- a/src/sqlite/pulse.cs
+++ b/src/sqlite/pulse.cs
@@ -87,15 +87,17 @@ class SqlitePulse : Sqlite
//if all persons, put -1 in personID
- public static string[] SelectPulses(int sessionID, int personID)
+ public static string[] SelectPulses(bool dbconOpened, int sessionID, int personID)
{
+ if(!dbconOpened)
+ Sqlite.Open();
+
string tp = Constants.PersonTable;
string filterPersonString = "";
if(personID != -1)
filterPersonString = " AND " + tp + ".uniqueID == " + personID;
- Sqlite.Open();
dbcmd.CommandText = "SELECT " + tp + ".name, pulse.* " +
" FROM " + tp + ", pulse " +
" WHERE " + tp + ".uniqueID == pulse.personID" +
@@ -130,7 +132,9 @@ class SqlitePulse : Sqlite
}
reader.Close();
- Sqlite.Close();
+
+ if(!dbconOpened)
+ Sqlite.Close();
string [] myPulses = new string[count];
count =0;
diff --git a/src/sqlite/runInterval.cs b/src/sqlite/runInterval.cs
index 8e1f62e..d872069 100644
--- a/src/sqlite/runInterval.cs
+++ b/src/sqlite/runInterval.cs
@@ -89,8 +89,11 @@ class SqliteRunInterval : SqliteRun
return myLast;
}
- public new static string[] SelectRuns(int sessionID, int personID, string filterType)
+ public new static string[] SelectRuns(bool dbconOpened, int sessionID, int personID, string
filterType)
{
+ if(!dbconOpened)
+ Sqlite.Open();
+
string tp = Constants.PersonTable;
string filterSessionString = "";
@@ -105,7 +108,6 @@ class SqliteRunInterval : SqliteRun
if(filterType != "")
filterTypeString = " AND runInterval.type == '" + filterType + "' " ;
- Sqlite.Open();
dbcmd.CommandText = "SELECT " + tp + ".name, runInterval.* " +
" FROM " + tp + ", runInterval " +
" WHERE " + tp + ".uniqueID == runInterval.personID" +
@@ -145,7 +147,9 @@ class SqliteRunInterval : SqliteRun
}
reader.Close();
- Sqlite.Close();
+
+ if(!dbconOpened)
+ Sqlite.Close();
string [] myRuns = new string[count];
count =0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]