List:Commits« Previous MessageNext Message »
From:rburnett Date:January 30 2007 10:48pm
Subject:Connector/NET commit: r570 - in branches/5.0: . Driver/Source/Types TestSuite
View as plain text  
Modified:
   branches/5.0/CHANGES
   branches/5.0/Driver/Source/Types/MySqlTime.cs
   branches/5.0/TestSuite/DataTypeTests.cs
Log:
Bug #25912 selecting negative time values gets wrong results 

The problem here is that we are using a TimeSpan struct to hold time values.  The ctor for
TimeSpan applies each value to the total time value.  So passing in -7 hours along with a
positive 24 minutes results in -7 hours + 24 minutes which is -6 hours and 36 minutes. 
The fix was to negate each value if the hours value is negative.

Modified: branches/5.0/CHANGES
===================================================================
--- branches/5.0/CHANGES	2007-01-30 18:57:14 UTC (rev 569)
+++ branches/5.0/CHANGES	2007-01-30 21:48:56 UTC (rev 570)
@@ -11,6 +11,7 @@
   Bug #25726 MySqlConnection throws NullReferenceException and ArgumentNullException 
   Bug #25609 MySqlDataAdapter.FillSchema 
   Bug #25928 Invalid Registry Entries 
+  Bug #25912 selecting negative time values gets wrong results 
   
   Other changes
   -------------

Modified: branches/5.0/Driver/Source/Types/MySqlTime.cs
===================================================================
--- branches/5.0/Driver/Source/Types/MySqlTime.cs	2007-01-30 18:57:14 UTC (rev 569)
+++ branches/5.0/Driver/Source/Types/MySqlTime.cs	2007-01-30 21:48:56 UTC (rev 570)
@@ -187,6 +187,11 @@
 			int hours = Int32.Parse(parts[0]);
 			int mins = Int32.Parse(parts[1]);
 			int secs = Int32.Parse(parts[2]);
+            if (hours < 0)
+            {
+                mins *= -1;
+                secs *= -1;
+            }
 			int days = hours / 24;
 			hours = hours - (days * 24);
 			mValue = new TimeSpan(days, hours, mins, secs, 0);

Modified: branches/5.0/TestSuite/DataTypeTests.cs
===================================================================
--- branches/5.0/TestSuite/DataTypeTests.cs	2007-01-30 18:57:14 UTC (rev 569)
+++ branches/5.0/TestSuite/DataTypeTests.cs	2007-01-30 21:48:56 UTC (rev 570)
@@ -247,18 +247,18 @@
 				object value = reader["tm"];
 				Assert.AreEqual( value.GetType(), typeof(TimeSpan));
 				TimeSpan ts = (TimeSpan)reader["tm"];
-				Assert.AreEqual( 0, ts.Hours );
-				Assert.AreEqual( 0, ts.Minutes );
-				Assert.AreEqual( 0, ts.Seconds );
+				Assert.AreEqual(0, ts.Hours);
+				Assert.AreEqual(0, ts.Minutes);
+				Assert.AreEqual(0, ts.Seconds);
 
 				reader.Read();
 				value = reader["tm"];
 				Assert.AreEqual( value.GetType(), typeof(TimeSpan));
 				ts = (TimeSpan)reader["tm"];
-				Assert.AreEqual( 21, ts.Days );
-				Assert.AreEqual( 8, ts.Hours );
-				Assert.AreEqual( 45, ts.Minutes );
-				Assert.AreEqual( 17, ts.Seconds );
+				Assert.AreEqual(21, ts.Days);
+				Assert.AreEqual(8, ts.Hours);
+				Assert.AreEqual(45, ts.Minutes);
+				Assert.AreEqual(17, ts.Seconds);
 			
 				reader.Close();
 			}
@@ -714,5 +714,24 @@
             }
 		}
 
+        /// <summary>
+        /// Bug #25912 selecting negative time values gets wrong results 
+        /// </summary>
+        [Test]
+        public void TestNegativeTime()
+        {
+            execSQL("DROP TABLE IF EXISTS test");
+            execSQL("CREATE TABLE test (t time)");
+            execSQL("INSERT INTO test SET T='-07:24:00'");
+
+            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM test", conn);
+            DataTable dt = new DataTable();
+            da.Fill(dt);
+
+            TimeSpan ts = (TimeSpan)dt.Rows[0]["t"];
+            Assert.AreEqual(-7, ts.Hours);
+            Assert.AreEqual(-24, ts.Minutes);
+            Assert.AreEqual(0, ts.Seconds);
+        }
 	}
 }

Thread
Connector/NET commit: r570 - in branches/5.0: . Driver/Source/Types TestSuiterburnett30 Jan