List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:May 25 2011 3:39am
Subject:bzr commit into connector-net-6.2 branch (reggie.burnett:937)
View as plain text  
#At file:///C:/Users/Reggie/work/connector-net/6.2/ based on revid:reggie.burnett@stripped

  937 Reggie Burnett	2011-05-24 [merge]
      merge

    modified:
      MySql.Data.Entity/Provider/Fragments/SqlFragment.cs
      MySql.Data.Entity/Provider/Statements/SelectStatement.cs
      MySql.Data.Entity/Tests/JoinTests.cs
      MySql.Data.Entity/Tests/Properties/SQLSyntax.Designer.cs
      MySql.Data.Entity/Tests/Properties/SQLSyntax.resx
=== modified file 'MySql.Data.Entity/Provider/Fragments/SqlFragment.cs'
=== modified file 'MySql.Data.Entity/Provider/Fragments/SqlFragment.cs'
--- a/MySql.Data.Entity/Provider/Fragments/SqlFragment.cs	2011-05-24 01:47:48 +0000
+++ b/MySql.Data.Entity/Provider/Fragments/SqlFragment.cs	2011-05-25 03:39:25 +0000
@@ -164,6 +164,13 @@
             return cf;
         }
 
+        public void PushInput(string inputName)
+        {
+            if (PropertyFragment == null)
+                PropertyFragment = new PropertyFragment();
+            PropertyFragment.PushProperty(inputName);
+        }
+
         public override bool Equals(object obj)
         {
             if (!(obj is ColumnFragment)) return false;
@@ -319,6 +326,11 @@
             Properties.RemoveRange(index + 1, Properties.Count - index - 1);
         }
 
