MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:October 29 2009 9:39pm
Subject:bzr push into connector-net-trunk branch (reggie.burnett:791 to 792)
Bug#48100
View as plain text  
  792 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
  791 Reggie Burnett	2009-10-28 [merge]
      - fixed unsigned types in views when used as entities (bug # 47872)

    modified:
      CHANGES
      MySql.Data.Entity/Provider/MySql.Data.Entity.csproj
      MySql.Data.Entity/Provider/Properties/SchemaDefinition-5.0.ssdl
      MySql.Data.Entity/Provider/Properties/SchemaDefinition-5.1.ssdl
      MySql.Data.Entity/Provider/Properties/SchemaDefinition-6.0.ssdl
      MySql.Data.Entity/Tests/MySql.Data.Entity.Tests.csproj
      MySql.Data.Entity/Tests/TestModel.Designer.cs
=== modified file 'CHANGES'
=== modified file 'CHANGES'
--- a/CHANGES	2009-10-28 16:09:25 +0000
+++ b/CHANGES	2009-10-29 21:38:45 +0000
@@ -4,6 +4,7 @@
 - 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) 
+- now exposing the MySqlDecimal type along with GetMySqlDecimal methods on data reader (bug #48100)    
 
 Version 6.2.0
 - we now cleanup idle connections in the pool, if they were not used for too long

=== 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-10-09 21:44:54 +0000
+++ b/MySql.Data/Provider/Source/datareader.cs	2009-10-29 21:36:59 +0000
@@ -415,6 +415,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 19:02:53 +0000
+++ b/MySql.Data/Tests/Source/DataTypeTests.cs	2009-10-29 21:36:59 +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-20091029213845-wdo0g0563ts18v5v.bundle
Thread
bzr push into connector-net-trunk branch (reggie.burnett:791 to 792)Bug#48100Reggie Burnett29 Oct