MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Vladislav Vaintroub Date:October 7 2010 9:02pm
Subject:bzr commit into connector-net-6.0 branch (vvaintroub:840) Bug#57265
View as plain text  
#At file:///H:/connector_net/6.0/ based on revid:vvaintroub@stripped

  840 Vladislav Vaintroub	2010-10-07
      Bug #57265 CommandTimeout = 0 does not work.
           
      Fix : change the behavior of propertyl  MySqlCommand.CommandTimeout to return default value
      30 if and only if it was never set and there is no connection associated with the command. 
      Do not treat value 0 as special indicator for "timeout was never assigned".

    modified:
      MySql.Data/Provider/Source/command.cs
      MySql.Data/Tests/Source/CommandTests.cs
      MySql.Data/Tests/Source/TimeoutAndCancel.cs
=== modified file 'MySql.Data/Provider/Source/command.cs'
--- a/MySql.Data/Provider/Source/command.cs	2010-06-17 00:19:33 +0000
+++ b/MySql.Data/Provider/Source/command.cs	2010-10-07 21:02:45 +0000
@@ -57,6 +57,7 @@ namespace MySql.Data.MySqlClient
         private bool resetSqlSelect;
         List<MySqlCommand> batch;
         private string batchableCommandText;
+        private bool useDefaultTimeout;
 
 		/// <include file='docs/mysqlcommand.xml' path='docs/ctor1/*'/>
 		public MySqlCommand()
@@ -66,6 +67,7 @@ namespace MySql.Data.MySqlClient
 			parameters = new MySqlParameterCollection(this);
 			updatedRowSource = UpdateRowSource.Both;
 			cmdText = String.Empty;
+			useDefaultTimeout = true;
 		}
 
 		/// <include file='docs/mysqlcommand.xml' path='docs/ctor2/*'/>
@@ -138,8 +140,12 @@ namespace MySql.Data.MySqlClient
 #endif
 		public override int CommandTimeout
 		{
-			get { return commandTimeout == 0 ? 30 : commandTimeout; }
-			set { commandTimeout = value; }
+			get { return useDefaultTimeout ? 30 : commandTimeout; }
+			set 
+			{
+				commandTimeout = value;
+				useDefaultTimeout = false;
+			}
 		}
 
 		/// <include file='docs/mysqlcommand.xml' path='docs/CommandType/*'/>
@@ -183,8 +189,12 @@ namespace MySql.Data.MySqlClient
 
                 // if the user has not already set the command timeout, then
                 // take the default from the connection
-                if (connection != null && commandTimeout == 0)
+                if (connection != null && useDefaultTimeout)
+                {
                     commandTimeout = (int)connection.Settings.DefaultCommandTimeout;
+                    useDefaultTimeout = false;
+                }
+
 			}
 		}
 
@@ -446,6 +456,7 @@ namespace MySql.Data.MySqlClient
                 }
                 catch (Exception) { }
 
+
                 // if we caught an exception because of a cancel, then just return null
                 if (ex.IsQueryAborted)
                 {

=== modified file 'MySql.Data/Tests/Source/CommandTests.cs'
--- a/MySql.Data/Tests/Source/CommandTests.cs	2010-02-12 18:11:12 +0000
+++ b/MySql.Data/Tests/Source/CommandTests.cs	2010-10-07 21:02:45 +0000
@@ -343,6 +343,12 @@ namespace MySql.Data.MySqlClient.Tests
             cmd.CommandTimeout = 66;
             cmd.Connection = c;
             Assert.AreEqual(66, cmd.CommandTimeout);
+            cmd.CommandTimeout = 0;
+            Assert.AreEqual(0, cmd.CommandTimeout);
+
+            c = new MySqlConnection("server=localhost;default command timeout=0");
+            cmd = new MySqlCommand("", c);
+            Assert.AreEqual(0, cmd.CommandTimeout);
         }
 
         /// <summary>

=== modified file 'MySql.Data/Tests/Source/TimeoutAndCancel.cs'
--- a/MySql.Data/Tests/Source/TimeoutAndCancel.cs	2009-08-31 19:32:51 +0000
+++ b/MySql.Data/Tests/Source/TimeoutAndCancel.cs	2010-10-07 21:02:45 +0000
@@ -131,7 +131,9 @@ namespace MySql.Data.MySqlClient.Tests
                 cmd.Parameters.AddWithValue("duration", 60);
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.CommandTimeout = 5;
+                DateTime t0 = DateTime.Now;
                 cmd.ExecuteNonQuery();
+                Console.WriteLine("execution took " + (DateTime.Now.Ticks - t0.Ticks));
                 Assert.Fail("Should not get to this point");
             }
             catch (MySqlException ex)
@@ -160,6 +162,16 @@ namespace MySql.Data.MySqlClient.Tests
             cmd.ExecuteNonQuery();
         }
 
+         [Test]
+        public void TimeoutNotExpiring2()
+        {
+            if (Version < new Version(5, 0)) return;
+
+            MySqlCommand cmd = new MySqlCommand("SELECT SLEEP(1)", conn);
+            cmd.CommandTimeout = 0; // infinite timeout
+            cmd.ExecuteNonQuery();
+        }
+
         [Test]
         public void TimeoutDuringBatch()
         {


Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20101007210245-g2r1am9cv4hqmh76.bundle
Thread
bzr commit into connector-net-6.0 branch (vvaintroub:840) Bug#57265Vladislav Vaintroub7 Oct