From: Date: September 28 2006 5:51pm Subject: Connector/NET commit: r368 - in trunk: . TestSuite mysqlclient/Types List-Archive: http://lists.mysql.com/commits/12738 X-Bug: 15112 Message-Id: <200609281551.k8SFpK4L011688@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: trunk/CHANGES trunk/TestSuite/DateTimeTests.cs trunk/mysqlclient/Types/MySqlDateTime.cs Log: Bug #15112 MySqlDateTime Constructor Added some public constructors to MySqlDateTime. Modified: trunk/CHANGES =================================================================== --- trunk/CHANGES 2006-09-27 20:58:20 UTC (rev 367) +++ trunk/CHANGES 2006-09-28 15:51:19 UTC (rev 368) @@ -79,6 +79,7 @@ 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 + Bug #15112 MySqlDateTime Constructor Version 1.0.7 Modified: trunk/TestSuite/DateTimeTests.cs =================================================================== --- trunk/TestSuite/DateTimeTests.cs 2006-09-27 20:58:20 UTC (rev 367) +++ trunk/TestSuite/DateTimeTests.cs 2006-09-28 15:51:19 UTC (rev 368) @@ -159,6 +159,7 @@ /// /// Bug #9619 Cannot update row using DbDataAdapter when row contains an invalid date + /// Bug #15112 MySqlDateTime Constructor /// [Test] public void TestAllowZeroDateTime() @@ -195,7 +196,21 @@ MySqlCommandBuilder cb = new MySqlCommandBuilder(da); da.Fill(dt); dt.Rows[0]["id"] = 2; + DataRow row = dt.NewRow(); + row["id"] = 3; + row["d"] = new MySqlDateTime("2003-9-24"); + row["dt"] = new MySqlDateTime("0000/0/00 00:00:00"); + dt.Rows.Add(row); + da.Update(dt); + + dt.Clear(); + da.Fill(dt); + Assert.AreEqual(2, dt.Rows.Count); + MySqlDateTime date = (MySqlDateTime)dt.Rows[1]["d"]; + Assert.AreEqual(2003, date.Year); + Assert.AreEqual(9, date.Month); + Assert.AreEqual(24, date.Day); } catch (Exception ex) { Modified: trunk/mysqlclient/Types/MySqlDateTime.cs =================================================================== --- trunk/mysqlclient/Types/MySqlDateTime.cs 2006-09-27 20:58:20 UTC (rev 367) +++ trunk/mysqlclient/Types/MySqlDateTime.cs 2006-09-28 15:51:19 UTC (rev 368) @@ -38,7 +38,33 @@ 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) + { + } + public MySqlDateTime(DateTime dt) + : this(MySqlDbType.Datetime, dt) + { + } + + public MySqlDateTime(MySqlDateTime mdt) + { + year = mdt.Year; + month = mdt.Month; + day = mdt.Day; + hour = mdt.Hour; + minute = mdt.Minute; + second = mdt.Second; + millisecond = 0; + type = MySqlDbType.Datetime; + isNull = false; + } + + public MySqlDateTime(string s) : this(MySqlDateTime.Parse(s)) + { + } + internal MySqlDateTime(MySqlDbType type, int year, int month, int day, int hour, int minute, int second) { @@ -295,6 +321,12 @@ minute, second); } + static internal MySqlDateTime Parse(string s) + { + MySqlDateTime dt = new MySqlDateTime(); + return dt.ParseMySql(s, true); + } + static internal MySqlDateTime Parse(string s, Common.DBVersion version) { MySqlDateTime dt = new MySqlDateTime(); @@ -306,7 +338,7 @@ if (type == MySqlDbType.Timestamp && ! is41) return Parse40Timestamp(s); - string[] parts = s.Split( '-', ' ', ':' ); + string[] parts = s.Split( '-', ' ', ':', '/' ); int year = int.Parse(parts[0]); int month = int.Parse(parts[1]); @@ -429,7 +461,6 @@ shortPattern = shortPattern.Replace("3", "{2}" ); } - /// /// ///