+        public void PushProperty(string property)
+        {
+            Properties.Insert(0, property);
+        }
+
         public override bool Equals(object obj)
         {
             if (!(obj is PropertyFragment)) return false;

=== modified file 'MySql.Data.Entity/Provider/Statements/SelectStatement.cs'
--- a/MySql.Data.Entity/Provider/Statements/SelectStatement.cs	2011-05-24 01:47:48 +0000
+++ b/MySql.Data.Entity/Provider/Statements/SelectStatement.cs	2011-05-25 03:39:25 +0000
@@ -132,72 +132,73 @@
 
         void AddDefaultColumns()
         {
-//            List<PropertyFragment> properties = GetColumnPropertiesFromInput(From);
-            AddDefaultColumnsForFragment(From, null);
+            if (columnHash == null)
+                columnHash = new Dictionary<string, ColumnFragment>();
+
+            List<ColumnFragment> columns = GetDefaultColumnsForFragment(From);
+
+            foreach (ColumnFragment column in columns)
+            {
+                column.TableName = column.PropertyFragment.Properties[0];
+                if (columnHash.ContainsKey(column.ColumnName))
+                {
+                    column.ColumnAlias = MakeColumnNameUnique(column.ColumnName);
+                    columnHash.Add(column.ColumnAlias, column);
+                }
+                else
+                    columnHash.Add(column.ColumnName, column);
+                Columns.Add(column);
+            }
         }
 
-        //private List<PropertyFragment> GetColumnPropertiesFromInput(InputFragment input)
-        //{
-        //    if (input is TableFragment)
-        //}
-
-        void AddDefaultColumnsForFragment(InputFragment input, PropertyFragment trail)
+        List<ColumnFragment> GetDefaultColumnsForFragment(InputFragment input)
         {
-            if (trail == null)
-                trail = new PropertyFragment();
+            List<ColumnFragment> columns = new List<ColumnFragment>();
+
             if (input is TableFragment)
             {
-                AddDefaultColumnsForTable(input as TableFragment, trail);
+                return GetDefaultColumnsForTable(input as TableFragment);
             }
             else if (input is JoinFragment || input is UnionFragment)
             {
-                trail.Properties.Add(input.Name);
-                if (input.Left != null)
-                    AddDefaultColumnsForFragment(input.Left, trail);
-                trail.Trim(input.Name);
-                if (input.Right != null)
-                AddDefaultColumnsForFragment(input.Right, trail);
-
-                // if this input is scoped, then it is the base tablename for the columns
-                if (input.Scoped)
-                    foreach (ColumnFragment col in Columns)
-                        col.TableName = input.Name;
+                Debug.Assert(input.Left != null);
+                columns = GetDefaultColumnsForFragment(input.Left);
+                if (input is JoinFragment && input.Right != null)
+                {
+                    List<ColumnFragment> right = GetDefaultColumnsForFragment(input.Right);
+                    columns.AddRange(right);
+                }
             }
             else if (input is SelectStatement)
             {
                 SelectStatement select = input as SelectStatement;
                 foreach (ColumnFragment cf in select.Columns)
-                    Columns.Add(cf.Clone());
+                {
+                    ColumnFragment newColumn = new ColumnFragment(cf.TableName, cf.ColumnName);
+                    newColumn.PushInput(cf.ColumnName);
+                    columns.Add(newColumn);
+                }
             }
             else
                 throw new NotImplementedException();
+            if (!String.IsNullOrEmpty(input.Name) && input.Name != From.Name)
+                foreach (ColumnFragment c in columns)
+                    c.PushInput(input.Name);
+            return columns;
         }
 
-        void AddDefaultColumnsForTable(TableFragment table, PropertyFragment trail)
+        List<ColumnFragment> GetDefaultColumnsForTable(TableFragment table)
         {
-            trail.Properties.Add(table.Name);
-            if (columnHash == null)
-                columnHash = new Dictionary<string, ColumnFragment>();
+            List<ColumnFragment> columns = new List<ColumnFragment>();
 
             foreach (EdmProperty property in Metadata.GetProperties(table.Type.EdmType))
             {
-                PropertyFragment props = trail.Clone();
-                props.Properties.Add(property.Name);
-
                 ColumnFragment col = new ColumnFragment(table.Name, property.Name);
-                col.PropertyFragment = props;
-                if (table.Columns == null)
-                    table.Columns = new List<ColumnFragment>();
-                table.Columns.Add(col);
-                if (columnHash.ContainsKey(col.ColumnName))
-                {
-                    col.ColumnAlias = MakeColumnNameUnique(col.ColumnName);
-                    columnHash.Add(col.ColumnAlias, col);
-                }
-                else
-                    columnHash.Add(col.ColumnName, col);
-                Columns.Add(col);
+                col.PushInput(property.Name);
+                col.PushInput(table.Name);
+                columns.Add(col);
             }
+            return columns;
         }
 
         private string MakeColumnNameUnique(string baseName)

=== modified file 'MySql.Data.Entity/Tests/JoinTests.cs'
--- a/MySql.Data.Entity/Tests/JoinTests.cs	2011-05-24 01:47:48 +0000
+++ b/MySql.Data.Entity/Tests/JoinTests.cs	2011-05-25 03:39:25 +0000
@@ -124,28 +124,24 @@
         {
             using (testEntities context = new testEntities())
             {
-                string eSql = @"SELECT c.Id, c.Name, a.Id, a.Name, b.Id, b.Name FROM
-                                testEntities.Companies AS c JOIN (testEntities.Authors AS a
-                                JOIN testEntities.Books AS b ON a.Id = b.Id) ON c.Id = a.Id";
-                ObjectQuery<Company> query = context.CreateQuery<Company>(eSql);
-                string s= query.ToTraceString();
-
-
-                //var j1 = from store in context.Stores
-                //         join toy in context.Toys
-                //         on store.Id equals toy.Id
-                //         select new { store.Id, store.Name };
-                //var j2 = from a in context.Authors
-                //         join p in context.Publishers
-                //         on a.Id equals p.id
-                //         select new { a.Id, a.Name };
-                //var u1 = j1.Union(j2);
-                //var q = from book in context.Books
-                //        join u in j1.Union(j2)
-                //        on book.Id equals u.Id
-                //        select book;
-                //string sql = q.ToTraceString();
-                //CheckSql(sql, SQLSyntax.JoinOnRightSideAsDerivedTable);
+                string eSql = @"SELECT c.Id, c.Name, Union1.Id, Union1.Name, 
+                                Union2.Id, Union2.Name FROM 
+                                testEntities.Companies AS c JOIN (
+                                ((SELECT t.Id, t.Name FROM testEntities.Toys as t) 
+                                UNION ALL 
+                                (SELECT s.Id, s.Name FROM testEntities.Stores as s)) AS Union1
+                                JOIN 
+                                ((SELECT a.Id, a.Name FROM testEntities.Authors AS a) 
+                                UNION ALL 
+                                (SELECT b.Id, b.Name FROM testEntities.Books AS b)) AS Union2
+                                ON Union1.Id = Union2.Id) ON c.Id = Union1.Id";
+                ObjectQuery<DbDataRecord> query = context.CreateQuery<DbDataRecord>(eSql);
+                string sql = query.ToTraceString();
+                CheckSql(sql, SQLSyntax.JoinOfUnionsOnRightSideOfJoin);
+                foreach (DbDataRecord record in query)
+                {
+                    Assert.AreEqual(6, record.FieldCount);
+                }
             }
         }
 

=== modified file 'MySql.Data.Entity/Tests/Properties/SQLSyntax.Designer.cs'
--- a/MySql.Data.Entity/Tests/Properties/SQLSyntax.Designer.cs	2011-05-24 01:43:31 +0000
+++ b/MySql.Data.Entity/Tests/Properties/SQLSyntax.Designer.cs	2011-05-25 03:37:35 +0000
@@ -194,6 +194,39 @@
         
         /// <summary>
         ///   Looks up a localized string similar to SELECT
+        ///1 AS C1, 
+        ///Extent1.Id, 
+        ///Extent1.Name, 
+        ///Join1.Id AS C2, 
+        ///Join1.Name AS C3, 
+        ///Join1.Id1 AS C4, 
+        ///Join1.Name1 AS C5
+        ///FROM Companies AS Extent1 INNER JOIN (SELECT
+        ///UnionAll1.Id, 
+        ///UnionAll1.Name, 
+        ///UnionAll2.Id AS Id1, 
+        ///UnionAll2.Name AS Name1
+        ///FROM (SELECT
+        ///Extent2.Id, 
+        ///Extent2.Name
+        ///FROM Toys AS Extent2 UNION ALL SELECT
+        ///Extent3.Id, 
+        ///Extent3.Name
+        ///FROM Stores AS Extent3) AS UnionAll1 INNER JOIN (SELECT
+        ///Extent4.Id, 
+        ///Extent4.Name
+        ///FROM Authors AS Extent4 UNION ALL SELECT
+        ///Extent5.Id, 
+        ///Extent5.N [rest of string was truncated]&quot;;.
+        /// </summary>
+        internal static string JoinOfUnionsOnRightSideOfJoin {
+            get {
+                return ResourceManager.GetString("JoinOfUnionsOnRightSideOfJoin", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to SELECT
         ///Extent1.Id, 
         ///Extent1.EmployeeID, 
         ///Extent1.LastName, 

=== modified file 'MySql.Data.Entity/Tests/Properties/SQLSyntax.resx'
--- a/MySql.Data.Entity/Tests/Properties/SQLSyntax.resx	2011-05-24 01:43:31 +0000
+++ b/MySql.Data.Entity/Tests/Properties/SQLSyntax.resx	2011-05-25 03:37:35 +0000
@@ -201,6 +201,34 @@
 FROM Toys AS Extent2
  WHERE (Project1.Id = Extent2.SupplierId) AND (Extent2.MinAge &lt; 4))</value>
   </data>
+  <data name="JoinOfUnionsOnRightSideOfJoin" xml:space="preserve">
+    <value>SELECT
+1 AS C1, 
+Extent1.Id, 
+Extent1.Name, 
+Join1.Id AS C2, 
+Join1.Name AS C3, 
+Join1.Id1 AS C4, 
+Join1.Name1 AS C5
+FROM Companies AS Extent1 INNER JOIN (SELECT
+UnionAll1.Id, 
+UnionAll1.Name, 
+UnionAll2.Id AS Id1, 
+UnionAll2.Name AS Name1
+FROM (SELECT
+Extent2.Id, 
+Extent2.Name
+FROM Toys AS Extent2 UNION ALL SELECT
+Extent3.Id, 
+Extent3.Name
+FROM Stores AS Extent3) AS UnionAll1 INNER JOIN (SELECT
+Extent4.Id, 
+Extent4.Name
+FROM Authors AS Extent4 UNION ALL SELECT
+Extent5.Id, 
+Extent5.Name
+FROM Books AS Extent5) AS UnionAll2 ON UnionAll1.Id = UnionAll2.Id) AS Join1 ON Extent1.Id = Join1.Id</value>
+  </data>
   <data name="JoinOnRightSideAsDerivedTable" xml:space="preserve">
     <value>SELECT
 Extent1.Id, 


Attachment: [text/bzr-bundle] bzr/reggie.burnett@oracle.com-20110525033925-hmseckvp9g8h0uha.bundle
Thread
bzr commit into connector-net-6.2 branch (reggie.burnett:937) Reggie Burnett25 May