[chronojump/video-capture] Fixed blocker bug: 599719 (LastInsertRowId). Also closed all sqlite readers



commit 3f10b40361105a6767b98a92734bfca61bea9f83
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Dec 17 20:59:33 2010 +0100

    Fixed blocker bug: 599719 (LastInsertRowId). Also closed all sqlite readers

 src/chronojump.cs            |    2 +-
 src/event.cs                 |    1 +
 src/sqlite/country.cs        |   11 ++++++++---
 src/sqlite/event.cs          |    7 ++++++-
 src/sqlite/jump.cs           |    9 ++++++++-
 src/sqlite/jumpRj.cs         |    9 ++++++++-
 src/sqlite/jumpType.cs       |    2 ++
 src/sqlite/main.cs           |    2 ++
 src/sqlite/multiChronopic.cs |    9 ++++++++-
 src/sqlite/person.cs         |   11 +++++++++--
 src/sqlite/personSession.cs  |   10 ++++++++--
 src/sqlite/pulse.cs          |    8 +++++++-
 src/sqlite/reactionTime.cs   |    8 +++++++-
 src/sqlite/run.cs            |    8 +++++++-
 src/sqlite/runInterval.cs    |    8 +++++++-
 src/sqlite/runType.cs        |   17 +++++++++++++++--
 src/sqlite/server.cs         |   20 ++++++++++++++++----
 src/sqlite/session.cs        |   18 ++++++++++++++----
 src/sqlite/speciallity.cs    |    9 +++++++--
 src/sqlite/sport.cs          |   10 ++++++++--
 20 files changed, 149 insertions(+), 30 deletions(-)
---
diff --git a/src/chronojump.cs b/src/chronojump.cs
index 8a1a9d4..f69feb1 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -262,7 +262,7 @@ Log.WriteLine("doing backup");
 
 		splashMessageChange(5);  //check for new version
 
-		//messageToShowOnBoot += recuperateBrokenEvents();
+		messageToShowOnBoot += recuperateBrokenEvents();
 
 		//connect to server to Ping
 		versionAvailable = "";
diff --git a/src/event.cs b/src/event.cs
index e282600..3a226d1 100644
--- a/src/event.cs
+++ b/src/event.cs
@@ -48,6 +48,7 @@ public partial class Event
 		return -1;
 	}	
 	
+	
 	public string Type
 	{
 		get { return type; }
diff --git a/src/sqlite/country.cs b/src/sqlite/country.cs
index c699bad..26476d8 100644
--- a/src/sqlite/country.cs
+++ b/src/sqlite/country.cs
@@ -74,12 +74,17 @@ class SqliteCountry : Sqlite
 
 		dbcmd.CommandText = myString;
 		dbcmd.ExecuteNonQuery();
-		int myReturn = -10000; //dbcon.LastInsertRowId;
-		
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = (int)dbcmd.ExecuteScalar(); // Need to type-cast since `ExecuteScalar` returns an object.
+
 		if(! dbconOpened)
 			dbcon.Close();
 
-		return myReturn;
+		return myLast;
 	}
 
 	public static string [] SelectCountriesOfAContinent(string continent, bool insertUndefined)
diff --git a/src/sqlite/event.cs b/src/sqlite/event.cs
index 042e943..02a7c96 100644
--- a/src/sqlite/event.cs
+++ b/src/sqlite/event.cs
@@ -57,7 +57,11 @@ class SqliteEvent : Sqlite
 				" VALUES (NULL, '" + tableName + "', '" + eventName + "', '" + graphFileName + "', '', '')" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myLast = -10000; //dbcon.LastInsertRowId;
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = (int)dbcmd.ExecuteScalar(); // Need to type-cast since `ExecuteScalar` returns an object.
 		if(! dbconOpened) {
 			dbcon.Close();
 		}
@@ -82,6 +86,7 @@ class SqliteEvent : Sqlite
 			returnString = reader[0].ToString();
 		}
 	
+		reader.Close();
 		dbcon.Close();
 		return returnString;
 	}
diff --git a/src/sqlite/jump.cs b/src/sqlite/jump.cs
index 4eb24cb..fd9a211 100644
--- a/src/sqlite/jump.cs
+++ b/src/sqlite/jump.cs
@@ -81,7 +81,13 @@ class SqliteJump : Sqlite
 				+ Util.ConvertToPoint(angle) + ", " + simulated +")" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myLast = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
