[chronojump/77] done person, personSession classes, sqlite classes
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/77] done person, personSession classes, sqlite classes
- Date: Thu, 25 Feb 2010 10:03:08 +0000 (UTC)
commit cad6aee8c2dc02e12cad499a3ec7718378471065
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Feb 25 18:01:44 2010 +0800
done person, personSession classes, sqlite classes
sqlite_diagrams/chronojump_sqlite.dia | Bin 11962 -> 12715 bytes
src/person.cs | 169 +++++++++++
src/personSession.cs | 106 +++++++
src/sqlite/person.cs | 490 +++++++++++++++++++++++++++++++++
src/sqlite/personSession.cs | 392 ++++++++++++++++++++++++++
5 files changed, 1157 insertions(+), 0 deletions(-)
---
diff --git a/sqlite_diagrams/chronojump_sqlite.dia b/sqlite_diagrams/chronojump_sqlite.dia
index 03a5ce1..8059625 100644
Binary files a/sqlite_diagrams/chronojump_sqlite.dia and b/sqlite_diagrams/chronojump_sqlite.dia differ
diff --git a/src/person.cs b/src/person.cs
new file mode 100644
index 0000000..8feca49
--- /dev/null
+++ b/src/person.cs
@@ -0,0 +1,169 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ChronoJump is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Copyright (C) 2004-2010 Xavier de Blas <xaviblas gmail com>
+ */
+
+using System;
+using System.Data;
+using System.Text; //StringBuilder
+using Mono.Unix;
+
+public partial class Person {
+
+ private int uniqueID;
+ private string name;
+ private string sex; // "M" (male) , "F" (female) (Constants.M, Constants.F)
+ private DateTime dateBorn;
+ private int race;
+ private int countryID;
+ private string description;
+ private int serverUniqueID; //not on server
+
+ private int sessionID;
+
+ public Person() {
+ }
+
+ //suitable when we load a person from the database for being the current Person
+ //we know uniqueID
+ public Person(int uniqueID, string name, string sex, DateTime dateBorn,
+ int race, int countryID, string description, int serverUniqueID)
+ {
+ //needed by the return of gui/personAddModifyWindow
+ name = Util.RemoveTildeAndColon(name);
+ description = Util.RemoveTildeAndColon(description);
+
+ this.uniqueID = uniqueID;
+ this.sex = sex;
+ this.name = name;
+ this.dateBorn = dateBorn;
+ this.race = race;
+ this.countryID = countryID;
+ this.description = description;
+ this.serverUniqueID = serverUniqueID; //remember don't do this on server
+ }
+
+ //typical constructor
+ //used when we create new person
+ //we don't know uniqueID
+ public Person(string name, string sex, DateTime dateBorn, int race, int countryID, string description,
+ int serverUniqueID, int sessionID)
+ {
+ name = Util.RemoveTildeAndColon(name);
+ description = Util.RemoveTildeAndColon(description);
+
+ this.name = name;
+ this.sex = sex;
+ this.dateBorn = dateBorn;
+ this.race = race;
+ this.countryID = countryID;
+ this.description = description;
+ this.serverUniqueID = serverUniqueID; //remember don't do this on server
+ this.sessionID = sessionID;
+
+ //insert in the person table
+ //when insert as person we don't know uniqueID
+ uniqueID = -1;
+ int insertedID = this.InsertAtDB(false, Constants.PersonTable);
+
+ //we need uniqueID for personSession
+ uniqueID = insertedID;
+
+ Log.WriteLine(this.ToString());
+
+ //insert in the personSession table (fast way of knowing who was in each session)
+ //SqlitePersonSession.Insert (false, Constants.PersonSessionWeightTable, "-1", uniqueID, sessionID, weight);
+ }
+
+ public int InsertAtDB (bool dbconOpened, string tableName) {
+ int myID = SqlitePerson.Insert(dbconOpened, tableName,
+ uniqueID.ToString(), name, sex, dateBorn, race, countryID,
+ description, serverUniqueID);
+ return myID;
+ }
+
+
+ public override string ToString()
+ {
+ return "[uniqueID: " + uniqueID + "]" + name + ", " + ", " + sex + ", " + dateBorn.ToShortDateString() + ", " + description;
+ }
+
+ public override bool Equals(object evalString)
+ {
+ return this.ToString() == evalString.ToString();
+ }
+
+ public override int GetHashCode()
+ {
+ return this.ToString().GetHashCode();
+ }
+
+
+ public string Name {
+ get { return name; }
+ set { name = value; }
+ }
+
+ public string Sex {
+ get { return sex; }
+ set { sex = value; }
+ }
+
+ public DateTime DateBorn {
+ get { return dateBorn; }
+ set { dateBorn = value; }
+ }
+
+ public int Race {
+ get { return race; }
+ set { race = value; }
+ }
+
+ public int CountryID {
+ get { return countryID; }
+ set { countryID = value; }
+ }
+
+ public string Description {
+ get { return description; }
+ set { description = value; }
+ }
+
+ public int ServerUniqueID {
+ get { return serverUniqueID; }
+ set { serverUniqueID = value; }
+ }
+
+ public int UniqueID {
+ get { return uniqueID; }
+ set { uniqueID = value; }
+ }
+
+ public string DateLong {
+ get { return dateBorn.ToLongDateString(); }
+ }
+
+ public string DateShort {
+ get { return dateBorn.ToShortDateString(); }
+ }
+
+
+ ~Person() {}
+
+}
+
diff --git a/src/personSession.cs b/src/personSession.cs
new file mode 100644
index 0000000..6daa956
--- /dev/null
+++ b/src/personSession.cs
@@ -0,0 +1,106 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ChronoJump is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Copyright (C) 2004-2009 Xavier de Blas <xaviblas gmail com>
+ */
+
+using System;
+using System.Data;
+using System.Text; //StringBuilder
+using Mono.Unix;
+
+public partial class PersonSession {
+
+ private int uniqueID;
+ private int personID;
+ private int sessionID;
+ private double height;
+ private double weight;
+ private int sportID; //1 undefined, 2 none, 3...n other sports (check table sportType)
+ private int speciallityID;
+ private int practice; //-1 undefined, sedentary, 1 regular practice, 2 competition, 3 (alto rendimiento)
+ private string comments;
+
+
+ public PersonSession() {
+ }
+
+ //loading
+ //we know uniqueID
+ public PersonSession(int uniqueID, int personID, int sessionID,
+ double height, double weight, int sportID,
+ int speciallityID, int practice, string comments)
+ {
+ this.uniqueID = uniqueID;
+ this.personID = personID;
+ this.sessionID = sessionID;
+ this.height = height;
+ this.weight = weight;
+ this.sportID = sportID;
+ this.speciallityID = speciallityID;
+ this.practice = practice;
+ this.comments = comments;
+ }
+
+ //typical constructor
+ //creation
+ //we don't know uniqueID
+ public PersonSession(int personID, int sessionID,
+ double height, double weight, int sportID,
+ int speciallityID, int practice, string comments)
+ {
+ this.personID = personID;
+ this.sessionID = sessionID;
+ this.height = height;
+ this.weight = weight;
+ this.sportID = sportID;
+ this.speciallityID = speciallityID;
+ this.practice = practice;
+ this.comments = comments;
+
+
+ //insert in the personSession table
+ //when insert as personSession we don't know uniqueID
+ uniqueID = -1;
+ int insertedID = this.InsertAtDB(false, Constants.PersonSessionTable);
+
+ //we need uniqueID for personSession
+ uniqueID = insertedID;
+
+ Log.WriteLine(this.ToString());
+ }
+
+ public int InsertAtDB (bool dbconOpened, string tableName) {
+ int myID = SqlitePersonSession.Insert(dbconOpened, tableName,
+ uniqueID.ToString(),
+ personID, sessionID, height, weight
+ sportID, speciallityID,
+ practice, comments);
+ return myID;
+ }
+
+
+ public override string ToString()
+ {
+ return "";
+ //return "[uniqueID: " + uniqueID + "]" + name + ", " + ", " + sex + ", " + dateBorn.ToShortDateString() + ", " + description;
+ }
+
+ ~PersonSession() {}
+
+}
+
diff --git a/src/sqlite/person.cs b/src/sqlite/person.cs
new file mode 100644
index 0000000..fa5496a
--- /dev/null
+++ b/src/sqlite/person.cs
@@ -0,0 +1,490 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ChronoJump is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Copyright (C) 2004-2010 Xavier de Blas <xaviblas gmail com>
+ */
+
+using System;
+using System.Data;
+using System.IO;
+using System.Collections; //ArrayList
+using Mono.Data.Sqlite;
+
+
+class SqlitePerson : Sqlite
+{
+ public SqlitePerson() {
+ }
+
+ ~SqlitePerson() {}
+
+ //can be "Constants.PersonTable" or "Constants.ConvertTempTable"
+ //temp is used to modify table between different database versions if needed
+ //protected new internal static void createTable(string tableName)
+ protected override void createTable(string tableName)
+ {
+ dbcmd.CommandText =
+ "CREATE TABLE " + tableName + " ( " +
+ "uniqueID INTEGER PRIMARY KEY, " +
+ "name TEXT, " +
+ "sex TEXT, " +
+ "dateborn TEXT, " + //YYYY-MM-DD since db 0.72
+ "race INT, " +
+ "countryID INT, " +
+ "description TEXT, " +
+ "future1 TEXT, " +
+ "future2 TEXT, " +
+ "serverUniqueID INT ) ";
+ dbcmd.ExecuteNonQuery();
+ }
+
+ public static int Insert(bool dbconOpened, string uniqueID, string name, string sex, DateTime dateBorn,
+ int race, int countryID, string description, int serverUniqueID)
+ {
+ if(! dbconOpened)
+ dbcon.Open();
+
+ if(uniqueID == "-1")
+ uniqueID = "NULL";
+
+ string myString = "INSERT INTO " + Constants.PersonTable +
+ " (uniqueID, name, sex, dateBorn, race, countryID, description, future1, future2, serverUniqueID) VALUES (" + uniqueID + ", '" +
+ name + "', '" + sex + "', '" + UtilDate.ToSql(dateBorn) + "', " +
+ race + ", " + countryID + ", '" + description + "', '', '', " + serverUniqueID + ")";
+
+ dbcmd.CommandText = myString;
+ Log.WriteLine(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+ int myReturn = dbcon.LastInsertRowId;
+
+ if(! dbconOpened)
+ dbcon.Close();
+
+ return myReturn;
+ }
+
+ //public static string SelectJumperName(int uniqueID)
+ //select strings
+ public static string SelectAttribute(int uniqueID, string attribute)
+ {
+ dbcon.Open();
+
+ dbcmd.CommandText = "SELECT " + attribute + " FROM " + Constants.PersonTable + " WHERE uniqueID == " + uniqueID;
+
+ Log.WriteLine(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ string myReturn = "";
+ if(reader.Read()) {
+ myReturn = reader[0].ToString();
+ }
+ dbcon.Close();
+ return myReturn;
+ }
+
+ //currently only used on server
+ public static ArrayList SelectAllPersons()
+ {
+ dbcon.Open();
+ dbcmd.CommandText = "SELECT uniqueID, name FROM " + Constants.PersonTable;
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ ArrayList myArray = new ArrayList(1);
+
+ while(reader.Read())
+ myArray.Add ("(" + reader[0].ToString() + ") " + reader[1].ToString());
+
+ reader.Close();
+ dbcon.Close();
+
+ return myArray;
+ }
+
+ public static string[] SelectAllPersonsRecuperable(string sortedBy, int except, int inSession, string searchFilterName)
+ {
+ //sortedBy = name or uniqueID (= creation date)
+
+
+ //1st select all the person.uniqueID of people who are in CurrentSession (or none if except == -1)
+ //2n select all names in database (or in one session if inSession != -1)
+ //3d filter all names (save all found in 2 that is not in 1)
+ //
+ //probably this can be made in only one time... future
+ //
+ //1
+
+ string tp = Constants.PersonTable;
+ string tps = Constants.PersonSessionTable;
+
+ dbcon.Open();
+ dbcmd.CommandText = "SELECT " + tp + ".uniqueID " +
+ " FROM " + tp + "," + tps +
+ " WHERE " + tps + ".sessionID == " + except +
+ " AND " + tp + ".uniqueID == " + tps + ".personID ";
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ ArrayList arrayExcept = new ArrayList(2);
+
+ while(reader.Read())
+ arrayExcept.Add (reader[0].ToString());
+
+ reader.Close();
+ dbcon.Close();
+
+ //2
+ //sort no case sensitive when we sort by name
+ if(sortedBy == "name") {
+ sortedBy = "lower(" + tp + ".name)" ;
+ } else {
+ sortedBy = tp + ".uniqueID" ;
+ }
+
+ dbcon.Open();
+ if(inSession == -1) {
+ string nameLike = "";
+ if(searchFilterName != "")
+ nameLike = " WHERE LOWER(" + tp + ".name) LIKE LOWER ('%" + searchFilterName + "%') ";
+
+ dbcmd.CommandText =
+ "SELECT * FROM " + tp +
+ nameLike +
+ " ORDER BY " + sortedBy;
+
+ } else {
+ dbcmd.CommandText =
+ "SELECT " + tp + ".* FROM " + tp + ", " + tps +
+ " WHERE " + tps + ".sessionID == " + inSession +
+ " AND " + tp + ".uniqueID == " + tps + ".personID " +
+ " ORDER BY " + sortedBy;
+ }
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ SqliteDataReader reader2;
+ reader2 = dbcmd.ExecuteReader();
+
+ ArrayList arrayReturn = new ArrayList(2);
+
+ bool found;
+
+ //3
+ while(reader2.Read()) {
+ found = false;
+ foreach (string line in arrayExcept) {
+ if(line == reader2[0].ToString()) {
+ found = true;
+ goto finishForeach;
+ }
+ }
+
+finishForeach:
+
+ if (!found) {
+ Person p = new Person(
+ Convert.ToInt32(reader2[0].ToString()), //uniqueID
+ reader2[1].ToString(), //name
+ reader2[2].ToString(), //sex
+ UtilDate.FromSql(reader2[3].ToString()).ToShortDateString(), //dateBorn
+ Convert.ToInt32(reader2[4].ToString()), //race
+ Convert.ToInt32(reader2[5].ToString()), //countryID
+ reader2[6].ToString(), //description
+ Convert.ToInt32(reader2[9].ToString()) //serverUniqueID
+ )
+ arrayReturn.Add(p);
+ }
+ }
+
+ reader2.Close();
+ dbcon.Close();
+
+ return arrayReturn;
+ }
+
+ public static ArrayList SelectAllPersonEvents(int personID)
+ {
+ SqliteDataReader reader;
+ ArrayList arraySessions = new ArrayList(2);
+ ArrayList arrayJumps = new ArrayList(2);
+ ArrayList arrayJumpsRj = new ArrayList(2);
+ ArrayList arrayRuns = new ArrayList(2);
+ ArrayList arrayRunsInterval = new ArrayList(2);
+ ArrayList arrayRTs = new ArrayList(2);
+ ArrayList arrayPulses = new ArrayList(2);
+ ArrayList arrayMCs = new ArrayList(2);
+
+ string tps = Constants.PersonSessionTable;
+
+ dbcon.Open();
+
+ //session where this person is loaded
+ dbcmd.CommandText = "SELECT sessionID, session.Name, session.Place, session.Date " +
+ " FROM " + tps + ", session " +
+ " WHERE personID = " + personID + " AND session.uniqueID == " + tps + ".sessionID " +
+ " ORDER BY sessionID";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ reader = dbcmd.ExecuteReader();
+ while(reader.Read()) {
+ arraySessions.Add ( reader[0].ToString() + ":" + reader[1].ToString() + ":" +
+ reader[2].ToString() + ":" +
+ UtilDate.FromSql(reader[3].ToString()).ToShortDateString()
+ );
+ }
+ reader.Close();
+
+
+ //jumps
+ dbcmd.CommandText = "SELECT sessionID, count(*) FROM jump WHERE personID = " + personID +
+ " GROUP BY sessionID ORDER BY sessionID";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ reader = dbcmd.ExecuteReader();
+ while(reader.Read()) {
+ arrayJumps.Add ( reader[0].ToString() + ":" + reader[1].ToString() );
+ }
+ reader.Close();
+
+ //jumpsRj
+ dbcmd.CommandText = "SELECT sessionID, count(*) FROM jumpRj WHERE personID = " + personID +
+ " GROUP BY sessionID ORDER BY sessionID";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ reader = dbcmd.ExecuteReader();
+ while(reader.Read()) {
+ arrayJumpsRj.Add ( reader[0].ToString() + ":" + reader[1].ToString() );
+ }
+ reader.Close();
+
+ //runs
+ dbcmd.CommandText = "SELECT sessionID, count(*) FROM run WHERE personID = " + personID +
+ " GROUP BY sessionID ORDER BY sessionID";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ reader = dbcmd.ExecuteReader();
+ while(reader.Read()) {
+ arrayRuns.Add ( reader[0].ToString() + ":" + reader[1].ToString() );
+ }
+ reader.Close();
+
+ //runsInterval
+ dbcmd.CommandText = "SELECT sessionID, count(*) FROM runInterval WHERE personID = " + personID +
+ " GROUP BY sessionID ORDER BY sessionID";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ reader = dbcmd.ExecuteReader();
+ while(reader.Read()) {
+ arrayRunsInterval.Add ( reader[0].ToString() + ":" + reader[1].ToString() );
+ }
+ reader.Close();
+
+ //reaction time
+ dbcmd.CommandText = "SELECT sessionID, count(*) FROM reactiontime WHERE personID = " + personID +
+ " GROUP BY sessionID ORDER BY sessionID";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ reader = dbcmd.ExecuteReader();
+ while(reader.Read()) {
+ arrayRTs.Add ( reader[0].ToString() + ":" + reader[1].ToString() );
+ }
+ reader.Close();
+
+ //pulses
+ dbcmd.CommandText = "SELECT sessionID, count(*) FROM pulse WHERE personID = " + personID +
+ " GROUP BY sessionID ORDER BY sessionID";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ reader = dbcmd.ExecuteReader();
+ while(reader.Read()) {
+ arrayPulses.Add ( reader[0].ToString() + ":" + reader[1].ToString() );
+ }
+ reader.Close();
+
+ //pulses
+ dbcmd.CommandText = "SELECT sessionID, count(*) FROM multiChronopic WHERE personID = " + personID +
+ " GROUP BY sessionID ORDER BY sessionID";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ reader = dbcmd.ExecuteReader();
+ while(reader.Read()) {
+ arrayMCs.Add ( reader[0].ToString() + ":" + reader[1].ToString() );
+ }
+ reader.Close();
+
+
+ dbcon.Close();
+
+
+ ArrayList arrayAll = new ArrayList(2);
+ string tempJumps;
+ string tempJumpsRj;
+ string tempRuns;
+ string tempRunsInterval;
+ string tempRTs;
+ string tempPulses;
+ string tempMCs;
+ bool found; //using found because a person can be loaded in a session
+ //but whithout having done any event yet
+
+ //foreach session where this jumper it's loaded, check which events has
+ foreach (string mySession in arraySessions) {
+ string [] myStrSession = mySession.Split(new char[] {':'});
+ tempJumps = "";
+ tempJumpsRj = "";
+ tempRuns = "";
+ tempRunsInterval = "";
+ tempRTs = "";
+ tempPulses = "";
+ tempMCs = "";
+ found = false;
+
+ foreach (string myJumps in arrayJumps) {
+ string [] myStr = myJumps.Split(new char[] {':'});
+ if(myStrSession[0] == myStr[0]) {
+ tempJumps = myStr[1];
+ found = true;
+ break;
+ }
+ }
+
+ foreach (string myJumpsRj in arrayJumpsRj) {
+ string [] myStr = myJumpsRj.Split(new char[] {':'});
+ if(myStrSession[0] == myStr[0]) {
+ tempJumpsRj = myStr[1];
+ found = true;
+ break;
+ }
+ }
+
+ foreach (string myRuns in arrayRuns) {
+ string [] myStr = myRuns.Split(new char[] {':'});
+ if(myStrSession[0] == myStr[0]) {
+ tempRuns = myStr[1];
+ found = true;
+ break;
+ }
+ }
+
+ foreach (string myRunsInterval in arrayRunsInterval) {
+ string [] myStr = myRunsInterval.Split(new char[] {':'});
+ if(myStrSession[0] == myStr[0]) {
+ tempRunsInterval = myStr[1];
+ found = true;
+ break;
+ }
+ }
+
+ foreach (string myRTs in arrayRTs) {
+ string [] myStr = myRTs.Split(new char[] {':'});
+ if(myStrSession[0] == myStr[0]) {
+ tempRTs = myStr[1];
+ found = true;
+ break;
+ }
+ }
+
+ foreach (string myPulses in arrayPulses) {
+ string [] myStr = myPulses.Split(new char[] {':'});
+ if(myStrSession[0] == myStr[0]) {
+ tempPulses = myStr[1];
+ found = true;
+ break;
+ }
+ }
+
+ foreach (string myMCs in arrayMCs) {
+ string [] myStr = myMCs.Split(new char[] {':'});
+ if(myStrSession[0] == myStr[0]) {
+ tempMCs = myStr[1];
+ found = true;
+ break;
+ }
+ }
+
+
+ //if has events, write it's data
+ if (found) {
+ arrayAll.Add (myStrSession[1] + ":" + myStrSession[2] + ":" + //session name, place
+ myStrSession[3] + ":" + tempJumps + ":" + //sessionDate, jumps
+ tempJumpsRj + ":" + tempRuns + ":" + //jumpsRj, Runs
+ tempRunsInterval + ":" + tempRTs + ":" + //runsInterval, Reaction times
+ tempPulses + ":" + tempMCs); //pulses, MultiChronopic
+ }
+ }
+
+ return arrayAll;
+ }
+
+ public static bool ExistsAndItsNotMe(int uniqueID, string personName)
+ {
+ dbcon.Open();
+ dbcmd.CommandText = "SELECT uniqueID FROM " + Constants.PersonTable +
+ " WHERE LOWER(" + Constants.PersonTable + ".name) == LOWER('" + personName + "')" +
+ " AND uniqueID != " + uniqueID ;
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ bool exists = new bool();
+ exists = false;
+
+ if (reader.Read()) {
+ exists = true;
+ //Log.WriteLine("valor {0}", reader[0].ToString());
+ }
+ //Log.WriteLine("exists = {0}", exists.ToString());
+
+ reader.Close();
+ dbcon.Close();
+ return exists;
+ }
+
+
+ public static void Update(Person myPerson)
+ {
+ dbcon.Open();
+ dbcmd.CommandText = "UPDATE " + Constants.PersonTable +
+ " SET name = '" + myPerson.Name +
+ "', sex = '" + myPerson.Sex +
+ "', dateborn = '" + UtilDate.ToSql(myPerson.DateBorn) +
+ "', race = " + myPerson.Race +
+ ", countryID = " + myPerson.CountryID +
+ ", description = '" + myPerson.Description +
+ "', serverUniqueID = " + myPerson.ServerUniqueID +
+ " WHERE uniqueID == " + myPerson.UniqueID;
+ Log.WriteLine(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+ dbcon.Close();
+ }
+
+
+ public static void Delete(int uniqueID)
+ {
+ dbcmd.CommandText = "Delete FROM " + Constants.PersonTable +
+ " WHERE uniqueID == " + uniqueID.ToString();
+ Log.WriteLine(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+ }
+
+
+}
diff --git a/src/sqlite/personSession.cs b/src/sqlite/personSession.cs
new file mode 100644
index 0000000..4400efc
--- /dev/null
+++ b/src/sqlite/personSession.cs
@@ -0,0 +1,392 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ChronoJump is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Copyright (C) 2004-2010 Xavier de Blas <xaviblas gmail com>
+ */
+
+using System;
+using System.Data;
+using System.IO;
+using System.Collections; //ArrayList
+using Mono.Data.Sqlite;
+using Mono.Unix;
+
+
+class SqlitePersonSession : Sqlite
+{
+ public SqlitePersonSession() {
+ }
+
+ ~SqlitePersonSession() {}
+
+ protected override void createTable(string tableName)
+ {
+ dbcmd.CommandText =
+ "CREATE TABLE " + tableName + " ( " +
+ "uniqueID INTEGER PRIMARY KEY, " +
+ "personID INT, " +
+ "sessionID INT, " +
+ "height FLOAT, " +
+ "weight FLOAT, " +
+ "sportID INT, " +
+ "speciallityID INT, " +
+ "practice INT, " + //also called "level"
+ "comments TEXT, " +
+ "future1 TEXT, " +
+ "future2 TEXT)";
+ dbcmd.ExecuteNonQuery();
+ }
+
+ public static int Insert(bool dbconOpened, string uniqueID, int personID, int sessionID,
+ double height, double weight, int sportID, int speciallityID, int practice
+ string comments)
+ {
+ if(!dbconOpened)
+ dbcon.Open();
+
+ if(uniqueID == "-1")
+ uniqueID = "NULL";
+
+ dbcmd.CommandText = "INSERT INTO " + Constants.PersonSessionTable +
+ "(uniqueID, personID, sessionID, height, weight, " +
+ "sportID, speciallityID, practice, comments, future1, future2)" +
+ " VALUES ("
+ + uniqueID + ", " + personID + ", " + sessionID + ", " +
+ Util.ConvertToPoint(height) + ", " + Util.ConvertToPoint(weight) + ", " +
+ + sportID + ", " + speciallityID + ", " + practice + ", '" +
+ + comments + "', '', '')";
+ dbcmd.ExecuteNonQuery();
+ int myReturn = dbcon.LastInsertRowId;
+ if(!dbconOpened)
+ dbcon.Close();
+ return myReturn;
+ }
+
+ //we know session
+ //select doubles
+ public static double SelectAtribute(int personID, int sessionID, string attribute)
+ {
+ dbcon.Open();
+
+ dbcmd.CommandText = "SELECT " + attribute + " FROM " + Constants.PersonSessionTable +
+ " WHERE personID == " + personID +
+ " AND sessionID == " + sessionID;
+
+ //Log.WriteLine(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ double myReturn = 0;
+ if(reader.Read()) {
+ myReturn = Convert.ToDouble(Util.ChangeDecimalSeparator(reader[0].ToString()));
+ }
+ reader.Close();
+ dbcon.Close();
+ return myReturn;
+ }
+
+ //when a session is not know, then select atrribute of last session
+ //select doubles
+ public static double SelectAttribute(int personID, string attribute)
+ {
+ dbcon.Open();
+
+ dbcmd.CommandText = "SELECT " + attribute + ", sessionID FROM " + Constants.PersonSessionTable +
+ " WHERE personID == " + personID +
+ "ORDER BY sessionID DESC LIMIT 1";
+
+ Log.WriteLine(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ double myReturn = 0;
+ if(reader.Read()) {
+ myReturn = Convert.ToDouble(Util.ChangeDecimalSeparator(reader[0].ToString()));
+ }
+ reader.Close();
+ dbcon.Close();
+ return myReturn;
+ }
+
+ //double
+ public static void UpdateAttribute(int personID, int sessionID, string attribute, double attrValue)
+ {
+ dbcon.Open();
+ dbcmd.CommandText = "UPDATE " + Constants.PersonSessionTable +
+ " SET " + attribute + " = " + Util.ConvertToPoint(attrValue) +
+ " WHERE personID = " + personID +
+ " AND sessionID = " + sessionID
+ ;
+ Log.WriteLine(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+ dbcon.Close();
+ }
+
+ public static bool PersonSelectExistsInSession(int myPersonID, int mySessionID)
+ {
+ dbcon.Open();
+ dbcmd.CommandText = "SELECT * FROM " + Constants.PersonSessionTable +
+ " WHERE personID == " + myPersonID +
+ " AND sessionID == " + mySessionID ;
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ bool exists = new bool();
+ exists = false;
+
+ while(reader.Read())
+ exists = true;
+
+ reader.Close();
+ dbcon.Close();
+ return exists;
+ }
+
+ public static PersonSession Select(int personID, int sessionID)
+ {
+ string tps = Constants.PersonSessionTable;
+
+ dbcon.Open();
+ dbcmd.CommandText = "SELECT * FROM " + tps +
+ " WHERE uniqueID == " + uniqueID +
+ " AND sessionID == " + sessionID;
+
+ Log.WriteLine(dbcmd.CommandText.ToString());
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ string [] values = new string[12];
+
+ while(reader.Read()) {
+ PersonSession ps = new PersonSession(
+ Convert.ToInt32(reader[0].ToString()), //uniqueID
+ personID, //personID
+ sessionID, //sessionID
+ Convert.ToDouble(Util.ChangeDecimalSeparator(reader[3].ToString())), //height
+ Convert.ToDouble(Util.ChangeDecimalSeparator(reader[4].ToString())), //weight
+ Convert.ToInt32(reader[5].ToString()), //sportID
+ Convert.ToInt32(reader[6].ToString()), //speciallityID
+ Convert.ToInt32(reader[7].ToString()), //practice
+ reader[8].ToString() //comments
+ );
+ }
+
+ reader.Close();
+ dbcon.Close();
+ return ps;
+ }
+
+ //the difference between this select and others, is that this returns and ArrayList of Persons
+ //this is better than return the strings that can produce bugs in the future
+ //use this in the future:
+ public static ArrayList SelectCurrentSessionPersons(int sessionID)
+ {
+ string tp = Constants.PersonTable;
+ string tps = Constants.PersonSessionTable;
+
+ dbcon.Open();
+ dbcmd.CommandText = "SELECT " + tp + ".*" +
+ " FROM " + tp + ", " + tps +
+ " WHERE " + tps + ".sessionID == " + sessionID +
+ " AND " + tp + ".uniqueID == " + tps + ".personID " +
+ " ORDER BY upper(" + tp + ".name)";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ ArrayList myArray = new ArrayList(1);
+ while(reader.Read()) {
+ Person person = new Person(
+ Convert.ToInt32(reader[0].ToString()), //uniqueID
+ reader[1].ToString(), //name
+ reader[2].ToString(), //sex
+ UtilDate.FromSql(reader[3].ToString()), //dateBorn
+ Convert.ToInt32(reader[4].ToString()), //race
+ Convert.ToInt32(reader[5].ToString()), //countryID
+ reader[6].ToString(), //description
+ Convert.ToInt32(reader[9].ToString()) //serverUniqueID
+ );
+ myArray.Add (person);
+ }
+ reader.Close();
+ dbcon.Close();
+ return myArray;
+ }
+
+ /*
+ try to use upper method:
+ public static ArrayList SelectCurrentSessionPersons(int sessionID)
+
+ public static string[] SelectCurrentSession(int sessionID, bool onlyIDAndName, bool reverse)
+ {
+ string tp = Constants.PersonTable;
+ string tps = Constants.PersonSessionTable;
+
+ dbcon.Open();
+ dbcmd.CommandText = "SELECT " + tp + ".*, " + tps + ".weight, sport.name, speciallity.name " +
+ "FROM " + tp + ", " + tps + ", sport, speciallity " +
+ " WHERE " + tps + ".sessionID == " + sessionID +
+ " AND " + tp + ".uniqueID == " + tps + ".personID " +
+ " AND " + tp + ".sportID == sport.uniqueID " +
+ " AND " + tp + ".speciallityID == speciallity.uniqueID " +
+ " ORDER BY upper(" + tp + ".name)";
+ Log.WriteLine(dbcmd.CommandText.ToString());
+ dbcmd.ExecuteNonQuery();
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ ArrayList myArray = new ArrayList(2);
+
+ int count = new int();
+ count = 0;
+
+ while(reader.Read()) {
+ if(onlyIDAndName)
+ myArray.Add (reader[0].ToString() + ":" + reader[1].ToString() );
+ else {
+ string sportName = Catalog.GetString(reader[14].ToString());
+
+ string speciallityName = ""; //to solve a gettext bug (probably because speciallity undefined name is "")
+ if(reader[15].ToString() != "")
+ speciallityName = Catalog.GetString(reader[15].ToString());
+ string levelName = Catalog.GetString(Util.FindLevelName(Convert.ToInt32(reader[8])));
+
+ myArray.Add (
+ reader[0].ToString() + ":" + reader[1].ToString() + ":" + //id, name
+ reader[2].ToString() + ":" + //sex
+ UtilDate.FromSql(reader[3].ToString()).ToShortDateString() + ":" + //dateborn
+ reader[4].ToString() + ":" + reader[13].ToString() + ":" + //height, weight (from personSessionWeight)
+ sportName + ":" + speciallityName + ":" + levelName + ":" +
+ reader[9].ToString() //desc
+ );
+ }
+ count ++;
+ }
+
+ reader.Close();
+ dbcon.Close();
+
+ string [] myJumpers = new string[count];
+
+ if(reverse) {
+ //show the results in the combo_sujeto_actual in reversed order,
+ //then when we create a new person, this is the active, and this is shown
+ //correctly in the combo_sujeto_actual
+ int count2 = count -1;
+ foreach (string line in myArray) {
+ myJumpers [count2--] = line;
+ }
+ } else {
+ int count2 = 0;
+ foreach (string line in myArray) {
+ myJumpers [count2++] = line;
+ }
+ }
+ return myJumpers;
+ }
+ */
+
+ public static void DeletePersonFromSessionAndTests(string sessionID, string personID)
+ {
+ dbcon.Open();
+
+ //delete relations (existance) within persons and sessions in this session
+ dbcmd.CommandText = "Delete FROM " + Constants.PersonSessionTable +" WHERE sessionID == " + sessionID +
+ " AND personID == " + personID;
+ dbcmd.ExecuteNonQuery();
+
+ //if person is not in other sessions, delete it from DB
+ if(! PersonExistsInPSW(Convert.ToInt32(personID)))
+ SqlitePerson.Delete(Convert.ToInt32(personID));
+
+ //delete normal jumps
+ dbcmd.CommandText = "Delete FROM jump WHERE sessionID == " + sessionID +
+ " AND personID == " + personID;
+
+ dbcmd.ExecuteNonQuery();
+
+ //delete repetitive jumps
+ dbcmd.CommandText = "Delete FROM jumpRj WHERE sessionID == " + sessionID +
+ " AND personID == " + personID;
+ dbcmd.ExecuteNonQuery();
+
+ //delete normal runs
+ dbcmd.CommandText = "Delete FROM run WHERE sessionID == " + sessionID +
+ " AND personID == " + personID;
+
+ dbcmd.ExecuteNonQuery();
+
+ //delete intervallic runs
+ dbcmd.CommandText = "Delete FROM runInterval WHERE sessionID == " + sessionID +
+ " AND personID == " + personID;
+
+ dbcmd.ExecuteNonQuery();
+
+ //delete reaction times
+ dbcmd.CommandText = "Delete FROM reactionTime WHERE sessionID == " + sessionID +
+ " AND personID == " + personID;
+
+ dbcmd.ExecuteNonQuery();
+
+ //delete pulses
+ dbcmd.CommandText = "Delete FROM pulse WHERE sessionID == " + sessionID +
+ " AND personID == " + personID;
+
+ dbcmd.ExecuteNonQuery();
+
+ //delete multiChronopic
+ dbcmd.CommandText = "Delete FROM multiChronopic WHERE sessionID == " + sessionID +
+ " AND personID == " + personID;
+
+ dbcmd.ExecuteNonQuery();
+
+
+ dbcon.Close();
+ }
+
+ public static bool PersonExistsInPSW(int personID)
+ {
+ dbcmd.CommandText = "SELECT * FROM " + Constants.PersonSessionTable +
+ " WHERE personID == " + personID;
+ //Log.WriteLine(dbcmd.CommandText.ToString());
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+
+ bool exists = new bool();
+ exists = false;
+
+ if (reader.Read()) {
+ exists = true;
+ }
+ //Log.WriteLine(string.Format("personID exists = {0}", exists.ToString()));
+
+ reader.Close();
+ return exists;
+ }
+
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]