From: Date: September 22 2007 12:23am Subject: Connector/NET commit: r1022 - in branches/1.0: . TestSuite mysqlclient List-Archive: http://lists.mysql.com/commits/34470 X-Bug: 30964 Message-Id: <200709212223.l8LMNo82003220@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/1.0/CHANGES branches/1.0/TestSuite/ConnectionTests.cs branches/1.0/mysqlclient/Connection.cs branches/1.0/mysqlclient/datareader.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/1.0/CHANGES =================================================================== --- branches/1.0/CHANGES 2007-09-21 22:22:20 UTC (rev 1021) +++ branches/1.0/CHANGES 2007-09-21 22:23:49 UTC (rev 1022) @@ -4,6 +4,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 1.0.10 Bugs Modified: branches/1.0/TestSuite/ConnectionTests.cs =================================================================== --- branches/1.0/TestSuite/ConnectionTests.cs 2007-09-21 22:22:20 UTC (rev 1021) +++ branches/1.0/TestSuite/ConnectionTests.cs 2007-09-21 22:23:49 UTC (rev 1022) @@ -339,5 +339,30 @@ Assert.Fail(e.Message); } } + + /// + /// 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); + } + } } } Modified: branches/1.0/mysqlclient/Connection.cs =================================================================== --- branches/1.0/mysqlclient/Connection.cs 2007-09-21 22:22:20 UTC (rev 1021) +++ branches/1.0/mysqlclient/Connection.cs 2007-09-21 22:23:49 UTC (rev 1022) @@ -265,11 +265,11 @@ settings.Database = databaseName; } - internal void SetState(ConnectionState newState) + internal void SetState(ConnectionState newState, bool broadcast) { ConnectionState oldState = state; state = newState; - if (this.StateChange != null) + if (this.StateChange != null && broadcast) StateChange(this, new StateChangeEventArgs(oldState, newState)); } @@ -291,7 +291,7 @@ if (state == ConnectionState.Open) throw new InvalidOperationException(Resources.ConnectionAlreadyOpen); - SetState(ConnectionState.Connecting); + SetState(ConnectionState.Connecting, true); try { @@ -309,7 +309,7 @@ } catch (Exception) { - SetState(ConnectionState.Closed); + SetState(ConnectionState.Closed, true); throw; } @@ -317,11 +317,12 @@ 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.Length != 0) ChangeDatabase(settings.Database); hasBeenOpen = true; + SetState(ConnectionState.Open, true); } internal void Terminate() @@ -335,7 +336,7 @@ } catch (Exception) { } - SetState(ConnectionState.Closed); + SetState(ConnectionState.Closed, true); } /// Modified: branches/1.0/mysqlclient/datareader.cs =================================================================== --- branches/1.0/mysqlclient/datareader.cs 2007-09-21 22:22:20 UTC (rev 1021) +++ branches/1.0/mysqlclient/datareader.cs 2007-09-21 22:23:49 UTC (rev 1022) @@ -677,7 +677,7 @@ // When executing query statements, the result byte that is returned // from MySql is the column count. That is why we reference the LastResult // property here to dimension our field array - connection.SetState(ConnectionState.Fetching); + connection.SetState(ConnectionState.Fetching, true); // load in our field defs and set our internal variables so we know // what we can do (canRead, hasRows) @@ -688,7 +688,7 @@ catch (Exception ex) { if (ex is MySqlException && !(ex as MySqlException).IsFatal) - connection.SetState(ConnectionState.Open); + connection.SetState(ConnectionState.Open, true); else connection.Terminate(); throw; @@ -696,7 +696,7 @@ finally { if (connection.State != ConnectionState.Closed && connection.State != ConnectionState.Open) - connection.SetState(ConnectionState.Open); + connection.SetState(ConnectionState.Open, true); } } @@ -712,7 +712,7 @@ if (!canRead) return false; readCount++; - connection.SetState(ConnectionState.Fetching); + connection.SetState(ConnectionState.Fetching, true); try { @@ -743,7 +743,7 @@ } finally { - connection.SetState(ConnectionState.Open); + connection.SetState(ConnectionState.Open, true); } return true; }