List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:December 16 2011 10:12pm
Subject:bzr commit into connector-net-6.3 branch (reggie.burnett:1108)
View as plain text  
#At file:///C:/work/connector-net/6.3/ based on revid:reggie.burnett@stripped

 1108 Reggie Burnett	2011-12-16
      backing out millseconds work from 6.3

    modified:
      Source/MySql.Data/Types/MySqlDateTime.cs
      Source/MySql.Data/Types/MySqlTime.cs
      Tests/MySql.Data.Tests/DateTimeTests.cs
=== modified file 'Source/MySql.Data/Types/MySqlDateTime.cs'
=== modified file 'Source/MySql.Data/Types/MySqlDateTime.cs'
--- a/Source/MySql.Data/Types/MySqlDateTime.cs	2011-12-15 17:46:53 +0000
+++ b/Source/MySql.Data/Types/MySqlDateTime.cs	2011-12-16 22:12:42 +0000
@@ -26,7 +26,6 @@
 using MySql.Data.MySqlClient;
 using System.Globalization;
 
-
 namespace MySql.Data.Types
 {
 
@@ -50,9 +49,8 @@
     /// <param name="hour">The hour to use.</param>
     /// <param name="minute">The minute to use.</param>
     /// <param name="second">The second to use.</param>
-    /// <param name="millisecond">The millisecond to use.</param>
-    public MySqlDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
-      : this(MySqlDbType.DateTime, year, month, day, hour, minute, second, millisecond)
+    public MySqlDateTime(int year, int month, int day, int hour, int minute, int second)
+      : this(MySqlDbType.DateTime, year, month, day, hour, minute, second)
     {
     }
 
@@ -91,7 +89,7 @@
     }
 
     internal MySqlDateTime(MySqlDbType type, int year, int month, int day, int hour, int minute,
-      int second, int millisecond)
+      int second)
     {
       this.isNull = false;
       this.type = type;
@@ -101,17 +99,17 @@
       this.hour = hour;
       this.minute = minute;
       this.second = second;
-      this.millisecond = millisecond > 0 ? millisecond : 0;
+      this.millisecond = 0;
     }
 
     internal MySqlDateTime(MySqlDbType type, bool isNull)
-      : this(type, 0, 0, 0, 0, 0, 0, 0)
+      : this(type, 0, 0, 0, 0, 0, 0)
     {
       this.isNull = isNull;
     }
 
     internal MySqlDateTime(MySqlDbType type, DateTime val)
-      : this(type, 0, 0, 0, 0, 0, 0, 0)
+      : this(type, 0, 0, 0, 0, 0, 0)
     {
       this.isNull = false;
       year = val.Year;
@@ -261,14 +259,14 @@
 
     void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object value, int length)
     {
-      MySqlDateTime dtValue;      
+      MySqlDateTime dtValue;
 
       string valueAsString = value as string;
 
       if (value is DateTime)
         dtValue = new MySqlDateTime(type, (DateTime)value);
       else if (valueAsString != null)
-        dtValue = MySqlDateTime.Parse(valueAsString);
+        dtValue = new MySqlDateTime(type, DateTime.Parse(valueAsString, CultureInfo.CurrentCulture));
       else if (value is MySqlDateTime)
         dtValue = (MySqlDateTime)value;
       else
@@ -280,7 +278,7 @@
         return;
       }
 
-      if (dtValue.Millisecond > 0)
+      if (type == MySqlDbType.Timestamp)
         packet.WriteByte(11);
       else
         packet.WriteByte(7);
@@ -301,15 +299,8 @@
         packet.WriteByte((byte)dtValue.Second);
       }
 
-      if (dtValue.Millisecond > 0)
-      {
-        long val = dtValue.Millisecond;       
-        for (int x = 0; x < 4; x++)
-        {
-          packet.WriteByte((byte)(val & 0xff));          
-          val >>= 8;          
-        }      
-      }      
+      if (type == MySqlDbType.Timestamp)
+        packet.WriteInteger(dtValue.Millisecond, 4);
     }
 
     static internal MySqlDateTime Parse(string s)
