List:Commits« Previous MessageNext Message »
From:rburnett Date:May 21 2009 6:16pm
Subject:Connector/NET commit: r1617 - in branches/6.0: . MySql.Data/Provider/Source MySql.Data/Provider/Source/Types MySql.Data/Tests/Source
View as plain text  
Modified:
   branches/6.0/CHANGES
   branches/6.0/MySql.Data/Provider/Source/Types/MySqlGuid.cs
   branches/6.0/MySql.Data/Provider/Source/datareader.cs
   branches/6.0/MySql.Data/Tests/Source/DataTypeTests.cs
Log:
- fixed regression where a user could no longer call GetBytes on a guid column (bug #44507)


Modified: branches/6.0/CHANGES
===================================================================
--- branches/6.0/CHANGES	2009-05-20 15:54:30 UTC (rev 1616)
+++ branches/6.0/CHANGES	2009-05-21 18:16:16 UTC (rev 1617)
@@ -2,6 +2,7 @@
 - fixed regression where using stored procs with datasets (bug #44460)
 - fixed compilation under VS 2005 (bug #44822)
 - fixed support for bool data type in entity framework support
+- fixed regression where a user could no longer call GetBytes on a guid column (bug #44507)
 
 Version 6.0.3 - 4/22/09
 - fixed broken connection prompting

Modified: branches/6.0/MySql.Data/Provider/Source/Types/MySqlGuid.cs
===================================================================
--- branches/6.0/MySql.Data/Provider/Source/Types/MySqlGuid.cs	2009-05-20 15:54:30 UTC (rev 1616)
+++ branches/6.0/MySql.Data/Provider/Source/Types/MySqlGuid.cs	2009-05-21 18:16:16 UTC (rev 1617)
@@ -30,13 +30,20 @@
 	{
         Guid mValue;
         private bool isNull;
+        private byte[] bytes;
 
-        public MySqlGuid(Guid g)
+        public MySqlGuid(byte[] buff)
         {
-            mValue = g;
+            mValue = new Guid(buff);
             isNull = false;
+            bytes = buff;
         }
 
+        public byte[] Bytes
+        {
+            get { return bytes; }
+        }
+
 		#region IMySqlValue Members
 
 		public bool IsNull
@@ -145,9 +152,9 @@
                 if (length == -1)
                     length = (long)packet.ReadFieldLength();
 
-                byte[] newBuff = new byte[length];
-                packet.Read(newBuff, 0, (int)length);
-                g = new MySqlGuid(new Guid(newBuff));
+                byte[] buff = new byte[length];
+                packet.Read(buff, 0, (int)length);
+                g = new MySqlGuid(buff);
             }
             return g;
 		}

Modified: branches/6.0/MySql.Data/Provider/Source/datareader.cs
===================================================================
--- branches/6.0/MySql.Data/Provider/Source/datareader.cs	2009-05-20 15:54:30 UTC (rev 1616)
+++ branches/6.0/MySql.Data/Provider/Source/datareader.cs	2009-05-21 18:16:16 UTC (rev 1617)
@@ -283,27 +283,30 @@
 
 			IMySqlValue val = GetFieldValue(i, false);
 
-			if (!(val is MySqlBinary))
-				throw new MySqlException("GetBytes can only be called on binary columns");
+			if (!(val is MySqlBinary) && !(val is MySqlGuid))
+				throw new MySqlException("GetBytes can only be called on binary or guid columns");
 
-			MySqlBinary binary = (MySqlBinary)val;
+            byte[] bytes = null;
+            if (val is MySqlBinary)
+                bytes = ((MySqlBinary)val).Value;
+            else
+                bytes = ((MySqlGuid)val).Bytes;
+
 			if (buffer == null)
-				return (long)binary.Value.Length;
+                return bytes.Length;
 
 			if (bufferoffset >= buffer.Length || bufferoffset < 0)
 				throw new IndexOutOfRangeException("Buffer index must be a valid index in buffer");
 			if (buffer.Length < (bufferoffset + length))
 				throw new ArgumentException("Buffer is not large enough to hold the requested data");
 			if (fieldOffset < 0 ||
-				((ulong)fieldOffset >= (ulong)binary.Value.Length && (ulong)binary.Value.Length > 0))
+				((ulong)fieldOffset >= (ulong)bytes.Length && (ulong)bytes.Length > 0))
 				throw new IndexOutOfRangeException("Data index must be a valid index in the field");
 
-			byte[] bytes = (byte[])binary.Value;
-
 			// adjust the length so we don't run off the end
-			if ((ulong)binary.Value.Length < (ulong)(fieldOffset + length))
+			if ((ulong)bytes.Length < (ulong)(fieldOffset + length))
 			{
-				length = (int)((ulong)binary.Value.Length - (ulong)fieldOffset);
+				length = (int)((ulong)bytes.Length - (ulong)fieldOffset);
 			}
 
 			Buffer.BlockCopy(bytes, (int)fieldOffset, buffer, (int)bufferoffset, (int)length);

Modified: branches/6.0/MySql.Data/Tests/Source/DataTypeTests.cs
===================================================================
--- branches/6.0/MySql.Data/Tests/Source/DataTypeTests.cs	2009-05-20 15:54:30 UTC (rev 1616)
+++ branches/6.0/MySql.Data/Tests/Source/DataTypeTests.cs	2009-05-21 18:16:16 UTC (rev 1617)
@@ -826,5 +826,34 @@
             Assert.AreEqual(1, dt.Rows[0]["id"]);
             Assert.AreEqual(guid, dt.Rows[0]["g"]);
         }
+
+        /// <summary>
+        /// Bug #44507 Binary(16) considered as Guid 
+        /// </summary>
+        [Test]
+        public void ReadBinary16AsBinary()
+        {
+            execSQL("DROP TABLE IF EXISTS Test");
+            execSQL("CREATE TABLE Test (id INT, guid BINARY(16))");
+
+            Guid g = new Guid("32A48AC5-285A-46c6-A0D4-158E6E39729C");
+            MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES (1, ?guid)", conn);
+            cmd.Parameters.AddWithValue("?guid", g);
+            cmd.ExecuteNonQuery();
+
+            cmd.CommandText = "SELECT * FROM Test";
+            cmd.Parameters.Clear();
+            using (MySqlDataReader reader = cmd.ExecuteReader())
+            {
+                reader.Read();
+
+                object o = reader.GetValue(1);
+                Assert.IsTrue(o is Guid);
+
+                byte[] bytes = new byte[16];
+                long size = reader.GetBytes(1, 0, bytes, 0, 16);
+                Assert.AreEqual(16, size);
+            }
+        }
     }
 }

Thread
Connector/NET commit: r1617 - in branches/6.0: . MySql.Data/Provider/Source MySql.Data/Provider/Source/Types MySql.Data/Tests/Sourcerburnett21 May