MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:rburnett Date:September 26 2006 11:05pm
Subject:Connector/NET commit: r366 - in branches/1.0: . TestSuite mysqlclient mysqlclient/Types
View as plain text  
Modified:
   branches/1.0/CHANGES
   branches/1.0/TestSuite/DateTimeTests.cs
   branches/1.0/mysqlclient/Types/MySqlDateTime.cs
   branches/1.0/mysqlclient/datareader.cs
Log:
Bug #9619 Cannot update row using DbDataAdapter when row contains an invalid date 



Modified: branches/1.0/CHANGES
===================================================================
--- branches/1.0/CHANGES	2006-09-26 22:59:31 UTC (rev 365)
+++ branches/1.0/CHANGES	2006-09-26 23:05:49 UTC (rev 366)
@@ -33,6 +33,7 @@
 	Bug #14592 Wrong column length returned for VARCHAR UTF8 columns 	
 	Bug #18391 Better error handling for the .NET class "MySqlCommand" needed. 	
 	Bug #8131 Data Adapter doesn't close connection 
+	Bug #9619 Cannot update row using DbDataAdapter when row contains an invalid date 
 	
 x-xx-05 - Version 1.0.7
 

Modified: branches/1.0/TestSuite/DateTimeTests.cs
===================================================================
--- branches/1.0/TestSuite/DateTimeTests.cs	2006-09-26 22:59:31 UTC (rev 365)
+++ branches/1.0/TestSuite/DateTimeTests.cs	2006-09-26 23:05:49 UTC (rev 366)
@@ -149,47 +149,57 @@
 			}
 		}
 
-		[Test]
-		public void TestAllowZeroDateTime()
-		{
-			execSQL("INSERT INTO Test (id, d, dt) VALUES (1, '0000-00-00', '0000-00-00 00:00:00')");
+        /// <summary>
+        /// Bug #9619 Cannot update row using DbDataAdapter when row contains an invalid date 
+        /// </summary>
+        [Test]
+        public void TestAllowZeroDateTime()
+        {
+            execSQL("INSERT INTO Test (id, d, dt) VALUES (1, '0000-00-00', '0000-00-00 00:00:00')");
 
-			MySqlConnection c = new MySqlConnection(
-				conn.ConnectionString + ";pooling=false;AllowZeroDatetime=true" );
-			c.Open();
-			MySqlDataReader reader = null;
-			try 
-			{
-				MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", c);
-				reader = cmd.ExecuteReader();
-				reader.Read();
+            MySqlConnection c = new MySqlConnection(
+                conn.ConnectionString + ";pooling=false;AllowZeroDatetime=true");
+            c.Open();
+            MySqlDataReader reader = null;
+            try
+            {
+                MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", c);
+                reader = cmd.ExecuteReader();
+                reader.Read();
 
-				Assert.IsTrue( reader.GetValue(1) is MySqlDateTime );
-				Assert.IsTrue( reader.GetValue(2) is MySqlDateTime );
+                Assert.IsTrue(reader.GetValue(1) is MySqlDateTime);
+                Assert.IsTrue(reader.GetValue(2) is MySqlDateTime);
 
-				Assert.IsFalse( reader.GetMySqlDateTime(1).IsValidDateTime );
-				Assert.IsFalse( reader.GetMySqlDateTime(2).IsValidDateTime );
+                Assert.IsFalse(reader.GetMySqlDateTime(1).IsValidDateTime);
+                Assert.IsFalse(reader.GetMySqlDateTime(2).IsValidDateTime);
 
-				try 
-				{
-					reader.GetDateTime(1);
-					Assert.Fail("This should not succeed");
-				}
-				catch (MySqlConversionException) {}
+                try
+                {
+                    reader.GetDateTime(1);
+                    Assert.Fail("This should not succeed");
+                }
+                catch (MySqlConversionException) { }
+                reader.Close();
+                reader = null;
 
+                DataTable dt = new DataTable();
+                MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM test", c);
+                MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
+                da.Fill(dt);
+                dt.Rows[0]["id"] = 2;
+                da.Update(dt);
+            }
+            catch (Exception ex)
+            {
+                Assert.Fail(ex.Message);
+            }
+            finally
+            {
+                if (reader != null) reader.Close();
+                c.Close();
+            }
+        }
 
-			}
-			catch (MySqlException ex) 
-			{
-				Assert.Fail( ex.Message );
-			}
-			finally 
-			{
-				if (reader != null) reader.Close();
-				c.Close();
-			}
-		}
-
 		[Test]
 		public void InsertDateTimeValue()
 		{

Modified: branches/1.0/mysqlclient/Types/MySqlDateTime.cs
===================================================================
--- branches/1.0/mysqlclient/Types/MySqlDateTime.cs	2006-09-26 22:59:31 UTC (rev 365)
+++ branches/1.0/mysqlclient/Types/MySqlDateTime.cs	2006-09-26 23:05:49 UTC (rev 366)
@@ -30,7 +30,7 @@
 	/// </summary>
 	public class MySqlDateTime : MySqlValue, IConvertible, IComparable
 	{
-		private int	year, month, day, hour, minute, second;
+        private int year, month, day, hour, minute, second, milli;
 		private static string	fullPattern;
 		private static string	shortPattern;
 
@@ -55,7 +55,7 @@
 				ComposePatterns();
 		}
 
-		internal MySqlDateTime( MySqlDbType type ) 
+		internal MySqlDateTime(MySqlDbType type) 
 		{
 			mySqlDbType = type;
 			objectValue = this;
@@ -69,6 +69,7 @@
 			hour = val.Hour;
 			minute = val.Minute;
 			second = val.Second;
+            milli = val.Millisecond;
 		}
 
 		#region Properties
@@ -126,9 +127,15 @@
 			set { second = value; }
 		}
 