@@ -326,13 +317,13 @@
 
     private MySqlDateTime ParseMySql(string s)
     {
-      string[] parts = s.Split('-', ' ', ':', '/', '.');
+      string[] parts = s.Split('-', ' ', ':', '/');
 
       int year = int.Parse(parts[0]);
       int month = int.Parse(parts[1]);
       int day = int.Parse(parts[2]);
 
-      int hour = 0, minute = 0, second = 0, millisecond = 0;
+      int hour = 0, minute = 0, second = 0;
       if (parts.Length > 3)
       {
         hour = int.Parse(parts[3]);
@@ -340,17 +331,11 @@
         second = int.Parse(parts[5]);
       }
 
-      if (parts.Length > 6)
-      {
-        millisecond = int.Parse(parts[6]);        
-      }
-
-      return new MySqlDateTime(type, year, month, day, hour, minute, second, millisecond);
+      return new MySqlDateTime(type, year, month, day, hour, minute, second);
     }
 
     IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal)
-    {      
-      
+    {
       if (nullVal) return new MySqlDateTime(type, true);
 
       if (length >= 0)
@@ -361,7 +346,8 @@
 
       long bufLength = packet.ReadByte();
       int year = 0, month = 0, day = 0;
-      int hour = 0, minute = 0, second = 0, millisecond = 0;
+      int hour = 0, minute = 0, second = 0;
+
       if (bufLength >= 4)
       {
         year = packet.ReadInteger(2);
@@ -373,16 +359,13 @@
       {
         hour = packet.ReadByte();
         minute = packet.ReadByte();
-        second = packet.ReadByte();       
+        second = packet.ReadByte();
       }
 
       if (bufLength > 7)
-      {
-        millisecond = packet.Read3ByteInt();
-        packet.ReadByte();
-      }
-      
-      return new MySqlDateTime(type, year, month, day, hour, minute, second, millisecond);
+        packet.ReadInteger(4);
+
+      return new MySqlDateTime(type, year, month, day, hour, minute, second);
     }
 
     void IMySqlValue.SkipValue(MySqlPacket packet)
@@ -398,9 +381,8 @@
     {
       if (!IsValidDateTime)
         throw new MySqlConversionException("Unable to convert MySQL date/time value to System.DateTime");
-      if ((millisecond < 0) || (millisecond >= 0x3e8)) millisecond = (int)(millisecond / 0x3e8);
-      
-      return new DateTime(year, month, day, hour, minute, second, millisecond);
+
+      return new DateTime(year, month, day, hour, minute, second);
     }
 
     private static string FormatDateCustom(string format, int monthVal, int dayVal, int yearVal)
@@ -425,7 +407,7 @@
     {
       if (this.IsValidDateTime)
       {
-        DateTime d = new DateTime(year, month, day, hour, minute, second, millisecond);
+        DateTime d = new DateTime(year, month, day, hour, minute, second);
         return (type == MySqlDbType.Date) ? d.ToString("d") : d.ToString();
       }
 
@@ -434,7 +416,7 @@
       if (type == MySqlDbType.Date)
         return dateString;
 
-      DateTime dt = new DateTime(1, 2, 3, hour, minute, second, millisecond);
+      DateTime dt = new DateTime(1, 2, 3, hour, minute, second);
       dateString = String.Format("{0} {1}", dateString, dt.ToLongTimeString());
       return dateString;
     }

=== modified file 'Source/MySql.Data/Types/MySqlTime.cs'
--- a/Source/MySql.Data/Types/MySqlTime.cs	2011-12-15 17:46:53 +0000
+++ b/Source/MySql.Data/Types/MySqlTime.cs	2011-12-16 22:12:42 +0000
@@ -100,8 +100,8 @@
       }
       else
       {
-        String s = String.Format("'{0}{1} {2:00}:{3:00}:{4:00}'",
-            negative ? "-" : "", ts.Days, ts.Hours, ts.Minutes, ts.Seconds);
+        String s = String.Format("'{0}{1} {2:00}:{3:00}:{4:00}.{5}'",
+            negative ? "-" : "", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
 
         packet.WriteStringNoNull(s);
       }
@@ -184,23 +184,16 @@
 
     public override string ToString()
     {
-      return String.Format("{0} {1:00}:{2:00}:{3:00}",
-        mValue.Days, mValue.Hours, mValue.Minutes, mValue.Seconds);
+      return String.Format("{0} {1:00}:{2:00}:{3:00}.{4}",
+        mValue.Days, mValue.Hours, mValue.Minutes, mValue.Seconds, mValue.Milliseconds);
     }
 
     private void ParseMySql(string s)
     {
-  
-      string[] parts = s.Split(':', '.');
+      string[] parts = s.Split(':');
       int hours = Int32.Parse(parts[0]);
       int mins = Int32.Parse(parts[1]);
       int secs = Int32.Parse(parts[2]);
-      int msecs = 0;
-
-      if (parts.Length > 3)
-          msecs = Int32.Parse(parts[3]);
-        
-        
       if (hours < 0 || parts[0].StartsWith("-"))
       {
         mins *= -1;
@@ -208,7 +201,7 @@
       }
       int days = hours / 24;
       hours = hours - (days * 24);
-      mValue = new TimeSpan(days, hours, mins, secs, msecs);
+      mValue = new TimeSpan(days, hours, mins, secs, 0);
       isNull = false;
     }
   }

=== modified file 'Tests/MySql.Data.Tests/DateTimeTests.cs'
--- a/Tests/MySql.Data.Tests/DateTimeTests.cs	2011-12-15 17:46:53 +0000
+++ b/Tests/MySql.Data.Tests/DateTimeTests.cs	2011-12-16 22:12:42 +0000
@@ -1,4 +1,4 @@
-// Copyright © 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+// Copyright (c) 2004-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
 //
 // MySQL Connector/NET is licensed under the terms of the GPLv2
 // <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most 
@@ -40,14 +40,14 @@
     {
       base.Setup();
       execSQL("CREATE TABLE Test (id INT NOT NULL, dt DATETIME, d DATE, " +
-        "t TIME, ts TIMESTAMP, PRIMARY KEY(id))");
+          "t TIME, ts TIMESTAMP, PRIMARY KEY(id))");
     }
 
     [Test]
     public void ConvertZeroDateTime()
     {
       execSQL("INSERT INTO Test VALUES(1, '0000-00-00', '0000-00-00', " +
-        "'00:00:00', NULL)");
+          "'00:00:00', NULL)");
 
       string connStr = this.GetConnectionString(true);
       connStr += ";convert zero datetime=yes";
