#At file:///C:/bzr-connector-net/trunk/ based on revid:reggie.burnett@strippedgz8r7r7eagf8s
817 Reggie Burnett 2010-01-05 [merge]
fixed entity framework function processing so that it handles stored functions properly (bug #45277)
removed:
MySql.Data.Entity/Provider/Properties/Resources.Designer.cs
added:
MySql.Data.Entity/Provider/Properties/Resources.Designer.cs
modified:
CHANGES
MySql.Data.Entity/Provider/Fragments/SqlFragment.cs
MySql.Data.Entity/Provider/Generators/FunctionProcessor.cs
MySql.Data.Entity/Provider/Metadata.cs
MySql.Data.Entity/Tests/ProceduresAndFunctions.cs
MySql.Data.Entity/Tests/Properties/procs.sql
MySql.Data.Entity/Tests/TestModel.Designer.cs
MySql.Data.Entity/Tests/TestModel.ssdl
=== modified file 'CHANGES'
=== modified file 'CHANGES'
--- a/CHANGES 2009-12-15 17:16:40 +0000
+++ b/CHANGES 2010-01-05 22:19:37 +0000
@@ -1,3 +1,7 @@
+- fixed entity framework function processing so that it handles stored functions properly
+ (bug #45277)
+
+version 6.2.2
- Fix race condition during TransactionScope rollback (bug#35330)
- When sending file to server (LOAD DATA INFILE) open the file for read only, not for read/write
(bug #48944)
=== modified file 'MySql.Data.Entity/Provider/Fragments/SqlFragment.cs'
--- a/MySql.Data.Entity/Provider/Fragments/SqlFragment.cs 2009-04-21 18:02:13 +0000
+++ b/MySql.Data.Entity/Provider/Fragments/SqlFragment.cs 2010-01-05 22:09:58 +0000
@@ -169,10 +169,12 @@
public bool Distinct;
public SqlFragment Argmument;
public string Name;
+ public bool Quoted;
public override void WriteSql(StringBuilder sql)
{
- sql.AppendFormat("{0}({1}", Name, Distinct ? "DISTINCT " : "");
+ string name = Quoted ? QuoteIdentifier(Name) : Name;
+ sql.AppendFormat("{0}({1}", name, Distinct ? "DISTINCT " : "");
Argmument.WriteSql(sql);
sql.Append(")");
}
=== modified file 'MySql.Data.Entity/Provider/Generators/FunctionProcessor.cs'
--- a/MySql.Data.Entity/Provider/Generators/FunctionProcessor.cs 2009-04-21 18:02:13 +0000
+++ b/MySql.Data.Entity/Provider/Generators/FunctionProcessor.cs 2010-01-05 22:09:58 +0000
@@ -84,7 +84,37 @@
return GenericFunction(stringFunctions, e);
else if (mathFunctions.ContainsKey(e.Function.Name))
return GenericFunction(mathFunctions, e);
- return null;
+ else
+ return UserDefinedFunction(e);
+ }
+
+ private SqlFragment UserDefinedFunction(DbFunctionExpression e)
+ {
+ FunctionFragment f = new FunctionFragment();
+ f.Name = Metadata.TryGetValueMetadataProperty<string>(e.Function,
+ "StoreFunctionNameAttribute");
+
+ if (String.IsNullOrEmpty(f.Name))
+ f.Name = e.Function.Name;
+
+ f.Quoted = !Metadata.TryGetValueMetadataProperty<bool>(e.Function, "BuiltInAttribute");
+
+ bool isFuncNiladic = Metadata.TryGetValueMetadataProperty<bool>(e.Function, "NiladicFunctionAttribute");
+ if (isFuncNiladic && e.Arguments.Count > 0)
+ throw new InvalidOperationException("Niladic functions cannot have parameters");
+
+ ListFragment list = new ListFragment();
+ string delimiter = "";
+ foreach (DbExpression arg in e.Arguments)
+ {
+ if (delimiter.Length > 0)
+ list.Append(new LiteralFragment(delimiter));
+ list.Append(arg.Accept(callingGenerator));
+ delimiter = ", ";
+ }
+ f.Argmument = list;
+
+ return f;
}
private SqlFragment BitwiseFunction(DbFunctionExpression e)
=== modified file 'MySql.Data.Entity/Provider/Metadata.cs'
--- a/MySql.Data.Entity/Provider/Metadata.cs 2009-09-01 00:49:03 +0000
+++ b/MySql.Data.Entity/Provider/Metadata.cs 2010-01-05 22:09:58 +0000
@@ -151,5 +151,13 @@
return ((RowType)type).Properties;
throw new NotSupportedException();
}
+
+ internal static T TryGetValueMetadataProperty<T>(MetadataItem mi, string name)
+ {
+ MetadataProperty property;
+ bool exists = mi.MetadataProperties.TryGetValue(name, true, out property);
+ if (exists) return (T)property.Value;
+ return default(T);
+ }
}
}
=== added file 'MySql.Data.Entity/Provider/Properties/Resources.Designer.cs'
--- a/MySql.Data.Entity/Provider/Properties/Resources.Designer.cs 1970-01-01 00:00:00 +0000
+++ b/MySql.Data.Entity/Provider/Properties/Resources.Designer.cs 2010-01-05 22:17:34 +0000
@@ -0,0 +1,72 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4927
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace MySql.Data.Entity.Properties {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MySql.Data.Entity.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Result type of a function is expected to be a collection of RowType or PrimitiveType.
+ /// </summary>
+ internal static string WrongFunctionResultType {
+ get {
+ return ResourceManager.GetString("WrongFunctionResultType", resourceCulture);
+ }
+ }
+ }
+}
=== removed file 'MySql.Data.Entity/Provider/Properties/Resources.Designer.cs'
--- a/MySql.Data.Entity/Provider/Properties/Resources.Designer.cs 2009-10-14 12:59:53 +0000
+++ b/MySql.Data.Entity/Provider/Properties/Resources.Designer.cs 1970-01-01 00:00:00 +0000
@@ -1,72 +0,0 @@
-//------------------------------------------------------------------------------
-// <auto-generated>
-// This code was generated by a tool.
-// Runtime Version:2.0.50727.4927
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
-namespace MySql.Data.Entity.Properties {
- using System;
-
-
- /// <summary>
- /// A strongly-typed resource class, for looking up localized strings, etc.
- /// </summary>
- // This class was auto-generated by the StronglyTypedResourceBuilder
- // class via a tool like ResGen or Visual Studio.
- // To add or remove a member, edit your .ResX file then rerun ResGen
- // with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Resources {
-
- private static global::System.Resources.ResourceManager resourceMan;
-
- private static global::System.Globalization.CultureInfo resourceCulture;
-
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources() {
- }
-
- /// <summary>
- /// Returns the cached ResourceManager instance used by this class.
- /// </summary>
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MySql.Data.Entity.Properties.Resources", typeof(Resources).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- /// <summary>
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- /// </summary>
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Result type of a function is expected to be a collection of RowType or PrimitiveType.
- /// </summary>
- internal static string WrongFunctionResultType {
- get {
- return ResourceManager.GetString("WrongFunctionResultType", resourceCulture);
- }
- }
- }
-}
=== modified file 'MySql.Data.Entity/Tests/ProceduresAndFunctions.cs'
--- a/MySql.Data.Entity/Tests/ProceduresAndFunctions.cs 2009-04-21 18:02:13 +0000
+++ b/MySql.Data.Entity/Tests/ProceduresAndFunctions.cs 2010-01-05 22:09:58 +0000
@@ -102,5 +102,26 @@
da.Fill(dt);
Assert.AreEqual(0, dt.Rows.Count);
}
+
+ /// <summary>
+ /// Bug #45277 Calling User Defined Function using eSql causes NullReferenceException
+ /// </summary>
+ [Test]
+ public void UserDefinedFunction()
+ {
+ using (EntityConnection conn = new EntityConnection("name=testEntities"))
+ {
+ conn.Open();
+
+ string query = @"SELECT e.FirstName AS Name FROM testEntities.Employees AS e
+ WHERE testModel.Store.spFunc(e.Id, '') = 6";
+ using (EntityCommand cmd = new EntityCommand(query, conn))
+ {
+ EntityDataReader reader = cmd.ExecuteReader();
+ Assert.IsTrue(reader.Read());
+ Assert.AreEqual(6, reader[0]);
+ }
+ }
+ }
}
}
\ No newline at end of file
=== modified file 'MySql.Data.Entity/Tests/Properties/procs.sql'
--- a/MySql.Data.Entity/Tests/Properties/procs.sql 2009-02-25 19:26:34 +0000
+++ b/MySql.Data.Entity/Tests/Properties/procs.sql 2010-01-05 22:09:58 +0000
@@ -17,3 +17,9 @@
BEGIN
UPDATE authors SET `name`=thename, age=theage WHERE id=theid;
END $$
+
+CREATE FUNCTION spFunc(id INT, name VARCHAR(20)) RETURNS INT
+BEGIN
+ RETURN id;
+END $$
+
=== modified file 'MySql.Data.Entity/Tests/TestModel.Designer.cs'
--- a/MySql.Data.Entity/Tests/TestModel.Designer.cs 2009-11-03 16:10:05 +0000
+++ b/MySql.Data.Entity/Tests/TestModel.Designer.cs 2010-01-05 22:14:55 +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: 11/3/2009 9:33:22 AM
+// Generation date: 1/5/2010 4:13:44 PM
namespace MySql.Data.Entity.Tests
{
=== modified file 'MySql.Data.Entity/Tests/TestModel.ssdl'
--- a/MySql.Data.Entity/Tests/TestModel.ssdl 2009-11-03 16:10:05 +0000
+++ b/MySql.Data.Entity/Tests/TestModel.ssdl 2010-01-05 22:14:55 +0000
@@ -199,7 +199,12 @@
<Parameter Name="thename" Type="varchar" Mode="In" />
<Parameter Name="theage" Type="int" Mode="In" />
</Function>
-
+ <Function Name="spFunc" Aggregate="false"
+ BuiltIn="false" NiladicFunction="false" IsComposable="true"
+ ParameterTypeSemantics="AllowImplicitConversion" Schema="test" ReturnType="int">
+ <Parameter Name="id" Type="int" Mode="In" />
+ <Parameter Name="name" Type="varchar" Mode="In" />
+ </Function>
<EntityType Name="DataTypeTests">
<Key>
<PropertyRef Name="id"/>
Attachment: [text/bzr-bundle] bzr/reggie.burnett@sun.com-20100105221937-03wflj2vnrqtj7gq.bundle
| Thread |
|---|
| • bzr commit into connector-net-trunk branch (reggie.burnett:817)Bug#45277 | Reggie Burnett | 5 Jan |