[chronojump] selectRunsCreateSelection protected. runsI select implement Orders_by, limit, personNameInComment
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] selectRunsCreateSelection protected. runsI select implement Orders_by, limit, personNameInComment
- Date: Mon, 27 Sep 2021 11:55:05 +0000 (UTC)
commit 8d62bf416ae54de7b8e441a22d9129f4a98dfde0
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Sep 27 13:49:42 2021 +0200
selectRunsCreateSelection protected. runsI select implement Orders_by, limit, personNameInComment
src/exportFiles/sprint.cs | 3 ++-
src/sqlite/run.cs | 30 +++++++++++++++++-------------
src/sqlite/runInterval.cs | 47 +++++++++++++++++++++++++++++++++++++++++------
3 files changed, 60 insertions(+), 20 deletions(-)
---
diff --git a/src/exportFiles/sprint.cs b/src/exportFiles/sprint.cs
index 3b608f372..c774d3645 100644
--- a/src/exportFiles/sprint.cs
+++ b/src/exportFiles/sprint.cs
@@ -65,7 +65,8 @@ public class SprintExport : ExportFiles
protected override bool getData ()
{
- ri_l = SqliteRunInterval.SelectRuns (false, sessionID, personID, "");
+ ri_l = SqliteRunInterval.SelectRuns (false, sessionID, personID, "",
+ Sqlite.Orders_by.DEFAULT, -1, false);
personSession_l = SqlitePersonSession.SelectCurrentSessionPersons(sessionID, true);
riTypes_l = SqliteRunIntervalType.SelectRunIntervalTypesNew("", false);
diff --git a/src/sqlite/run.cs b/src/sqlite/run.cs
index 7ca5e78ca..0b0461f2b 100644
--- a/src/sqlite/run.cs
+++ b/src/sqlite/run.cs
@@ -89,36 +89,39 @@ class SqliteRun : Sqlite
}
//note this is selecting also the person.name
- private static string selectRunsCreateSelection (int sessionID, int personID, string filterType,
+ //used on run and runI
+ protected static string selectCreateSelection (string tableName,
+ int sessionID, int personID, string filterType,
Orders_by order, int limit, bool onlyBestInSession)
{
+ string t = tableName;
string tp = Constants.PersonTable;
string filterSessionString = "";
if(sessionID != -1)
- filterSessionString = " AND run.sessionID = " + sessionID;
+ filterSessionString = string.Format(" AND {0}.sessionID = {1}", t, sessionID);
string filterPersonString = "";
if(personID != -1)
- filterPersonString = " AND " + tp + ".uniqueID = " + personID;
+ filterPersonString = string.Format(" AND {0}.uniqueID = {1}", tp, personID);
string filterTypeString = "";
if(filterType != "")
- filterTypeString = " AND run.type = \"" + filterType + "\" " ;
+ filterTypeString = " AND " + t + ".type = \"" + filterType + "\" " ;
- string orderByString = " ORDER BY upper(" + tp + ".name), run.uniqueID ";
+ string orderByString = string.Format(" ORDER BY upper({0}.name), {1}.uniqueID ", tp, t);
if(order == Orders_by.ID_DESC)
- orderByString = " ORDER BY run.uniqueID DESC ";
+ orderByString = string.Format(" ORDER BY {0}.uniqueID DESC ", t);
if(onlyBestInSession)
- orderByString = " ORDER BY run.sessionID, run.distance/run.time DESC ";
+ orderByString = string.Format(" ORDER BY {0}.sessionID, {0}.distance/{0}.time DESC ",
t);
string limitString = "";
if(limit != -1)
limitString = " LIMIT " + limit;
- return "SELECT " + tp + ".name, run.* " +
- " FROM " + tp + ", run " +
- " WHERE " + tp + ".uniqueID = run.personID" +
+ return string.Format("SELECT {0}.name, {1}.* ", tp, t) +
+ string.Format(" FROM {0}, {1} ", tp, t) +
+ string.Format(" WHERE {0}.uniqueID = {1}.personID", tp, t) +
filterSessionString +
filterPersonString +
filterTypeString +
@@ -138,7 +141,8 @@ class SqliteRun : Sqlite
if(!dbconOpened)
Sqlite.Open();
- dbcmd.CommandText = selectRunsCreateSelection (sessionID, personID, filterType, order, limit,
false);
+ dbcmd.CommandText = selectCreateSelection (Constants.RunTable,
+ sessionID, personID, filterType, order, limit, false);
LogB.SQL(dbcmd.CommandText.ToString());
dbcmd.ExecuteNonQuery();
@@ -198,12 +202,12 @@ class SqliteRun : Sqlite
if(! dbconOpened)
Sqlite.Open();
- //runs previous to DB 2.13 have no datetime on run
+ //runs previous to DB 2.13 have no datetime on run, runI
//find session datetime for that runs
List<Session> session_l = SqliteSession.SelectAll(true, Sqlite.Orders_by.DEFAULT);
- dbcmd.CommandText = selectRunsCreateSelection (sessionID, personID, runType, order, limit,
onlyBestInSession);
+ dbcmd.CommandText = selectCreateSelection (Constants.RunTable, sessionID, personID, runType,
order, limit, onlyBestInSession);
LogB.SQL(dbcmd.CommandText.ToString());
dbcmd.ExecuteNonQuery();
diff --git a/src/sqlite/runInterval.cs b/src/sqlite/runInterval.cs
index 45d6b7dfe..da62b7c54 100644
--- a/src/sqlite/runInterval.cs
+++ b/src/sqlite/runInterval.cs
@@ -118,12 +118,18 @@ class SqliteRunInterval : SqliteRun
}
//like SelectRunsSA below method but much better: return list of RunInterval
- public static List<RunInterval> SelectRuns (bool dbconOpened, int sessionID, int personID, string
filterType)
+ public static List<RunInterval> SelectRuns (bool dbconOpened, int sessionID, int personID, string
runType,
+ Orders_by order, int limit, bool personNameInComment)
{
if(!dbconOpened)
Sqlite.Open();
- dbcmd.CommandText = selectRunsIntervalCreateSelection (sessionID, personID, filterType);
+ //runs previous to DB 2.13 have no datetime on run, runI
+ //find session datetime for that runs
+ List<Session> session_l = SqliteSession.SelectAll(true, Sqlite.Orders_by.DEFAULT);
+
+ dbcmd.CommandText = selectCreateSelection (Constants.RunIntervalTable,
+ sessionID, personID, runType, order, limit, false);
LogB.SQL(dbcmd.CommandText.ToString());
dbcmd.ExecuteNonQuery();
@@ -134,7 +140,8 @@ class SqliteRunInterval : SqliteRun
List<RunInterval> ri_l = new List<RunInterval>();
while(reader.Read())
- ri_l.Add(new RunInterval(
+ {
+ RunInterval runI = new RunInterval(
Convert.ToInt32(reader[1].ToString()), //runInterval.uniqueID
Convert.ToInt32(reader[2].ToString()), //runInterval.personID
Convert.ToInt32(reader[3].ToString()), //runInterval.sessionID
@@ -149,7 +156,34 @@ class SqliteRunInterval : SqliteRun
Convert.ToInt32(reader[12].ToString()), //simulated
Util.IntToBool(Convert.ToInt32(reader[13])), //initialSpeed
reader[14].ToString() //datetime
- ));
+ );
+
+ //runs previous to DB 2.13 have no datetime on run
+ //find session datetime for that runs
+ if(runI.Datetime == "")
+ {
+ bool found = false;
+ foreach(Session session in session_l)
+ {
+ if(session.UniqueID == runI.SessionID)
+ {
+ runI.Datetime = UtilDate.ToFile(session.Date);
+ found = true;
+ break;
+ }
+
+ }
+ //on really old versions of Chronojump, deleting a session maybe does not
delete the runs
+ //so could be able to found a run without a session, so assign here the
MinValue possible of DateTime
+ if(! found)
+ runI.Datetime = UtilDate.ToFile(DateTime.MinValue);
+ }
+
+ if(personNameInComment)
+ runI.Description = reader[0].ToString();
+
+ ri_l.Add(runI);
+ }
reader.Close();
@@ -160,12 +194,13 @@ class SqliteRunInterval : SqliteRun
}
//method that retruns an string array
- public static string[] SelectRunsSA (bool dbconOpened, int sessionID, int personID, string filterType)
+ public static string[] SelectRunsSA (bool dbconOpened, int sessionID, int personID, string runType)
{
if(!dbconOpened)
Sqlite.Open();
- dbcmd.CommandText = selectRunsIntervalCreateSelection (sessionID, personID, filterType);
+ dbcmd.CommandText = selectCreateSelection (Constants.RunIntervalTable,
+ sessionID, personID, runType, Orders_by.DEFAULT, -1, false);
LogB.SQL(dbcmd.CommandText.ToString());
dbcmd.ExecuteNonQuery();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]