List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:October 29 2009 9:32pm
Subject:bzr commit into connector-net-6.1 branch (reggie.burnett:784) Bug#48100
View as plain text  
#At file:///D:/bzr-connector-net/6.1/ based on revid:reggie.burnett@stripped

  784 Reggie Burnett	2009-10-29 [merge]
      - now exposing the MySqlDecimal type along with GetMySqlDecimal methods on data reader (bug #48100)

    modified:
      CHANGES
      MySql.Data/Provider/Source/Types/MySqlDecimal.cs
      MySql.Data/Provider/Source/datareader.cs
      MySql.Data/Tests/Source/DataTypeTests.cs
=== modified file 'CHANGES'
=== modified file 'CHANGES'
--- a/CHANGES	2009-10-28 16:02:29 +0000
+++ b/CHANGES	2009-10-29 21:32:36 +0000
@@ -8,7 +8,8 @@
 - fixed indexes schema collection so that it still works with bad table names such as b``a`d (bug #48101)
 - fixed guid type so that multi-byte character sets will not effect how it works.  A column would be
   considered a guid if it has a *character* length of 36, not a *byte* length of 36 (bug #47985)
-- fixed unsigned types in views when used as entities (bug #   47872) 
+- fixed unsigned types in views when used as entities (bug # 47872) 
+- now exposing the MySqlDecimal type along with GetMySqlDecimal methods on data reader (bug #48100)    
 
 Version 6.1.2
 - fixed hanging after losing network connectivity to server (bug#43761) 

=== modified file 'MySql.Data/Provider/Source/Types/MySqlDecimal.cs'
--- a/MySql.Data/Provider/Source/Types/MySqlDecimal.cs	2009-04-21 18:02:13 +0000
+++ b/MySql.Data/Provider/Source/Types/MySqlDecimal.cs	2009-10-29 21:29:54 +0000
@@ -26,21 +26,21 @@
 namespace MySql.Data.Types
 {
 
-	internal struct MySqlDecimal : IMySqlValue
+	public struct MySqlDecimal : IMySqlValue
 	{
 		private byte precision;
 		private byte scale;
-		private Decimal mValue;
+        private string mValue;
 		private bool isNull;
 
-		public MySqlDecimal(bool isNull)
+		internal MySqlDecimal(bool isNull)
 		{
 			this.isNull = isNull;
-			mValue = 0;
+            mValue = null;
 			precision = scale = 0;
 		}
 
-		public MySqlDecimal(decimal val)
+		internal MySqlDecimal(string val)
 		{
 			this.isNull = false;
 			precision = scale = 0;
@@ -84,9 +84,19 @@
 
 		public decimal Value
 		{
-			get { return mValue; }
+			get { return Convert.ToDecimal(mValue); }
 		}
 
+        public double ToDouble()
+        {
+            return Double.Parse(mValue);
+        }
+
+        public override string ToString()
+        {
+            return mValue;
+        }
+
 		Type IMySqlValue.SystemType
 		{
 			get { return typeof(decimal); }
@@ -112,18 +122,12 @@
 			if (nullVal)
 				return new MySqlDecimal(true);
 
+            string s = String.Empty;
 			if (length == -1)
-			{
-                string s = packet.ReadLenString();
-				return new MySqlDecimal(Decimal.Parse(s,
-					 CultureInfo.InvariantCulture));
-			}
-			else
-			{
-                string s = packet.ReadString(length);
-				return new MySqlDecimal(Decimal.Parse(s,
-					 CultureInfo.InvariantCulture));
-			}
+                s = packet.ReadLenString();
+            else 
+                s = packet.ReadString(length);
+			return new MySqlDecimal(s);
 		}
 
         void IMySqlValue.SkipValue(MySqlPacket packet)

=== modified file 'MySql.Data/Provider/Source/datareader.cs'
--- a/MySql.Data/Provider/Source/datareader.cs	2009-08-10 18:04:41 +0000
+++ b/MySql.Data/Provider/Source/datareader.cs	2009-10-29 21:32:36 +0000
@@ -401,6 +401,16 @@
 				return dt.GetDateTime();
 		}
 
+        public MySqlDecimal GetMySqlDecimal(string column)
+        {
+            return GetMySqlDecimal(GetOrdinal(column));
+        }
+
+        public MySqlDecimal GetMySqlDecimal(int i)
+        {
+			return (MySqlDecimal)GetFieldValue(i, false);
+        }
+
 		/// <include file='docs/MySqlDataReader.xml' path='docs/GetDecimalS/*'/>
 		public Decimal GetDecimal(string column)
 		{

=== modified file 'MySql.Data/Tests/Source/DataTypeTests.cs'
--- a/MySql.Data/Tests/Source/DataTypeTests.cs	2009-10-23 15:53:16 +0000
+++ b/MySql.Data/Tests/Source/DataTypeTests.cs	2009-10-29 21:32:36 +0000
@@ -1004,5 +1004,34 @@
                 }
             }
         }
+
+        /// <summary>
+        /// Bug #48100	Impossible to retrieve decimal value if it doesn't fit into .Net System.Decimal
+        /// </summary>
+        [Test]
+        public void MySqlDecimal()
+        {
+            execSQL("DROP TABLE IF EXISTS Test");
+            execSQL("CREATE TABLE Test (id INT, dec1 DECIMAL(36,2))");
+            execSQL("INSERT INTO Test VALUES (1, 9999999999999999999999999999999999.99)");
+
+            MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
+            using (MySqlDataReader reader = cmd.ExecuteReader())
+            {
+                reader.Read();
+                MySqlDecimal dec = reader.GetMySqlDecimal(1);
+                string s = dec.ToString();
+                Assert.AreEqual(9999999999999999999999999999999999.99, dec.ToDouble());
+                Assert.AreEqual("9999999999999999999999999999999999.99", dec.ToString());
+                try
+                {
+                    decimal d = dec.Value;
+                    Assert.Fail("this should have failed");
+                }
+                catch (Exception ex) 
+                {
+                }
+            }
+        }
     }
 }


Attachment: [text/bzr-bundle] bzr/reggie.burnett@sun.com-20091029213236-8gdx12pq4bzx0z2v.bundle
Thread
bzr commit into connector-net-6.1 branch (reggie.burnett:784) Bug#48100Reggie Burnett29 Oct