+
 		if(! dbconOpened)
 			dbcon.Close();
 
@@ -182,6 +188,7 @@ class SqliteJump : Sqlite
 
 		Jump myJump = new Jump(DataReaderToStringArray(reader, 11));
 	
+		reader.Close();
 		dbcon.Close();
 		return myJump;
 	}
diff --git a/src/sqlite/jumpRj.cs b/src/sqlite/jumpRj.cs
index 2236ad2..2f56b9d 100644
--- a/src/sqlite/jumpRj.cs
+++ b/src/sqlite/jumpRj.cs
@@ -78,7 +78,12 @@ class SqliteJumpRj : SqliteJump
 				jumps + ", " + Util.ConvertToPoint(time) + ", '" + limited + "', '" + angleString + "', " + simulated +")" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myLast = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 
 		if(! dbconOpened)
 			dbcon.Close();
@@ -184,6 +189,7 @@ class SqliteJumpRj : SqliteJump
 
 		JumpRj myJump = new JumpRj(DataReaderToStringArray(reader, 18));
 
+		reader.Close();
 		dbcon.Close();
 		return myJump;
 	}
@@ -225,6 +231,7 @@ class SqliteJumpRj : SqliteJump
 						reader[3].ToString(), reader[4].ToString()));
 			}
 		}
+		reader.Close();
 		dbcon.Close();
 	}
 
diff --git a/src/sqlite/jumpType.cs b/src/sqlite/jumpType.cs
index 11188af..839581b 100644
--- a/src/sqlite/jumpType.cs
+++ b/src/sqlite/jumpType.cs
@@ -400,6 +400,7 @@ class SqliteJumpType : Sqlite
 				Log.WriteLine("found type: NO hasWeight");
 			}
 		}
+		reader.Close();
 		dbcon.Close();
 		return hasWeight;
 	}
@@ -424,6 +425,7 @@ class SqliteJumpType : Sqlite
 				hasFall = false;
 			}
 		}
+		reader.Close();
 		dbcon.Close();
 		return hasFall;
 	}
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index 2fd7789..69e67df 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -1230,6 +1230,7 @@ class Sqlite
 		}
 		Log.WriteLine(string.Format("name exists = {0}", exists.ToString()));
 
+		reader.Close();
 		dbcon.Close();
 		return exists;
 	}
@@ -1322,6 +1323,7 @@ class Sqlite
 			} catch { exists = 0; }
 		}
 		Log.WriteLine(string.Format("exists = {0}", exists.ToString()));
+		reader.Close();
 		dbcon.Close();
 
 		return exists;
diff --git a/src/sqlite/multiChronopic.cs b/src/sqlite/multiChronopic.cs
index 8b16902..2262f80 100644
--- a/src/sqlite/multiChronopic.cs
+++ b/src/sqlite/multiChronopic.cs
@@ -99,7 +99,12 @@ class SqliteMultiChronopic : Sqlite
 			description + "', " + simulated + ")" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myLast = -10000; //dbcon.LastInsertRowId;
+		
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 		
 		if(! dbconOpened)
 			dbcon.Close();
@@ -190,6 +195,7 @@ class SqliteMultiChronopic : Sqlite
 		
 		MultiChronopic mc = new MultiChronopic(DataReaderToStringArray(reader, 19));
 	
+		reader.Close();
 		dbcon.Close();
 		return mc;
 	}
@@ -219,6 +225,7 @@ class SqliteMultiChronopic : Sqlite
 			maxCPs = 4;
 		}
 		
+		reader.Close();
 		dbcon.Close();
 		return maxCPs;
 	}
diff --git a/src/sqlite/person.cs b/src/sqlite/person.cs
index 14cd20d..8e8ffa8 100644
--- a/src/sqlite/person.cs
+++ b/src/sqlite/person.cs
@@ -69,12 +69,17 @@ class SqlitePerson : Sqlite
 		dbcmd.CommandText = myString;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myReturn = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = -10000; //dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 
 		if(! dbconOpened)
 			dbcon.Close();
 
-		return myReturn;
+		return myLast;
 	}
 
 	//This is like SqlitePersonSession.Selectbut this returns a Person
@@ -103,6 +108,7 @@ class SqlitePerson : Sqlite
 					Convert.ToInt32(reader[9].ToString()) //serverUniqueID
 					);
 		}
+		reader.Close();
 		dbcon.Close();
 		return p;
 	}