@@ -100,7 +100,7 @@
     public void DateAdd()
     {
       MySqlCommand cmd = new MySqlCommand("select date_add(?someday, interval 1 hour)",
-        conn);
+          conn);
       DateTime now = DateTime.Now;
       DateTime later = now.AddHours(1);
       later = later.AddMilliseconds(later.Millisecond * -1);
@@ -179,7 +179,7 @@
     public void InsertDateTimeValue()
     {
       using (MySqlConnection c = new MySqlConnection(conn.ConnectionString +
-        ";allow zero datetime=yes"))
+          ";allow zero datetime=yes"))
       {
         c.Open();
         MySqlDataAdapter da = new MySqlDataAdapter("SELECT id, dt FROM Test", c);
@@ -317,32 +317,32 @@
     {
       execSQL("DROP TABLE Test");
       execSQL("CREATE TABLE Test(ID INT NOT NULL AUTO_INCREMENT, " +
-        "SATELLITEID VARCHAR(3) NOT NULL, ANTENNAID INT, AOS_TIMESTAMP DATETIME NOT NULL, " +
-        "TEL_TIMESTAMP DATETIME, LOS_TIMESTAMP DATETIME, PRIMARY KEY (ID))");
+          "SATELLITEID VARCHAR(3) NOT NULL, ANTENNAID INT, AOS_TIMESTAMP DATETIME NOT NULL, " +
+          "TEL_TIMESTAMP DATETIME, LOS_TIMESTAMP DATETIME, PRIMARY KEY (ID))");
       execSQL("INSERT INTO Test VALUES (NULL,'224','0','2005-07-24 00:00:00'," +
-        "'2005-07-24 00:02:00','2005-07-24 00:22:00')");
+          "'2005-07-24 00:02:00','2005-07-24 00:22:00')");
       execSQL("INSERT INTO Test VALUES (NULL,'155','24','2005-07-24 03:00:00'," +
-        "'2005-07-24 03:02:30','2005-07-24 03:20:00')");
+          "'2005-07-24 03:02:30','2005-07-24 03:20:00')");
       execSQL("INSERT INTO Test VALUES (NULL,'094','34','2005-07-24 09:00:00'," +
-        "'2005-07-24 09:00:30','2005-07-24 09:15:00')");
+          "'2005-07-24 09:00:30','2005-07-24 09:15:00')");
       execSQL("INSERT INTO Test VALUES (NULL,'224','54','2005-07-24 12:00:00'," +
-        "'2005-07-24 12:01:00','2005-07-24 12:33:00')");
+          "'2005-07-24 12:01:00','2005-07-24 12:33:00')");
       execSQL("INSERT INTO Test VALUES (NULL,'155','25','2005-07-24 15:00:00'," +
-        "'2005-07-24 15:02:00','2005-07-24 15:22:00')");
+          "'2005-07-24 15:02:00','2005-07-24 15:22:00')");
       execSQL("INSERT INTO Test VALUES (NULL,'094','0','2005-07-24 17:00:00'," +
-        "'2005-07-24 17:02:12','2005-07-24 17:20:00')");
+          "'2005-07-24 17:02:12','2005-07-24 17:20:00')");
       execSQL("INSERT INTO Test VALUES (NULL,'224','24','2005-07-24 19:00:00'," +
-        "'2005-07-24 19:02:00','2005-07-24 19:27:00')");
+          "'2005-07-24 19:02:00','2005-07-24 19:27:00')");
       execSQL("INSERT INTO Test VALUES (NULL,'155','34','2005-07-24 21:00:00'," +
-        "'2005-07-24 21:02:33','2005-07-24 21:22:55')");
+          "'2005-07-24 21:02:33','2005-07-24 21:22:55')");
       execSQL("INSERT INTO Test VALUES (NULL,'094','55','2005-07-24 23:00:00'," +
-        "'2005-07-24 23:00:45','2005-07-24 23:22:23')");
+          "'2005-07-24 23:00:45','2005-07-24 23:22:23')");
 
       DateTime date = DateTime.Parse("7/24/2005", CultureInfo.GetCultureInfo("en-us"));
       StringBuilder sql = new StringBuilder();
       sql.AppendFormat(CultureInfo.InvariantCulture,
-        @"SELECT ID, ANTENNAID, TEL_TIMESTAMP, LOS_TIMESTAMP FROM Test 
-				WHERE TEL_TIMESTAMP >= '{0}'", date.ToString("u"));
+          @"SELECT ID, ANTENNAID, TEL_TIMESTAMP, LOS_TIMESTAMP FROM Test 
+                WHERE TEL_TIMESTAMP >= '{0}'", date.ToString("u"));
       MySqlDataAdapter da = new MySqlDataAdapter(sql.ToString(), conn);
       DataSet dataSet = new DataSet();
       da.Fill(dataSet);
@@ -372,7 +372,7 @@
       execSQL("INSERT INTO Test VALUES(1, Now(), '0000-00-00', NULL, NULL)");
 
       using (MySqlConnection c = new MySqlConnection(
-        conn.ConnectionString + ";pooling=false;AllowZeroDatetime=true"))
+          conn.ConnectionString + ";pooling=false;AllowZeroDatetime=true"))
       {
         c.Open();
 
@@ -427,96 +427,6 @@
         Assert.IsTrue(reader.Read());
       }
     }