+        public int Millisecond
+        {
+            get { return milli; }
+            set { milli = value; }
+        }
+
 		#endregion
 
-		private void SerializeText( PacketWriter writer, DateTime value ) 
+		private void SerializeText(PacketWriter writer, MySqlDateTime value) 
 		{
 			string val = String.Empty;
 
@@ -146,20 +153,21 @@
 
 		internal override void Serialize(PacketWriter writer, bool binary, object value, int length)
 		{
-			if (value is MySqlDateTime)
-				value = (value as MySqlDateTime).GetDateTime();
+            MySqlDateTime dtValue;
 
-			if (value is string)
-				value = DateTime.Parse((string)value, 
-					System.Globalization.CultureInfo.CurrentCulture);
+            if (value is DateTime)
+                dtValue = new MySqlDateTime((DateTime)value, MySqlDbType);
+            else if (value is string)
+                dtValue = new MySqlDateTime(DateTime.Parse((string)value,
+                    System.Globalization.CultureInfo.CurrentCulture), MySqlDbType);
+            else if (value is MySqlDateTime)
+                dtValue = (MySqlDateTime)value;
+            else
+				throw new MySqlException("Unable to serialize date/time value.");
 
-			if (! (value is DateTime))
-				throw new MySqlException( "Only DateTime objects can be serialized by MySqlDateTime" );
-
-			DateTime dtValue = (DateTime)value;
 			if (! binary)
 			{
-				SerializeText( writer, dtValue );
+				SerializeText(writer, dtValue);
 				return;
 			}
 
@@ -168,24 +176,24 @@
 			else
 				writer.WriteByte( 7 );
 
-			writer.WriteInteger( dtValue.Year, 2 );
-			writer.WriteByte( (byte)dtValue.Month );
-			writer.WriteByte( (byte)dtValue.Day );
+			writer.WriteInteger(dtValue.Year, 2);
+			writer.WriteByte((byte)dtValue.Month);
+			writer.WriteByte((byte)dtValue.Day);
 			if (mySqlDbType == MySqlDbType.Date) 
 			{
-				writer.WriteByte( 0 );
-				writer.WriteByte( 0 );
-				writer.WriteByte( 0 );
+				writer.WriteByte(0);
+				writer.WriteByte(0);
+				writer.WriteByte(0);
 			}
 			else 
 			{
-				writer.WriteByte( (byte)dtValue.Hour );
-				writer.WriteByte( (byte)dtValue.Minute  );
-				writer.WriteByte( (byte)dtValue.Second );
+				writer.WriteByte((byte)dtValue.Hour);
+				writer.WriteByte((byte)dtValue.Minute);
+				writer.WriteByte((byte)dtValue.Second);
 			}
 			
 			if (mySqlDbType == MySqlDbType.Timestamp)
-				writer.WriteInteger( dtValue.Millisecond, 4 );
+				writer.WriteInteger(dtValue.Millisecond, 4);
 		}
 
 		internal override DbType DbType 

Modified: branches/1.0/mysqlclient/datareader.cs
===================================================================
--- branches/1.0/mysqlclient/datareader.cs	2006-09-26 22:59:31 UTC (rev 365)
+++ branches/1.0/mysqlclient/datareader.cs	2006-09-26 23:05:49 UTC (rev 366)
@@ -377,9 +377,14 @@
 		{
 			if (! isOpen) throw new Exception("No current query in data reader");
 			if (i >= fields.Length) throw new IndexOutOfRangeException();
-			
-			if (currentResult[i] is MySqlDateTime && !connection.Settings.AllowZeroDateTime)
-				return typeof(DateTime);
+
+            if (currentResult[i] is MySqlDateTime)
+            {
+                if (!connection.Settings.AllowZeroDateTime)
+                    return typeof(DateTime);
+                return typeof(MySqlDateTime);
+            }
+
 			return currentResult[i].SystemType;
 		}
 

Thread
Connector/NET commit: r366 - in branches/1.0: . TestSuite mysqlclient mysqlclient/Typesrburnett27 Sep