List:Commits« Previous MessageNext Message »
From:rburnett Date:September 22 2007 12:22am
Subject:Connector/NET commit: r1021 - in branches/5.0: . Driver/Source TestSuite/Source
View as plain text  
Modified:
   branches/5.0/CHANGES
   branches/5.0/Driver/Source/Connection.cs
   branches/5.0/TestSuite/Source/ConnectionTests.cs
Log:
Fixed problem that prevented commands from being executed from the state change handler.  Not sure why you would want to do this but...  (bug #30964)


Modified: branches/5.0/CHANGES
===================================================================
--- branches/5.0/CHANGES	2007-09-21 21:28:22 UTC (rev 1020)
+++ branches/5.0/CHANGES	2007-09-21 22:22:20 UTC (rev 1021)
@@ -5,6 +5,8 @@
   - Changed from using Array.Copy to Buffer.BlockCopy in MySqlDataReader.GetBytes.  This
     helps with memory usage as we expect the source and destination arrays to not be overlapping.
     (Bug #31090)
+  - Fixed problem that prevented commands from being executed from the state change
+    handler.  Not sure why you would want to do this but...  (bug #30964)
 
 Version 5.0.8   8/16/2007
 

Modified: branches/5.0/Driver/Source/Connection.cs
===================================================================
--- branches/5.0/Driver/Source/Connection.cs	2007-09-21 21:28:22 UTC (rev 1020)
+++ branches/5.0/Driver/Source/Connection.cs	2007-09-21 22:22:20 UTC (rev 1021)
@@ -352,13 +352,14 @@
             this.database = database;
         }
 
-        internal void SetState(ConnectionState newConnectionState)
+        internal void SetState(ConnectionState newConnectionState, bool broadcast)
         {
             if (newConnectionState == this.connectionState)
                 return;
             ConnectionState oldConnectionState = this.connectionState;
-            this.connectionState = newConnectionState;
-            this.OnStateChange(new StateChangeEventArgs(oldConnectionState, this.connectionState));
+            connectionState = newConnectionState;
+			if (broadcast)
+				OnStateChange(new StateChangeEventArgs(oldConnectionState, this.connectionState));
         }
 
         /// <summary>
@@ -369,7 +370,7 @@
         {
             bool result = driver.Ping();
             if (!result)
-                SetState(ConnectionState.Closed);
+                SetState(ConnectionState.Closed, true);
             return result;
         }
 
@@ -379,7 +380,7 @@
             if (State == ConnectionState.Open)
                 throw new InvalidOperationException(Resources.ConnectionAlreadyOpen);
 
-            SetState(ConnectionState.Connecting);
+            SetState(ConnectionState.Connecting, true);
 
             try
             {
@@ -397,7 +398,7 @@
             }
             catch (Exception)
             {
-                SetState(ConnectionState.Closed);
+                SetState(ConnectionState.Closed, true);
                 throw;
             }
 
@@ -405,7 +406,7 @@
             if (driver.Settings.UseOldSyntax)
                 Logger.LogWarning("You are using old syntax that will be removed in future versions");
 
-            SetState(ConnectionState.Open);
+            SetState(ConnectionState.Open, false);
             driver.Configure(this);
             if (settings.Database != null && settings.Database != String.Empty)
                 ChangeDatabase(settings.Database);
@@ -425,6 +426,7 @@
 #endif
 
             hasBeenOpen = true;
+			SetState(ConnectionState.Open, true);
         }
 
         /// <include file='docs/MySqlConnection.xml' path='docs/CreateCommand/*'/>
@@ -482,7 +484,7 @@
                     driver.Close();
             }
             catch (Exception) { }
-            SetState(ConnectionState.Closed);
+            SetState(ConnectionState.Closed, true);
         }
 
         /// <include file='docs/MySqlConnection.xml' path='docs/Close/*'/>
@@ -507,7 +509,7 @@
             else
                 driver.Close();
 
-            SetState(ConnectionState.Closed);
+            SetState(ConnectionState.Closed, true);
         }
 
 #if MONO2

Modified: branches/5.0/TestSuite/Source/ConnectionTests.cs
===================================================================
--- branches/5.0/TestSuite/Source/ConnectionTests.cs	2007-09-21 21:28:22 UTC (rev 1020)
+++ branches/5.0/TestSuite/Source/ConnectionTests.cs	2007-09-21 22:22:20 UTC (rev 1021)
@@ -385,5 +385,30 @@
 				}
 			}
 		}
+
+		/// <summary>
+		/// Bug #30964 StateChange imperfection 
+		/// </summary>
+		MySqlConnection rqConnection;
+		[Test]
+		public void RunningAQueryFromStateChangeHandler()
+		{
+			string connStr = GetConnectionString(true);
+			using (rqConnection = new MySqlConnection(connStr))
+			{
+				rqConnection.StateChange += new StateChangeEventHandler(RunningQueryStateChangeHandler);
+				rqConnection.Open();
+			}
+		}
+
+		void RunningQueryStateChangeHandler(object sender, StateChangeEventArgs e)
+		{
+			if (e.CurrentState == ConnectionState.Open)
+			{
+				MySqlCommand cmd = new MySqlCommand("SELECT 1", rqConnection);
+				object o = cmd.ExecuteScalar();
+				Assert.AreEqual(1, o);
+			}
+		}
 	}
 }

Thread
Connector/NET commit: r1021 - in branches/5.0: . Driver/Source TestSuite/Sourcerburnett22 Sep