-
-    [Test]
-    public void CanUpdateMilliseconds()
-    {
-      if (Version < new Version(5, 6)) return;
-      DateTime dt = DateTime.Now;
-      MySqlCommand cmd = new MySqlCommand();
-
-      execSQL("DROP TABLE Test");
-      execSQL("CREATE TABLE Test (id INT NOT NULL, dt DATETIME(6), d DATE, " +
-        "t TIME, ts TIMESTAMP, PRIMARY KEY(id))");
-
-      cmd.Connection = conn;
-      cmd.CommandText = "INSERT INTO Test VALUES(1, ?dt, NULL, NULL, NULL)";
-      cmd.Parameters.AddWithValue("?dt", dt);
-      cmd.ExecuteNonQuery();
-      
-      //Update value
-      cmd.Parameters.Clear();
-      cmd.Connection = conn;
-      cmd.CommandText = "UPDATE Test SET dt=?dt";
-      cmd.Parameters.Add(new MySqlParameter("?dt", "2011-01-01 12:34:56.123456"));
-      cmd.ExecuteNonQuery();
-      
-      cmd.CommandText = "SELECT dt FROM Test";
-      cmd.Parameters.Clear();
-      cmd.Connection = conn;
-
-      MySqlDataReader rdr = cmd.ExecuteReader();
-
-      while (rdr.Read())
-      {
-        Assert.AreEqual("12:34:56.1230", rdr.GetDateTime(0).ToString("hh:mm:ss.ffff"));      
-      }
-      rdr.Close();
-    }
-
-    [Test]
-    public void CanUpdateMillisecondsWithIgnorePrepareOnFalse()
-    {
-      if (Version < new Version(5, 6)) return;      
-      MySqlCommand cmd = new MySqlCommand();
-
-      using (MySqlConnection c = new MySqlConnection(conn.ConnectionString + ";ignore prepare=False;"))
-      {
-        c.Open();
-
-        execSQL("DROP TABLE Test");
-        execSQL("CREATE TABLE Test (id INT NOT NULL, dt DATETIME(6), d DATE, " +
-          "t TIME, ts TIMESTAMP, PRIMARY KEY(id))");
-
-        cmd.Connection = c;
-        cmd.CommandText = "INSERT INTO Test VALUES(?id, ?dt, NULL, NULL, NULL)";
-        cmd.Parameters.Add(new MySqlParameter("?id", 1));
-
-        MySqlParameter datetimeinsert = new MySqlParameter();
-        datetimeinsert.ParameterName = "?dt";
-        datetimeinsert.MySqlDbType = MySqlDbType.DateTime;
-        datetimeinsert.Value = "2011-01-01 12:34:59.123456";
-        cmd.Parameters.Add(datetimeinsert);
-
-        cmd.Prepare();    
-      
-        cmd.ExecuteNonQuery();
-
-        cmd.Parameters.Clear();
-
-        MySqlParameter datetimepar = new MySqlParameter();
-        datetimepar.ParameterName = "?dt";
-        datetimepar.MySqlDbType = MySqlDbType.DateTime;
-        datetimepar.Value = "1999-01-01 12:34:59.999999";
-
-        cmd.Connection = c;
-        cmd.CommandText = "UPDATE Test SET dt=?dt WHERE id =1";
-        cmd.Parameters.Add(datetimepar);
-        cmd.Prepare();
-        cmd.ExecuteNonQuery();
-
-        cmd.CommandText = "SELECT dt FROM Test WHERE id = 1";
-        cmd.Parameters.Clear();
-        cmd.Connection = c;
-        cmd.Prepare();
-        MySqlDataReader rdr = cmd.ExecuteReader();
-
-        while (rdr.Read())
-        {
-          Assert.AreEqual("12:34:59.9990", rdr.GetDateTime(0).ToString("hh:mm:ss.ffff"));      
-        }
-        rdr.Close();
-      }
-    }
   }
+
 }

Attachment: [text/bzr-bundle] bzr/reggie.burnett@oracle.com-20111216221242-np9vgcda706327xq.bundle
Thread
bzr commit into connector-net-6.3 branch (reggie.burnett:1108) Reggie Burnett19 Dec