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

 1098 Reggie Burnett	2011-12-16 [merge]
      merged

    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 23:39:51 +0000
+++ b/Source/MySql.Data/Types/MySqlDateTime.cs	2011-12-16 22:16:44 +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 23:39:51 +0000
+++ b/Source/MySql.Data/Types/MySqlTime.cs	2011-12-16 22:16:44 +0000
@@ -100,7 +100,6 @@
       }
       else
       {
-
         String s = String.Format("'{0}{1} {2:00}:{3:00}:{4:00}.{5}'",
           negative ? "-" : "", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
 
@@ -185,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;
@@ -209,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 23:39:51 +0000
+++ b/Tests/MySql.Data.Tests/DateTimeTests.cs	2011-12-16 22:16:44 +0000
@@ -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-20111216221644-0znp0iuc4dii7c8j.bundle
Thread
bzr commit into connector-net-6.4 branch (reggie.burnett:1098) Reggie Burnett19 Dec