[chronojump] SqliteSession.SelectAll can have SQL opened or not
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] SqliteSession.SelectAll can have SQL opened or not
- Date: Mon, 6 Sep 2021 12:32:44 +0000 (UTC)
commit 3f20cdaf0ca12df1d96eb7bf543650da824c3b9b
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Sep 6 14:29:22 2021 +0200
SqliteSession.SelectAll can have SQL opened or not
src/gui/app1/session/loadAndImport.cs | 2 +-
src/gui/event.cs | 2 +-
src/jump.cs | 2 +-
src/sqlite/jump.cs | 14 +++++++-------
src/sqlite/personSession.cs | 10 +++++++---
src/sqlite/run.cs | 13 +++----------
src/sqlite/session.cs | 35 +++++++++++++++++++++--------------
7 files changed, 41 insertions(+), 37 deletions(-)
---
diff --git a/src/gui/app1/session/loadAndImport.cs b/src/gui/app1/session/loadAndImport.cs
index 6a44af5d5..9a28126bc 100644
--- a/src/gui/app1/session/loadAndImport.cs
+++ b/src/gui/app1/session/loadAndImport.cs
@@ -883,7 +883,7 @@ public partial class ChronoJumpWindow
private void on_app1s_button_import_at_new_done_do_load_clicked (object o, EventArgs args)
{
//ID has to be the last one, get the last session
- List<Session> session_l = SqliteSession.SelectAll(Sqlite.Orders_by.ID_DESC);
+ List<Session> session_l = SqliteSession.SelectAll(false, Sqlite.Orders_by.ID_DESC);
if(session_l == null && session_l.Count == 0)
return;
diff --git a/src/gui/event.cs b/src/gui/event.cs
index dbf4c67ab..1c3ffa165 100644
--- a/src/gui/event.cs
+++ b/src/gui/event.cs
@@ -690,7 +690,7 @@ public class EventMoreWindow
void on_button_delete_type_clicked (object o, EventArgs args)
{
- List<Session> session_l = SqliteSession.SelectAll(Sqlite.Orders_by.DEFAULT);
+ List<Session> session_l = SqliteSession.SelectAll(false, Sqlite.Orders_by.DEFAULT);
string [] tests = findTestTypesInSessions();
//this will be much better doing a select distinct(session) instead of using SelectJumps or
Runs
diff --git a/src/jump.cs b/src/jump.cs
index b0d725c34..5edaf7e69 100644
--- a/src/jump.cs
+++ b/src/jump.cs
@@ -180,7 +180,7 @@ public class JumpRj : Jump
this.datetime = datetime;
}
- //used to select a jump at SqliteJump.SelectRjJumpData and at Sqlite.convertTables
+ //used to select a jump at SqliteJumpRj.SelectJumpData and at Sqlite.convertTables
public JumpRj(string [] eventString)
{
//foreach(string myStr in eventString)
diff --git a/src/sqlite/jump.cs b/src/sqlite/jump.cs
index 86285f9b1..608f9ffd8 100644
--- a/src/sqlite/jump.cs
+++ b/src/sqlite/jump.cs
@@ -204,13 +204,15 @@ class SqliteJump : Sqlite
*/
public static List<Jump> SelectJumps (int sID, int pID, string jumpType, Orders_by order, int limit,
bool personNameInComment, bool onlyBestInSession)
{
+ Sqlite.Open(); // -------------------->
+
//jumps previous to DB 1.82 have no datetime on jump
//find session datetime for that jumps
- List<Session> session_l = SqliteSession.SelectAll(Sqlite.Orders_by.DEFAULT);
+ List<Session> session_l = SqliteSession.SelectAll(true, Sqlite.Orders_by.DEFAULT);
//for personNameInComment
List<Person> person_l =
- SqlitePersonSession.SelectCurrentSessionPersonsAsList(sID);
+ SqlitePersonSession.SelectCurrentSessionPersonsAsList(true, sID);
string andString = "";
string sessionString = "";
@@ -249,8 +251,6 @@ class SqliteJump : Sqlite
limitString = " LIMIT " + limit;
- Sqlite.Open(); // --------------------
-
// Selecciona les dades de tots els salts
dbcmd.CommandText = "SELECT * FROM jump " +
whereString + sessionString + personString + jumpTypeString +
@@ -265,7 +265,7 @@ class SqliteJump : Sqlite
List<Jump> jmp_l = DataReaderToJump (reader, session_l, person_l, personNameInComment);
reader.Close();
- Sqlite.Close(); // --------------------
+ Sqlite.Close(); // <--------------------
return jmp_l;
}
@@ -453,7 +453,7 @@ class SqliteJump : Sqlite
{
//jumps previous to DB 1.82 have no datetime on jump
//find session datetime for that jumps
- List<Session> session_l = SqliteSession.SelectAll(Sqlite.Orders_by.DEFAULT);
+ List<Session> session_l = SqliteSession.SelectAll(false, Sqlite.Orders_by.DEFAULT);
string personID = pID.ToString();
string sessionID = sID.ToString();
@@ -501,7 +501,7 @@ class SqliteJump : Sqlite
{
//jumps previous to DB 1.82 have no datetime on jump
//find session datetime for that jumps
- List<Session> session_l = SqliteSession.SelectAll(Sqlite.Orders_by.DEFAULT);
+ List<Session> session_l = SqliteSession.SelectAll(false, Sqlite.Orders_by.DEFAULT);
string personID = pID.ToString();
string sessionID = sID.ToString();
diff --git a/src/sqlite/personSession.cs b/src/sqlite/personSession.cs
index 4f7343143..12174b50d 100644
--- a/src/sqlite/personSession.cs
+++ b/src/sqlite/personSession.cs
@@ -260,14 +260,16 @@ class SqlitePersonSession : Sqlite
//sessionID can be -1
//TODO: add the sessionID -1 code
- public static List<Person> SelectCurrentSessionPersonsAsList (int sessionID)
+ public static List<Person> SelectCurrentSessionPersonsAsList (bool dbconOpened, int sessionID)
{
string tp = Constants.PersonTable;
string tps = Constants.PersonSessionTable;
string tpsString = "";
- Sqlite.Open();
+ if(! dbconOpened)
+ Sqlite.Open();
+
dbcmd.CommandText = "SELECT " + tp + ".*" +
" FROM " + tp + ", " + tps +
" WHERE " + tps + ".sessionID == " + sessionID +
@@ -298,7 +300,9 @@ class SqlitePersonSession : Sqlite
}
reader.Close();
- Sqlite.Close();
+
+ if(! dbconOpened)
+ Sqlite.Close();
return person_l;
}
diff --git a/src/sqlite/run.cs b/src/sqlite/run.cs
index be4162977..7ca5e78ca 100644
--- a/src/sqlite/run.cs
+++ b/src/sqlite/run.cs
@@ -195,24 +195,17 @@ class SqliteRun : Sqlite
public static List<Run> SelectRuns (bool dbconOpened, int sessionID, int personID, string runType,
Orders_by order, int limit, bool personNameInComment, bool onlyBestInSession)
{
- //need to close DB for SqliteSession.SelectAll
- if(dbconOpened)
- {
- Sqlite.Close();
-// dbconOpened = false;
- }
+ if(! dbconOpened)
+ Sqlite.Open();
//runs previous to DB 2.13 have no datetime on run
//find session datetime for that runs
- List<Session> session_l = SqliteSession.SelectAll(Sqlite.Orders_by.DEFAULT);
+ List<Session> session_l = SqliteSession.SelectAll(true, Sqlite.Orders_by.DEFAULT);
dbcmd.CommandText = selectRunsCreateSelection (sessionID, personID, runType, order, limit,
onlyBestInSession);
LogB.SQL(dbcmd.CommandText.ToString());
-// if(! dbconOpened)
- Sqlite.Open();
-
dbcmd.ExecuteNonQuery();
SqliteDataReader reader;
diff --git a/src/sqlite/session.cs b/src/sqlite/session.cs
index 2b3b09143..3971898a8 100644
--- a/src/sqlite/session.cs
+++ b/src/sqlite/session.cs
@@ -252,7 +252,7 @@ class SqliteSession : Sqlite
{
dbcmd.CommandText = "SELECT * FROM " + Constants.SessionTable + " WHERE LOWER(name) =
LOWER(\"" + name + "\")";
- List<Session> session_l = selectDo(dbcmd);
+ List<Session> session_l = selectDo(false, dbcmd);
if(session_l.Count == 0)
return new Session();
@@ -264,34 +264,38 @@ class SqliteSession : Sqlite
{
dbcmd.CommandText = "SELECT * FROM " + Constants.SessionTable + " WHERE uniqueID == " +
myUniqueID ;
- List<Session> session_l = selectDo(dbcmd);
+ List<Session> session_l = selectDo(false, dbcmd);
if(session_l.Count == 0)
return new Session();
//return (Session) selectDo(dbcmd)[0];
return session_l[0];
}
- public static List<Session> SelectAll(Orders_by orderBy)
+ public static List<Session> SelectAll(bool dbconOpened, Orders_by orderBy)
{
string orderByStr = " ORDER BY uniqueID";
if(orderBy == Orders_by.ID_DESC)
orderByStr += " DESC";
dbcmd.CommandText = "SELECT * FROM " + Constants.SessionTable + orderByStr;
- return selectDo(dbcmd);
+ return selectDo(dbconOpened, dbcmd);
}
- private static List<Session> selectDo(SqliteCommand mydbcmd)
+ private static List<Session> selectDo(bool dbconOpened, SqliteCommand mydbcmd)
{
- try {
- Sqlite.Open();
- } catch {
- //done because there's an eventual problem maybe thread related on very few starts of
chronojump
- LogB.SQL("Catched dbcon problem at Session.Select");
- Sqlite.Close();
- Sqlite.Open();
- LogB.SQL("reopened again");
+ if( ! dbconOpened)
+ {
+ try {
+ Sqlite.Open();
+ } catch {
+ //done because there's an eventual problem maybe thread related on very few
starts of chronojump
+ LogB.SQL("Catched dbcon problem at Session.Select");
+ Sqlite.Close();
+ Sqlite.Open();
+ LogB.SQL("reopened again");
+ }
}
LogB.SQL(mydbcmd.CommandText.ToString());
+
SqliteDataReader reader;
reader = mydbcmd.ExecuteReader();
@@ -315,7 +319,10 @@ class SqliteSession : Sqlite
}
reader.Close();
- Sqlite.Close();
+
+ if( ! dbconOpened)
+ Sqlite.Close();
+
return session_l;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]