List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:August 10 2009 7:37pm
Subject:bzr commit into connector-net-6.0 branch (reggie.burnett:744) Bug#44455
View as plain text  
#At file:///D:/bzr-connector-net/old6.0/ based on
revid:reggie@core-20090810153016-qzd0x57ut300p0ek

  744 Reggie Burnett	2009-08-10
      - fixed formatting of single, double, and decimal values when used with entity
framework
        in cultures that use the comma as a decimal separator (bug #44455)

    modified:
      CHANGES
      MySql.Data.Entity/Provider/Generators/SqlGenerator.cs
      MySql.Data.Entity/Provider/Metadata.cs
      MySql.Data.Entity/Tests/DataTypeTests.cs
      MySql.Data.Entity/Tests/Properties/schema.sql
      MySql.Data.Entity/Tests/TestModel.Designer.cs
      MySql.Data.Entity/Tests/TestModel.csdl
      MySql.Data.Entity/Tests/TestModel.msl
      MySql.Data.Entity/Tests/TestModel.ssdl
=== modified file 'CHANGES'
=== modified file 'CHANGES'
--- a/CHANGES	2009-08-10 15:30:16 +0000
+++ b/CHANGES	2009-08-10 17:37:48 +0000
@@ -18,6 +18,8 @@
   (thanks Lynn!) (bug #45723)
 - fixed bug that caused our TIME type to not be supported (bug #45457)
 - fixed unsigned type problems with entity framework (bug #45077)  
+- fixed formatting of single, double, and decimal values when used with entity framework
+  in cultures that use the comma as a decimal separator (bug #44455)  
   
 Version 6.0.4
 - fixed regression where using stored procs with datasets (bug #44460)

=== modified file 'MySql.Data.Entity/Provider/Generators/SqlGenerator.cs'
--- a/MySql.Data.Entity/Provider/Generators/SqlGenerator.cs	2009-04-21 18:02:13 +0000
+++ b/MySql.Data.Entity/Provider/Generators/SqlGenerator.cs	2009-08-10 17:37:48 +0000
@@ -148,13 +148,9 @@
         public override SqlFragment Visit(DbConstantExpression expression)
         {
             PrimitiveTypeKind pt =
((PrimitiveType)expression.ResultType.EdmType).PrimitiveTypeKind;
-            if (Metadata.IsNumericType(expression.ResultType))
-                return new LiteralFragment(expression.Value.ToString());
-            else if (pt == PrimitiveTypeKind.Decimal)
-            {
-                decimal val = (decimal)expression.Value;
-                return new LiteralFragment(val.ToString(CultureInfo.InvariantCulture));
-            }
+            string literal = Metadata.GetNumericLiteral(pt, expression.Value);
+            if (literal != null)
+                return new LiteralFragment(literal);
             else if (pt == PrimitiveTypeKind.Boolean)
                 return new LiteralFragment(String.Format("cast({0} as decimal(0,0))",
                     (bool)expression.Value ? 1 : 0));

=== modified file 'MySql.Data.Entity/Provider/Metadata.cs'
--- a/MySql.Data.Entity/Provider/Metadata.cs	2009-08-05 20:52:53 +0000
+++ b/MySql.Data.Entity/Provider/Metadata.cs	2009-08-10 17:37:48 +0000
@@ -23,11 +23,32 @@
 using System.Data.Metadata.Edm;
 using System.Data.Common.CommandTrees;
 using System.Collections.Generic;
+using System.Globalization;
 
 namespace MySql.Data.Entity
 {
     class Metadata
     {
+        public static string GetNumericLiteral(PrimitiveTypeKind type, object value)
+        {
+            switch (type)
+            {
+                case PrimitiveTypeKind.Byte:
+                case PrimitiveTypeKind.Int16:
+                case PrimitiveTypeKind.Int32:
+                case PrimitiveTypeKind.Int64:
+                case PrimitiveTypeKind.SByte:
+                    return value.ToString();
+                case PrimitiveTypeKind.Double:
+                    return ((double)value).ToString("R", CultureInfo.InvariantCulture);
+                case PrimitiveTypeKind.Single:
+                    return ((float)value).ToString("R", CultureInfo.InvariantCulture);
+                case PrimitiveTypeKind.Decimal:
+                    return ((decimal)value).ToString(CultureInfo.InvariantCulture);
+            }
+            return null;
+        }
+
         public static bool IsNumericType(TypeUsage typeUsage)
         {
             PrimitiveType pt = (PrimitiveType)typeUsage.EdmType;

=== modified file 'MySql.Data.Entity/Tests/DataTypeTests.cs'
--- a/MySql.Data.Entity/Tests/DataTypeTests.cs	2009-08-10 15:30:16 +0000
+++ b/MySql.Data.Entity/Tests/DataTypeTests.cs	2009-08-10 17:37:48 +0000
@@ -28,6 +28,7 @@
 using System.Data.EntityClient;
 using System.Data.Common;
 using System.Data.Objects;
+using System.Globalization;
 
 namespace MySql.Data.Entity.Tests
 {
@@ -74,5 +75,34 @@
                 context.Attach(row);
             }
         }
+
+        /// <summary>
+        /// Bug #44455	insert and update error with entity framework
+        /// </summary>
+        [Test]
+        public void DoubleValuesNonEnglish()
+        {
+            CultureInfo curCulture = Thread.CurrentThread.CurrentCulture;
+            CultureInfo curUICulture = Thread.CurrentThread.CurrentUICulture;
+            CultureInfo newCulture = new CultureInfo("da-DK");
+            Thread.CurrentThread.CurrentCulture = newCulture;
+            Thread.CurrentThread.CurrentUICulture = newCulture;
+
+            try
+            {
+                using (testEntities context = new testEntities())
+                {
+                    Child c = Child.CreateChild(20, 1, "Rubble", "Bam bam");
+                    c.BirthWeight = 8.65;
+                    context.AddToChildren(c);
+                    context.SaveChanges();
+                }
+            }
+            finally
+            {
+                Thread.CurrentThread.CurrentCulture = curCulture;
+                Thread.CurrentThread.CurrentUICulture = curUICulture;
+            }
+        }
     }
 }
\ No newline at end of file

=== modified file 'MySql.Data.Entity/Tests/Properties/schema.sql'
--- a/MySql.Data.Entity/Tests/Properties/schema.sql	2009-08-10 15:30:16 +0000
+++ b/MySql.Data.Entity/Tests/Properties/schema.sql	2009-08-10 17:37:48 +0000
@@ -37,9 +37,10 @@
 	EmployeeId INT NOT NULL,
 	LastName NVARCHAR(20) NOT NULL,
 	FirstName NVARCHAR(10) NOT NULL,
-	BirthTime TIME);
+	BirthTime TIME,
+	Weight DOUBLE);
 
-INSERT INTO EmployeeChildren VALUES (1, 1, 'Flintstone', 'Pebbles', NULL);
+INSERT INTO EmployeeChildren VALUES (1, 1, 'Flintstone', 'Pebbles', NULL, NULL);
 
 CREATE TABLE Companies (
 	`Id` INT NOT NULL AUTO_INCREMENT,

=== modified file 'MySql.Data.Entity/Tests/TestModel.Designer.cs'
--- a/MySql.Data.Entity/Tests/TestModel.Designer.cs	2009-08-10 15:30:16 +0000
+++ b/MySql.Data.Entity/Tests/TestModel.Designer.cs	2009-08-10 17:37:48 +0000
@@ -15,7 +15,7 @@
 [assembly: global::System.Data.Objects.DataClasses.EdmRelationshipAttribute("testModel",
"FK_Books_Publishers", "Publishers",
global::System.Data.Metadata.Edm.RelationshipMultiplicity.One,
typeof(MySql.Data.Entity.Tests.Publisher), "Books",
global::System.Data.Metadata.Edm.RelationshipMultiplicity.Many,
typeof(MySql.Data.Entity.Tests.Book))]
 
 // Original file name:
-// Generation date: 8/10/2009 9:53:24 AM
+// Generation date: 8/10/2009 11:51:12 AM
 namespace MySql.Data.Entity.Tests
 {
     
@@ -560,6 +560,29 @@
         private global::System.Nullable<global::System.TimeSpan> _BirthTime;
         partial void
OnBirthTimeChanging(global::System.Nullable<global::System.TimeSpan> value);
         partial void OnBirthTimeChanged();
+        /// <summary>
+        /// There are no comments for Property BirthWeight in the schema.
+        /// </summary>
+        [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute()]
+        [global::System.Runtime.Serialization.DataMemberAttribute()]
+        public global::System.Nullable<double> BirthWeight
+        {
+            get
+            {
+                return this._BirthWeight;
+            }
+            set
+            {
+                this.OnBirthWeightChanging(value);
+                this.ReportPropertyChanging("BirthWeight");
+                this._BirthWeight =
global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value);
+                this.ReportPropertyChanged("BirthWeight");
+                this.OnBirthWeightChanged();
+            }
+        }
+        private global::System.Nullable<double> _BirthWeight;
+        partial void OnBirthWeightChanging(global::System.Nullable<double> value);
+        partial void OnBirthWeightChanged();
     }
     /// <summary>
     /// There are no comments for testModel.Company in the schema.

=== modified file 'MySql.Data.Entity/Tests/TestModel.csdl'
--- a/MySql.Data.Entity/Tests/TestModel.csdl	2009-08-10 15:30:16 +0000
+++ b/MySql.Data.Entity/Tests/TestModel.csdl	2009-08-10 17:37:48 +0000
@@ -52,6 +52,7 @@
     <Property Name="LastName" Type="String" Nullable="false" MaxLength="20" />
     <Property Name="FirstName" Type="String" Nullable="false" MaxLength="10" />
     <Property Name="BirthTime" Type="Time" Nullable="true"/>
+    <Property Name="BirthWeight" Type="Double" Nullable="true"/>
   </EntityType>
 
   <EntityType Name="Company">

=== modified file 'MySql.Data.Entity/Tests/TestModel.msl'
--- a/MySql.Data.Entity/Tests/TestModel.msl	2009-08-05 20:52:53 +0000
+++ b/MySql.Data.Entity/Tests/TestModel.msl	2009-08-10 17:37:48 +0000
@@ -42,6 +42,7 @@
           <ScalarProperty Name="LastName" ColumnName="LastName" />
           <ScalarProperty Name="FirstName" ColumnName="FirstName" />
           <ScalarProperty Name="BirthTime" ColumnName="BirthTime"/>
+          <ScalarProperty Name="BirthWeight" ColumnName="Weight"/>
         </MappingFragment>
       </EntityTypeMapping>
     </EntitySetMapping>

=== modified file 'MySql.Data.Entity/Tests/TestModel.ssdl'
--- a/MySql.Data.Entity/Tests/TestModel.ssdl	2009-08-10 15:30:16 +0000
+++ b/MySql.Data.Entity/Tests/TestModel.ssdl	2009-08-10 17:37:48 +0000
@@ -56,6 +56,7 @@
     <Property Name="LastName" Type="nvarchar" Nullable="false" MaxLength="20" />
     <Property Name="FirstName" Type="nvarchar" Nullable="false" MaxLength="10" />
     <Property Name="BirthTime" Type="time" Nullable="true"/>
+    <Property Name="Weight" Type="double" Nullable ="true"/>
   </EntityType>
 
   <EntityType Name="Companies">


Attachment: [text/bzr-bundle] bzr/reggie.burnett@sun.com-20090810173748-54jbbkjg91zzbhi2.bundle
Thread
bzr commit into connector-net-6.0 branch (reggie.burnett:744) Bug#44455Reggie Burnett10 Aug 2009