@@ -125,6 +131,7 @@ class SqlitePerson : Sqlite
 		if(reader.Read()) {
 			myReturn = reader[0].ToString();
 		}
+		reader.Close();
 		dbcon.Close();
 		return myReturn;
 	}
diff --git a/src/sqlite/personSession.cs b/src/sqlite/personSession.cs
index 650897d..07d274a 100644
--- a/src/sqlite/personSession.cs
+++ b/src/sqlite/personSession.cs
@@ -71,10 +71,16 @@ class SqlitePersonSession : Sqlite
 			comments + "', '', '')"; 
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myReturn = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
+
 		if(!dbconOpened)
 			dbcon.Close();
-		return myReturn;
+		return myLast;
 	}
 	
 	//we KNOW session
diff --git a/src/sqlite/pulse.cs b/src/sqlite/pulse.cs
index db76a65..6824501 100644
--- a/src/sqlite/pulse.cs
+++ b/src/sqlite/pulse.cs
@@ -72,7 +72,12 @@ class SqlitePulse : Sqlite
 				+ timeString + "', '" + description + "', " + simulated + ")" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myLast = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 
 		if(! dbconOpened)
 			dbcon.Close();
@@ -151,6 +156,7 @@ class SqlitePulse : Sqlite
 
 		Pulse myPulse = new Pulse(DataReaderToStringArray(reader, 9));
 
+		reader.Close();
 		dbcon.Close();
 		return myPulse;
 	}
diff --git a/src/sqlite/reactionTime.cs b/src/sqlite/reactionTime.cs
index 1ba3ce4..ff88797 100644
--- a/src/sqlite/reactionTime.cs
+++ b/src/sqlite/reactionTime.cs
@@ -70,7 +70,12 @@ class SqliteReactionTime : Sqlite
 				+ Util.ConvertToPoint(time) + ", '" + description + "', " + simulated + ")" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myLast = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 		
 		if(! dbconOpened)
 			dbcon.Close();
@@ -147,6 +152,7 @@ class SqliteReactionTime : Sqlite
 		
 		ReactionTime myRT = new ReactionTime(DataReaderToStringArray(reader, 7));
 	
+		reader.Close();
 		dbcon.Close();
 		return myRT;
 	}
diff --git a/src/sqlite/run.cs b/src/sqlite/run.cs
index dab2095..6b84e2d 100644
--- a/src/sqlite/run.cs
+++ b/src/sqlite/run.cs
@@ -72,7 +72,12 @@ class SqliteRun : Sqlite
 				description + "', " + simulated + ")" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myLast = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 
 		if(! dbconOpened)
 			dbcon.Close();
@@ -161,6 +166,7 @@ class SqliteRun : Sqlite
 	
 		Run myRun = new Run(DataReaderToStringArray(reader, 8));
 	
+		reader.Close();
 		dbcon.Close();
 		return myRun;
 	}
diff --git a/src/sqlite/runInterval.cs b/src/sqlite/runInterval.cs
index e3ee0d6..b3f4c6e 100644
--- a/src/sqlite/runInterval.cs
+++ b/src/sqlite/runInterval.cs
@@ -73,7 +73,12 @@ class SqliteRunInterval : SqliteRun
 				description + "', '" + limited + "', " + simulated + ")" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myLast = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 
 		if(! dbconOpened)
 			dbcon.Close();
@@ -164,6 +169,7 @@ class SqliteRunInterval : SqliteRun
 
 		RunInterval myRun = new RunInterval(DataReaderToStringArray(reader, 12));
 
+		reader.Close();
 		dbcon.Close();
 		return myRun;
 	}
diff --git a/src/sqlite/runType.cs b/src/sqlite/runType.cs
index 57aa8d1..78f52e5 100644
--- a/src/sqlite/runType.cs
+++ b/src/sqlite/runType.cs
@@ -113,7 +113,13 @@ class SqliteRunType : Sqlite
 				t.Name + "', " + Util.ConvertToPoint(t.Distance) + ", '" + t.Description +	"')" ;	
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myLast = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
+
 		if(! dbconOpened) {
 			dbcon.Close();
 		}
@@ -226,6 +232,7 @@ class SqliteRunType : Sqlite
 		while(reader.Read()) {
 			distance = Convert.ToDouble(reader[0].ToString());
 		}
+		reader.Close();
 		dbcon.Close();
 		return distance;
 	}
