[chronojump] Fixed crash when exportSession 4 times (Open and Close db too much)
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Fixed crash when exportSession 4 times (Open and Close db too much)
- Date: Thu, 7 Apr 2011 16:12:08 +0000 (UTC)
commit 13e062d3c419d08f7bb565f741a4c1795758d155
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Apr 7 18:10:44 2011 +0200
Fixed crash when exportSession 4 times (Open and Close db too much)
glade/chronojump.glade | 9 ++++-----
src/execute/run.cs | 2 +-
src/exportSession.cs | 11 ++++++++++-
src/gui/chronojump.cs | 4 ++--
src/gui/jump.cs | 5 +++--
src/sqlite/main.cs | 12 +++++++++++-
src/sqlite/personSession.cs | 11 +++++++----
7 files changed, 38 insertions(+), 16 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index f9e1681..8093793 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -13902,7 +13902,7 @@ by you</property>
<widget class="GtkViewport" id="viewport_mode">
<property name="visible">True</property>
<property name="resize_mode">queue</property>
- <property name="hadjustment">0 0 730 73 657 730</property>
+ <property name="hadjustment">0 0 738 73.799999999999997 664.20000000000005 738</property>
<property name="shadow_type">out</property>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox2">
@@ -17750,7 +17750,6 @@ Second Chronopic to platforms.</property>
<child>
<widget class="GtkNotebook" id="notebook_results_data">
<property name="visible">True</property>
- <property name="show_tabs">False</property>
<property name="show_border">False</property>
<child>
<widget class="GtkTable" id="table3">
@@ -18263,7 +18262,7 @@ Second Chronopic to platforms.</property>
<widget class="GtkLabel" id="label267">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Now</property>
+ <property name="label" translatable="yes">Last jump</property>
<property name="justify">center</property>
</widget>
<packing>
@@ -18806,7 +18805,7 @@ Second Chronopic to platforms.</property>
<widget class="GtkLabel" id="label305">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Now</property>
+ <property name="label" translatable="yes">Last run</property>
<property name="justify">center</property>
</widget>
<packing>
@@ -19160,7 +19159,7 @@ Second Chronopic to platforms.</property>
<widget class="GtkLabel" id="label313">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">Now</property>
+ <property name="label" translatable="yes">Last pulse</property>
<property name="justify">center</property>
</widget>
<packing>
diff --git a/src/execute/run.cs b/src/execute/run.cs
index da588ed..edbd875 100644
--- a/src/execute/run.cs
+++ b/src/execute/run.cs
@@ -319,7 +319,7 @@ Log.WriteLine("MANAGE(3)!!!!");
// P = W * 9.8 * D / t
// W: person weight
// D: distance between 3d and 9th stair
- double weight = SqlitePersonSession.SelectAttribute(personID, sessionID, Constants.Weight);
+ double weight = SqlitePersonSession.SelectAttribute(false, personID, sessionID, Constants.Weight);
double distanceMeters = distance / 1000;
description = "P = " + Util.TrimDecimals ( (weight * 9.8 * distanceMeters / time).ToString(), pDN) + " (Watts)";
} else if(type == "Gesell-DBT")
diff --git a/src/exportSession.cs b/src/exportSession.cs
index 7f8a566..8096a12 100644
--- a/src/exportSession.cs
+++ b/src/exportSession.cs
@@ -235,7 +235,7 @@ public class ExportSession
Catalog.GetString ("Sport") + ":" + Catalog.GetString("Speciallity") + ":" +
Catalog.GetString ("Level") + ":" + Catalog.GetString ("Comments")
);
-
+
foreach (Person p in myPersons) {
PersonSession ps = SqlitePersonSession.Select(p.UniqueID, mySession.UniqueID);
string sportName = (SqliteSport.Select(ps.SportID)).Name;
@@ -287,10 +287,13 @@ public class ExportSession
Catalog.GetString("Simulated")
);
+
+ Sqlite.Open();
foreach (string jumpString in myJumps) {
string [] myStr = jumpString.Split(new char[] {':'});
double personWeight = SqlitePersonSession.SelectAttribute(
+ true, //dbconOpened
Convert.ToInt32(myStr[2]),
Convert.ToInt32(myStr[3]),
Constants.Weight);
@@ -331,6 +334,8 @@ public class ExportSession
);
}
+ Sqlite.Close();
+
writeData(myData);
writeData("VERTICAL-SPACE");
}
@@ -346,6 +351,7 @@ public class ExportSession
if(myJumpsRj.Length > 0)
printTitles(title);
+ Sqlite.Open();
foreach (string jump in myJumpsRj) {
if(showSubjumps) {
@@ -394,6 +400,7 @@ public class ExportSession
myWeight = Util.WeightFromPercentToKg(
Convert.ToDouble(myStr[8]),
SqlitePersonSession.SelectAttribute(
+ true, //dbconOpened
Convert.ToInt32(myStr[2]),
Convert.ToInt32(myStr[3]),
Constants.Weight
@@ -461,6 +468,8 @@ public class ExportSession
writeData("VERTICAL-SPACE");
}
}
+ Sqlite.Close();
+
//if not showSubjumps write data at last for not having every row as TH
if(! showSubjumps) {
writeData(myData);
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 08c1550..dcf61b3 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -4266,7 +4266,7 @@ Console.WriteLine("X");
if(eventOldPerson == myJump.PersonID) {
if(! weightPercentPreferred) {
double personWeight = SqlitePersonSession.SelectAttribute(
- myJump.PersonID, currentSession.UniqueID, Constants.Weight);
+ false, myJump.PersonID, currentSession.UniqueID, Constants.Weight);
myJump.Weight = Util.WeightFromPercentToKg(myJump.Weight, personWeight);
}
myTreeViewJumps.Update(myJump);
@@ -4289,7 +4289,7 @@ Console.WriteLine("X");
if(eventOldPerson == myJump.PersonID) {
if(! weightPercentPreferred) {
double personWeight = SqlitePersonSession.SelectAttribute(
- myJump.PersonID, currentSession.UniqueID, Constants.Weight);
+ false, myJump.PersonID, currentSession.UniqueID, Constants.Weight);
myJump.Weight = Util.WeightFromPercentToKg(myJump.Weight, personWeight);
}
myTreeViewJumpsRj.Update(myJump);
diff --git a/src/gui/jump.cs b/src/gui/jump.cs
index 9f0fe81..7e706ec 100644
--- a/src/gui/jump.cs
+++ b/src/gui/jump.cs
@@ -62,6 +62,7 @@ public class EditJumpWindow : EditEventWindow
EditJumpWindowBox.weightPercentPreferred = weightPercentPreferred;
EditJumpWindowBox.personWeight = SqlitePersonSession.SelectAttribute(
+ false,
Convert.ToInt32(myEvent.PersonID),
Convert.ToInt32(myEvent.SessionID),
Constants.Weight);
@@ -250,7 +251,7 @@ public class EditJumpWindow : EditEventWindow
else
jumpWeightInKg = Convert.ToDouble(entryWeight);
- double newPersonWeight = SqlitePersonSession.SelectAttribute(personID, mySessionID, Constants.Weight);
+ double newPersonWeight = SqlitePersonSession.SelectAttribute(false, personID, mySessionID, Constants.Weight);
//jumpPercentWeightForNewPerson = jumpWeightInKg * 100 / newPersonWeight;
jumpPercentWeightForNewPerson = Util.WeightFromKgToPercent(jumpWeightInKg, newPersonWeight);
Log.WriteLine(string.Format("oldPW: {0}, jWinKg {1}, newPW{2}, jWin%NewP{3}",
@@ -291,7 +292,7 @@ public class EditJumpRjWindow : EditJumpWindow
EditJumpRjWindowBox.weightPercentPreferred = weightPercentPreferred;
EditJumpRjWindowBox.personWeight = SqlitePersonSession.SelectAttribute(
- myEvent.PersonID, myEvent.SessionID, Constants.Weight);
+ false, myEvent.PersonID, myEvent.SessionID, Constants.Weight);
EditJumpRjWindowBox.pDN = pDN;
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 7f32ffc..10a9d12 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -15,7 +15,7 @@
* 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>
+ * Copyright (C) 2004-2011 Xavier de Blas <xaviblas gmail com>
*/
using System;
@@ -86,6 +86,16 @@ class Sqlite
~Sqlite() {}
+ //these two methods are used by methods who want to leave the connection opened
+ //because lots of similar transactions have to be done
+ public static void Open()
+ {
+ dbcon.Open();
+ }
+ public static void Close()
+ {
+ dbcon.Close();
+ }
public static bool Connect()
{
diff --git a/src/sqlite/personSession.cs b/src/sqlite/personSession.cs
index 4a88d00..5bdd118 100644
--- a/src/sqlite/personSession.cs
+++ b/src/sqlite/personSession.cs
@@ -15,7 +15,7 @@
* 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>
+ * Copyright (C) 2004-2011 Xavier de Blas <xaviblas gmail com>
*/
using System;
@@ -85,9 +85,10 @@ class SqlitePersonSession : Sqlite
//we KNOW session
//select doubles
- public static double SelectAttribute(int personID, int sessionID, string attribute)
+ public static double SelectAttribute(bool dbconOpened, int personID, int sessionID, string attribute)
{
- dbcon.Open();
+ if( ! dbconOpened)
+ dbcon.Open();
dbcmd.CommandText = "SELECT " + attribute + " FROM " + Constants.PersonSessionTable +
" WHERE personID == " + personID +
@@ -104,7 +105,9 @@ class SqlitePersonSession : Sqlite
myReturn = Convert.ToDouble(Util.ChangeDecimalSeparator(reader[0].ToString()));
}
reader.Close();
- dbcon.Close();
+ if( ! dbconOpened)
+ dbcon.Close();
+
return myReturn;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]