/// <inheritdoc/>
        protected override SqlProvider VisitIntersect(IntersectProvider provider)
        {
            var left  = Compile(provider.Left);
            var right = Compile(provider.Right);

            var leftSelect       = left.Request.Statement;
            var keepOrderForLeft = (leftSelect.HasLimit || leftSelect.HasOffset) && providerInfo.Supports(ProviderFeatures.PagingRequiresOrderBy);

            if (!keepOrderForLeft)
            {
                leftSelect.OrderBy.Clear();
            }

            var rightSelect       = right.Request.Statement;
            var keepOrderForRight = (leftSelect.HasLimit || leftSelect.HasOffset) && providerInfo.Supports(ProviderFeatures.PagingRequiresOrderBy);

            if (!keepOrderForRight)
            {
                rightSelect.OrderBy.Clear();
            }

            var result   = SqlDml.Intersect(leftSelect, rightSelect);
            var queryRef = SqlDml.QueryRef(result);

            SqlSelect query = SqlDml.Select(queryRef);

            query.Columns.AddRange(queryRef.Columns.Cast <SqlColumn>());

            return(CreateProvider(query, provider, left, right));
        }
Example #2
0
        public void IntersectTest()
        {
            SqlSelect s1 = SqlDml.Select(SqlDml.TableRef(Catalog.Schemas["main"].Tables["track"]));

            s1.Columns.Add(SqlDml.Asterisk);
            SqlSelect s2 = SqlDml.Select(SqlDml.TableRef(Catalog.Schemas["main"].Tables["track"]));

            s2.Columns.Add(SqlDml.Asterisk);
            SqlSelect s3 = SqlDml.Select(SqlDml.TableRef(Catalog.Schemas["main"].Tables["track"]));

            s3.Columns.Add(SqlDml.Asterisk);

            Console.WriteLine(sqlDriver.Compile(s1.Intersect(s2)).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(s1.Intersect(s2).Intersect(s3)).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(s1.Intersect(s2.Intersect(s3))).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(SqlDml.Intersect(s1, s2)).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(SqlDml.Intersect(s1, s1.Intersect(s2))).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(SqlDml.Intersect(s1.Intersect(s2), s1)).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(SqlDml.Intersect(s1.Intersect(s2), s1.Intersect(s2))).GetCommandText());
        }
Example #3
0
        public void IntersectTest() //TODO: Relook into the keyword for INTERSECT
        {
            SqlSelect s1 = SqlDml.Select(SqlDml.TableRef(Catalog.DefaultSchema.Tables["address"]));

            s1.Columns.Add(SqlDml.Asterisk);
            SqlSelect s2 = SqlDml.Select(SqlDml.TableRef(Catalog.DefaultSchema.Tables["address"]));

            s2.Columns.Add(SqlDml.Asterisk);
            SqlSelect s3 = SqlDml.Select(SqlDml.TableRef(Catalog.DefaultSchema.Tables["address"]));

            s3.Columns.Add(SqlDml.Asterisk);

            Console.WriteLine(SqlDriver.Compile(s1.Intersect(s2)).GetCommandText());
            Console.WriteLine(SqlDriver.Compile(s1.Intersect(s2).Intersect(s3)).GetCommandText());
            Console.WriteLine(SqlDriver.Compile(s1.Intersect(s2.Intersect(s3))).GetCommandText());
            Console.WriteLine(SqlDriver.Compile(SqlDml.Intersect(s1, s2)).GetCommandText());
            Console.WriteLine(SqlDriver.Compile(SqlDml.Intersect(s1, s1.Intersect(s2))).GetCommandText());
            Console.WriteLine(SqlDriver.Compile(SqlDml.Intersect(s1.Intersect(s2), s1)).GetCommandText());
            Console.WriteLine(SqlDriver.Compile(SqlDml.Intersect(s1.Intersect(s2), s1.Intersect(s2))).GetCommandText());
        }
 public SqlQueryExpression Intersect(ISqlQueryExpression operand)
 {
     return(SqlDml.Intersect(this, operand));
 }