From: rburnett Date: September 21 2007 10:22pm Subject: Connector/NET commit: r1021 - in branches/5.0: . Driver/Source TestSuite/Source List-Archive: http://lists.mysql.com/commits/34469 X-Bug: 30964 Message-Id: <200709212222.l8LMMM7r002970@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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)); } /// @@ -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); } /// @@ -482,7 +484,7 @@ driver.Close(); } catch (Exception) { } - SetState(ConnectionState.Closed); + SetState(ConnectionState.Closed, true); } /// @@ -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 @@ } } } + + /// + /// Bug #30964 StateChange imperfection + /// + 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); + } + } } }