[chronojump/chronojump-importer] Adds SqliteSessionSwitcher. It allows to read sessions from different databases.
- From: Carles Pina i Estany <carlespina src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/chronojump-importer] Adds SqliteSessionSwitcher. It allows to read sessions from different databases.
- Date: Tue, 13 Sep 2016 08:59:48 +0000 (UTC)
commit 17e18cfe81e111887594897e2964cfe317366327
Author: Carles Pina i Estany <carles pina cat>
Date: Tue Sep 13 09:13:10 2016 +0100
Adds SqliteSessionSwitcher. It allows to read sessions from different databases.
It keeps using the same old code if the database is the user's default
database.
src/gui/session.cs | 8 +++--
src/sqlite/main.cs | 17 ++++++++++
src/sqlite/session.cs | 78 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 100 insertions(+), 3 deletions(-)
---
diff --git a/src/gui/session.cs b/src/gui/session.cs
index abb0296..c586484 100644
--- a/src/gui/session.cs
+++ b/src/gui/session.cs
@@ -661,8 +661,10 @@ public class SessionLoadWindow {
Gtk.Window parent;
private Session currentSession;
-
- SessionLoadWindow (Gtk.Window parent) {
+ private SqliteSessionSwitcher sqliteSession;
+
+ SessionLoadWindow (Gtk.Window parent, SqliteSessionSwitcher sqliteSession) {
+ this.sqliteSession = sqliteSession;
Glade.XML gladeXML;
gladeXML = Glade.XML.FromAssembly (Util.GetGladePath() + "chronojump.glade", "session_load",
null);
gladeXML.Autoconnect(this);
@@ -722,7 +724,7 @@ public class SessionLoadWindow {
static public SessionLoadWindow Show (Gtk.Window parent)
{
if (SessionLoadWindowBox == null) {
- SessionLoadWindowBox = new SessionLoadWindow (parent);
+ SessionLoadWindowBox = new SessionLoadWindow (parent, new SqliteSessionSwitcher(""));
}
SessionLoadWindowBox.session_load.Show ();
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index da00c21..8e54170 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -27,6 +27,23 @@ using System.Diagnostics; //for launching other process
using Mono.Unix;
+class SqliteGeneral
+{
+ private SqliteConnection dbcon;
+
+ public SqliteGeneral(string databasePath)
+ {
+ dbcon = new SqliteConnection ();
+ string connectionString = "version = 3; Data source = " + databasePath;
+ dbcon.Open();
+ }
+
+ public SqliteCommand command()
+ {
+ SqliteCommand dbcmd = dbcon.CreateCommand();
+ return dbcmd;
+ }
+}
class Sqlite
{
diff --git a/src/sqlite/session.cs b/src/sqlite/session.cs
index 85bf7f8..2ea866c 100644
--- a/src/sqlite/session.cs
+++ b/src/sqlite/session.cs
@@ -24,7 +24,84 @@ using System.IO;
using System.Collections; //ArrayList
using Mono.Data.Sqlite;
using Mono.Unix;
+using System.Collections.Generic;
+public class SqliteSessionSwitcher
+{
+ private string databasePath;
+ public SqliteSessionSwitcher(string databasePath)
+ {
+ this.databasePath = databasePath;
+ }
+
+ public string[] SelectAllSessions(string filterName)
+ {
+ if (string.IsNullOrEmpty (databasePath))
+ {
+ return SqliteSession.SelectAllSessions (filterName);
+ }
+ else
+ {
+ SqliteGeneral sqliteGeneral = new SqliteGeneral(databasePath);
+ SqliteCommand dbcommand = sqliteGeneral.command();
+
+ dbcommand.CommandText = "SELECT uniqueID, name, place, data, comment FROM Sessions";
+
+ SqliteDataReader reader = dbcommand.ExecuteReader ();
+
+ List<string> result = new List<string>();
+
+ // Each row should be:
+ // 1:SIMULATED::11/09/2016:--Undefined::Undefined:Use this session to simulate
tests.:0:0:0:0:0:0:0:0:0 ; 0:0 ; 0
+ while (reader.Read())
+ {
+ string row = string.Format
("{0}:{1}::{2}--Undefined::Undefined:{3}:0:0:0:0:0:0:0:0:0 ; 0:0 ; 0", reader ["uniqueID"], reader ["name"],
reader ["data"], reader ["comment"]);
+ result.Add(row);
+ }
+ return result.ToArray();
+ }
+ }
+
+ public Session Select(string myUniqueID)
+ {
+ if (string.IsNullOrEmpty (databasePath))
+ {
+ return SqliteSession.Select (myUniqueID);
+ }
+ else
+ {
+ SqliteGeneral sqliteGeneral = new SqliteGeneral(databasePath);
+ SqliteCommand dbcommand = sqliteGeneral.command();
+
+ dbcommand.CommandText = "SELECT * FROM Sessions WHERE uniqueID == @myUniqueID";
+ dbcommand.Parameters.Add (new SqliteParameter ("@myUniqueID", myUniqueID));
+
+ SqliteDataReader reader = dbcommand.ExecuteReader ();
+
+ // Copied from a non-callable (yet) static method: SqliteSession::Select()
+ string [] values = new string[9];
+
+ while(reader.Read()) {
+ values[0] = reader[0].ToString();
+ values[1] = reader[1].ToString();
+ values[2] = reader[2].ToString();
+ values[3] = reader[3].ToString();
+ values[4] = reader[4].ToString();
+ values[5] = reader[5].ToString();
+ values[6] = reader[6].ToString();
+ values[7] = reader[7].ToString();
+ values[8] = reader[8].ToString();
+ }
+
+ Session mySession = new Session(values[0],
+ values[1], values[2], UtilDate.FromSql(values[3]),
+ Convert.ToInt32(values[4]),
Convert.ToInt32(values[5]), Convert.ToInt32(values[6]),
+ values[7], Convert.ToInt32(values[8]) );
+
+ return mySession;
+ }
+ }
+}
class SqliteSession : Sqlite
{
@@ -596,6 +673,7 @@ class SqliteSession : Sqlite
mySessions [count++] = lineNotReadOnly;
}
+ LogB.SQL (mySessions [0]);
return mySessions;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]