示例#1
0
        public void UnionTest()
        {
            SqlSelect s1 = SqlDml.Select(SqlDml.TableRef(Catalog.Schemas["main"].Tables["track"]));

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

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

            s3.Columns.Add(s3.From["TrackId"]);

            Console.WriteLine(sqlDriver.Compile(s1.Union(s2)).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(s1.Union(s2).Union(s3)).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(s1.Union(s2.Union(s3))).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(SqlDml.Union(s1, s2)).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(SqlDml.Union(s1, s1.Union(s2))).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(SqlDml.Union(s1.Union(s2), s1)).GetCommandText());
            Console.WriteLine(sqlDriver.Compile(SqlDml.Union(s1.Union(s2), s1.Union(s2))).GetCommandText());
            s3.Where = SqlDml.In(1, s1.Union(s2));
            Console.WriteLine(sqlDriver.Compile(s3).GetCommandText());
            SqlQueryRef qr = SqlDml.QueryRef(s1.Union(s2), "qr");

            Assert.Greater(qr.Columns.Count, 0);
        }
示例#2
0
        public void Test201()
        {
            string nativeSql = "SELECT a.f FROM ((SELECT 1 as f UNION SELECT 2) EXCEPT (SELECT 3 UNION SELECT 4)) a";

            SqlSelect s1 = SqlDml.Select();
            SqlSelect s2 = SqlDml.Select();
            SqlSelect s3 = SqlDml.Select();
            SqlSelect s4 = SqlDml.Select();
            SqlSelect select;

            s1.Columns.Add(1, "f");
            s2.Columns.Add(2);
            s3.Columns.Add(3);
            s4.Columns.Add(4);
            SqlQueryRef qr = SqlDml.QueryRef(s1.Union(s2).Except(s3.Union(s4)), "a");

            select = SqlDml.Select(qr);
            select.Columns.Add(qr["f"]);

            Assert.Throws <NotSupportedException>(() => Assert.IsTrue(CompareExecuteNonQuery(nativeSql, select)));
        }