@@ -351,7 +358,13 @@ class SqliteRunIntervalType : SqliteRunType
 				Util.BoolToInt(t.Unlimited) + 	", '" + t.Description +	"', '" + t.DistancesString + 	"')" ;	
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myLast = -10000; //dbcon.LastInsertRowId;
+		
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
+
 		if(! dbconOpened) {
 			dbcon.Close();
 		}
diff --git a/src/sqlite/server.cs b/src/sqlite/server.cs
index 4d692bc..a798975 100644
--- a/src/sqlite/server.cs
+++ b/src/sqlite/server.cs
@@ -82,12 +82,17 @@ class SqliteServer : Sqlite
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		
 		dbcmd.ExecuteNonQuery();
-		int myReturn = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 
 		if(! dbconOpened)
 			dbcon.Close();
 
-		return myReturn;
+		return myLast;
 	}
 
 	public static int InsertEvaluator(bool dbconOpened, string code, string name, string email, DateTime dateBorn, 
@@ -114,12 +119,18 @@ class SqliteServer : Sqlite
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		
 		dbcmd.ExecuteNonQuery();
-		int myReturn = -10000; //dbcon.LastInsertRowId;
+
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 
 		if(! dbconOpened)
 			dbcon.Close();
 
-		return myReturn;
+		return myLast;
 	}
 	
 	public static void UpdateEvaluator(bool dbconOpened, int uniqueID, string code, string name, string email, DateTime dateBorn, 
@@ -175,6 +186,7 @@ class SqliteServer : Sqlite
 			myEval.Confiable = Util.IntToBool(Convert.ToInt32(reader[9].ToString())); 
 		}
 
+		reader.Close();
 		dbcon.Close();
 		return myEval;
 	}
diff --git a/src/sqlite/session.cs b/src/sqlite/session.cs
index 9e9b83a..20e8245 100644
--- a/src/sqlite/session.cs
+++ b/src/sqlite/session.cs
@@ -69,12 +69,17 @@ class SqliteSession : Sqlite
 			serverUniqueID + ")" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myReturn = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 		
 		if(! dbconOpened)
 			dbcon.Close();
 
-		return myReturn;
+		return myLast;
 	}
 
 	public static void Update(int uniqueID, string name, string place, DateTime date, int personsSportID, int personsSpeciallityID, int personsPractice, string comments) 
@@ -617,12 +622,17 @@ class SqliteServerSession : SqliteSession
 			")" ;
 		Log.WriteLine(dbcmd.CommandText.ToString());
 		dbcmd.ExecuteNonQuery();
-		int myReturn = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		string myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 		
 		if(! dbconOpened)
 			dbcon.Close();
 
-		return myReturn;
+		return myLast;
 	}
 	
 	//updating local session when it gets uploaded
diff --git a/src/sqlite/speciallity.cs b/src/sqlite/speciallity.cs
index 0bb7957..6900f3a 100644
--- a/src/sqlite/speciallity.cs
+++ b/src/sqlite/speciallity.cs
@@ -65,12 +65,17 @@ class SqliteSpeciallity : Sqlite
 		
 		dbcmd.CommandText = myString;
 		dbcmd.ExecuteNonQuery();
-		int myReturn = -10000; //dbcon.LastInsertRowId;
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 		
 		if(! dbconOpened)
 			dbcon.Close();
 
-		return myReturn;
+		return myLast;
 	}
 
 	public static string Select(int uniqueID)
diff --git a/src/sqlite/sport.cs b/src/sqlite/sport.cs
index 462bbe8..d0a16e7 100644
--- a/src/sqlite/sport.cs
+++ b/src/sqlite/sport.cs
@@ -70,12 +70,18 @@ class SqliteSport : Sqlite
 		
 		dbcmd.CommandText = myString;
 		dbcmd.ExecuteNonQuery();
-		int myReturn = -10000; //dbcon.LastInsertRowId;
+		
+
+		//int myLast = dbcon.LastInsertRowId;
+		//http://stackoverflow.com/questions/4341178/getting-the-last-insert-id-with-sqlite-net-in-c
+		myString = @"select last_insert_rowid()";
+		dbcmd.CommandText = myString;
+		int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since `ExecuteScalar` returns an object.
 		
 		if(! dbconOpened)
 			dbcon.Close();
 
-		return myReturn;
+		return myLast;
 	}
 
 	public static Sport Select(int uniqueID)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]