Modified:
branches/5.0/CHANGES
branches/5.0/Driver/Source/Types/MySqlDateTime.cs
branches/5.0/TestSuite/Source/DateTimeTests.cs
Log:
fixed MySqlDateTime.ToString() to properly return the date value (Bug #32010)
The problem was that we were using the defined date/time format strings with String.Format and that doesn't work. To fix it we had to write our own custom formatting function that handled parts like MM, dd, and yyyy.
Modified: branches/5.0/CHANGES
===================================================================
--- branches/5.0/CHANGES 2007-11-01 14:57:10 UTC (rev 1049)
+++ branches/5.0/CHANGES 2007-11-01 17:17:58 UTC (rev 1050)
@@ -19,6 +19,7 @@
used the wrong case for a user id and then fixed it to still get access denied
errors. (Bug #31433)
- improved the speed of load data local infile significantly
+ - fixed MySqlDateTime.ToString() to properly return the date value (Bug #32010)
Version 5.0.8 8/16/2007
Modified: branches/5.0/Driver/Source/Types/MySqlDateTime.cs
===================================================================
--- branches/5.0/Driver/Source/Types/MySqlDateTime.cs 2007-11-01 14:57:10 UTC (rev 1049)
+++ branches/5.0/Driver/Source/Types/MySqlDateTime.cs 2007-11-01 17:17:58 UTC (rev 1050)
@@ -408,6 +408,23 @@
return new DateTime(year, month, day, hour, minute, second);
}
+ private string FormatDateCustom(string format, int monthVal, int dayVal, int yearVal)
+ {
+ format = format.Replace("MM", "{0:00}");
+ format = format.Replace("M", "{0}");
+ format = format.Replace("dd", "{1:00}");
+ format = format.Replace("d", "{1}");
+ format = format.Replace("yyyy", "{2:0000}");
+ format = format.Replace("yy", "{3:00}");
+ format = format.Replace("y", "{4:0}");
+
+ int year2digit = yearVal - ((yearVal / 1000) * 1000);
+ year2digit -= ((year2digit / 100) * 100);
+ int year1digit = year2digit - ((year2digit / 10) * 10);
+
+ return String.Format(format, monthVal, dayVal, yearVal, year2digit, year1digit);
+ }
+
/// <summary>Returns a MySQL specific string representation of this value</summary>
public override string ToString()
{
@@ -417,12 +434,14 @@
return (type == MySqlDbType.Date) ? d.ToString("d") : d.ToString();
}
+ string dateString = FormatDateCustom(
+ CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern, month, day, year);
if (type == MySqlDbType.Date)
- return String.Format(CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern,
- year, month, day);
+ return dateString;
- return String.Format(CultureInfo.CurrentUICulture.DateTimeFormat.FullDateTimePattern,
- year, month, day, hour, minute, second);
+ DateTime dt = new DateTime(1, 2, 3, hour, minute, second);
+ dateString = String.Format("{0} {1}", dateString, dt.ToLongTimeString());
+ return dateString;
}
/// <summary></summary>
Modified: branches/5.0/TestSuite/Source/DateTimeTests.cs
===================================================================
--- branches/5.0/TestSuite/Source/DateTimeTests.cs 2007-11-01 14:57:10 UTC (rev 1049)
+++ branches/5.0/TestSuite/Source/DateTimeTests.cs 2007-11-01 17:17:58 UTC (rev 1050)
@@ -152,6 +152,7 @@
[Test]
public void TestAllowZeroDateTime()
{
+ execSQL("TRUNCATE TABLE Test");
execSQL("INSERT INTO Test (id, d, dt) VALUES (1, '0000-00-00', '0000-00-00 00:00:00')");
MySqlConnection c = new MySqlConnection(
@@ -183,6 +184,7 @@
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", c);
MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
da.Fill(dt);
+
dt.Rows[0]["id"] = 2;
DataRow row = dt.NewRow();
row["id"] = 3;
@@ -463,6 +465,17 @@
c.Close();
}
}
+
+ /// <summary>
+ /// Bug #32010 Connector return incorrect value when pulling 0 datetime
+ /// </summary>
+ [Test]
+ public void MySqlDateTimeFormatting()
+ {
+ DateTime dt = DateTime.Now;
+ MySqlDateTime mdt = new MySqlDateTime(dt);
+ Assert.AreEqual(dt.ToString(), mdt.ToString());
+ }
}
}
| Thread |
|---|
| • Connector/NET commit: r1050 - in branches/5.0: . Driver/Source/Types TestSuite/Source | rburnett | 1 Nov |