Modified:
branches/5.0/CHANGES
branches/5.0/Driver/Source/Types/MySqlDateTime.cs
branches/5.0/TestSuite/Source/CultureTests.cs
Log:
Fixed bug where Connecor/Net was hand building some date time patterns rather than using
the patterns provided under CultureInfo. This caused problems with some calendars that
do not support the same ranges as Gregorian. (Bug #29931)
Modified: branches/5.0/CHANGES
===================================================================
--- branches/5.0/CHANGES 2007-07-20 19:09:22 UTC (rev 795)
+++ branches/5.0/CHANGES 2007-07-20 20:14:04 UTC (rev 796)
@@ -24,6 +24,9 @@
- Fixed problem where a command timing out just after it actually finished would cause
an exception to be thrown on the command timeout thread which would then be seen
as an unhandled exception.
+ - Fixed bug where Connecor/Net was hand building some date time patterns rather than
using
+ the patterns provided under CultureInfo. This caused problems with some calendars
that do
+ not support the same ranges as Gregorian. (Bug #29931)
Version 5.0.7 5/16/2007
Modified: branches/5.0/Driver/Source/Types/MySqlDateTime.cs
===================================================================
--- branches/5.0/Driver/Source/Types/MySqlDateTime.cs 2007-07-20 19:09:22 UTC (rev 795)
+++ branches/5.0/Driver/Source/Types/MySqlDateTime.cs 2007-07-20 20:14:04 UTC (rev 796)
@@ -22,6 +22,7 @@
using System.Data;
using System.IO;
using MySql.Data.MySqlClient;
+using System.Globalization;
namespace MySql.Data.Types
{
@@ -35,8 +36,6 @@
private MySqlDbType type;
private int year, month, day, hour, minute, second;
private int millisecond;
- private static string fullPattern;
- private static string shortPattern;
public MySqlDateTime(int year, int month, int day, int hour, int minute, int second)
: this(MySqlDbType.Datetime, year, month, day, hour, minute, second)
@@ -78,9 +77,6 @@
this.minute = minute;
this.second = second;
this.millisecond = 0;
-
- if (fullPattern == null)
- ComposePatterns();
}
internal MySqlDateTime(MySqlDbType type, bool isNull)
@@ -418,52 +414,14 @@
return (type == MySqlDbType.Date) ? d.ToString("d") : d.ToString();
}
- if (type == MySqlDbType.Date)
- return String.Format(shortPattern, year, month, day);
+ if (type == MySqlDbType.Date)
+ return
String.Format(CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern,
+ year, month, day);
- if (hour >= 12)
- fullPattern = fullPattern.Replace("A", "P");
- return String.Format(fullPattern, year, month, day, hour, minute, second);
- }
+ return
String.Format(CultureInfo.CurrentUICulture.DateTimeFormat.FullDateTimePattern,
+ year, month, day, hour, minute, second);
+ }
- private void ComposePatterns()
- {
- DateTime tempDT = new DateTime(1, 2, 3, 4, 5, 6);
- fullPattern = tempDT.ToString();
- fullPattern = fullPattern.Replace("0001", "{0:0000}");
- if (fullPattern.IndexOf("02") != -1)
- fullPattern = fullPattern.Replace("02", "{1:00}");
- else
- fullPattern = fullPattern.Replace("2", "{1}");
- if (fullPattern.IndexOf("03") != -1)
- fullPattern = fullPattern.Replace("03", "{2:00}");
- else
- fullPattern = fullPattern.Replace("3", "{2}");
- if (fullPattern.IndexOf("04") != -1)
- fullPattern = fullPattern.Replace("04", "{3:00}");
- else
- fullPattern = fullPattern.Replace("4", "{3}");
- if (fullPattern.IndexOf("05") != -1)
- fullPattern = fullPattern.Replace("05", "{4:00}");
- else
- fullPattern = fullPattern.Replace("5", "{4}");
- if (fullPattern.IndexOf("06") != -1)
- fullPattern = fullPattern.Replace("06", "{5:00}");
- else
- fullPattern = fullPattern.Replace("6", "{5}");
-
- shortPattern = tempDT.ToString("d");
- shortPattern = shortPattern.Replace("0001", "{0:0000}");
- if (shortPattern.IndexOf("02") != -1)
- shortPattern = shortPattern.Replace("02", "{1:00}");
- else
- shortPattern = shortPattern.Replace("2", "{1}");
- if (shortPattern.IndexOf("03") != -1)
- shortPattern = shortPattern.Replace("03", "{2:00}");
- else
- shortPattern = shortPattern.Replace("3", "{2}");
- }
-
/// <summary></summary>
/// <param name="val"></param>
/// <returns></returns>
@@ -479,8 +437,6 @@
if (DateTime.IsLeapYear(Year))
daysInMonths[1]++;
-
-
}
internal static void SetDSInfo(DataTable dsTable)
Modified: branches/5.0/TestSuite/Source/CultureTests.cs
===================================================================
--- branches/5.0/TestSuite/Source/CultureTests.cs 2007-07-20 19:09:22 UTC (rev 795)
+++ branches/5.0/TestSuite/Source/CultureTests.cs 2007-07-20 20:14:04 UTC (rev 796)
@@ -130,5 +130,41 @@
Thread.CurrentThread.CurrentCulture = curCulture;
Thread.CurrentThread.CurrentUICulture = curUICulture;
}
- }
+
+ /// <summary>
+ /// Bug #29931 Connector/NET does not handle Saudi Hijri calendar correctly
+ /// </summary>
+ [Test]
+ public void ArabicCalendars()
+ {
+ execSQL("DROP TABLE IF EXISTS test");
+ execSQL("CREATE TABLE test(dt DATETIME)");
+ execSQL("INSERT INTO test VALUES ('2007-01-01 12:30:45')");
+
+ CultureInfo curCulture = Thread.CurrentThread.CurrentCulture;
+ CultureInfo curUICulture = Thread.CurrentThread.CurrentUICulture;
+ CultureInfo c = new CultureInfo("ar-SA");
+ Thread.CurrentThread.CurrentCulture = c;
+ Thread.CurrentThread.CurrentUICulture = c;
+
+ try
+ {
+ MySqlCommand cmd = new MySqlCommand("SELECT dt FROM test", conn);
+ DateTime dt = (DateTime)cmd.ExecuteScalar();
+ Assert.AreEqual(2007, dt.Year);
+ Assert.AreEqual(1, dt.Month);
+ Assert.AreEqual(1, dt.Day);
+ Assert.AreEqual(12, dt.Hour);
+ Assert.AreEqual(30, dt.Minute);
+ Assert.AreEqual(45, dt.Second);
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail(ex.Message);
+ }
+
+ Thread.CurrentThread.CurrentCulture = curCulture;
+ Thread.CurrentThread.CurrentUICulture = curUICulture;
+ }
+ }
}
| Thread |
|---|
| • Connector/NET commit: r796 - in branches/5.0: . Driver/Source/Types TestSuite/Source | rburnett | 20 Jul |