SelectUnion() public method

first token is either MySqlToken.KwSelect or MySqlToken.PuncLeftParen which has been scanned but not yet consumed
public SelectUnion ( ) : DmlQueryStatement
return Tup.Cobar4Net.Parser.Ast.Stmt.Dml.DmlQueryStatement
Ejemplo n.º 1
0
        public virtual void TestSelectUnion()
        {
            var sql =
                "(select id from t1) union all (select id from t2) union all (select id from t3) ordeR By d desC limit 1 offset ?";
            var lexer  = new MySqlLexer(sql);
            var parser = new MySqlDmlSelectParser(lexer, new MySqlExprParser(lexer));
            var select = (DmlSelectUnionStatement)parser.SelectUnion();

            Assert.AreEqual(0, @select.FirstDistinctIndex);
            Assert.AreEqual(3, @select.SelectStmtList.Count);
            var output = Output2MySql(select, sql);

            Assert.AreEqual(
                "(SELECT id FROM t1) UNION ALL (SELECT id FROM t2) UNION ALL (SELECT id FROM t3) ORDER BY d DESC LIMIT ?, 1",
                output);
            sql =
                "(select id from t1) union  select id from t2 order by id union aLl (select id from t3) ordeR By d asC";
            lexer  = new MySqlLexer(sql);
            parser = new MySqlDmlSelectParser(lexer, new MySqlExprParser(lexer));
            select = (DmlSelectUnionStatement)parser.SelectUnion();
            Assert.AreEqual(1, @select.FirstDistinctIndex);
            Assert.AreEqual(3, @select.SelectStmtList.Count);
            output = Output2MySql(select, sql);
            Assert.AreEqual(
                "(SELECT id FROM t1) UNION (SELECT id FROM t2 ORDER BY id) UNION ALL (SELECT id FROM t3) ORDER BY d",
                output);
            sql    = "(select id from t1) union distInct (select id from t2) union  select id from t3";
            lexer  = new MySqlLexer(sql);
            parser = new MySqlDmlSelectParser(lexer, new MySqlExprParser(lexer));
            select = (DmlSelectUnionStatement)parser.SelectUnion();
            Assert.AreEqual(2, @select.FirstDistinctIndex);
            Assert.AreEqual(3, @select.SelectStmtList.Count);
            output = Output2MySql(select, sql);
            Assert.AreEqual("(SELECT id FROM t1) UNION (SELECT id FROM t2) UNION (SELECT id FROM t3)", output);
        }
 public virtual void TestSelectUnion()
 {
     var sql =
         "(select id from t1) union all (select id from t2) union all (select id from t3) ordeR By d desC limit 1 offset ?";
     var lexer = new MySqlLexer(sql);
     var parser = new MySqlDmlSelectParser(lexer, new MySqlExprParser(lexer));
     var select = (DmlSelectUnionStatement)parser.SelectUnion();
     Assert.AreEqual(0, @select.FirstDistinctIndex);
     Assert.AreEqual(3, @select.SelectStmtList.Count);
     var output = Output2MySql(select, sql);
     Assert.AreEqual(
         "(SELECT id FROM t1) UNION ALL (SELECT id FROM t2) UNION ALL (SELECT id FROM t3) ORDER BY d DESC LIMIT ?, 1",
         output);
     sql =
         "(select id from t1) union  select id from t2 order by id union aLl (select id from t3) ordeR By d asC";
     lexer = new MySqlLexer(sql);
     parser = new MySqlDmlSelectParser(lexer, new MySqlExprParser(lexer));
     select = (DmlSelectUnionStatement)parser.SelectUnion();
     Assert.AreEqual(1, @select.FirstDistinctIndex);
     Assert.AreEqual(3, @select.SelectStmtList.Count);
     output = Output2MySql(select, sql);
     Assert.AreEqual(
         "(SELECT id FROM t1) UNION (SELECT id FROM t2 ORDER BY id) UNION ALL (SELECT id FROM t3) ORDER BY d",
         output);
     sql = "(select id from t1) union distInct (select id from t2) union  select id from t3";
     lexer = new MySqlLexer(sql);
     parser = new MySqlDmlSelectParser(lexer, new MySqlExprParser(lexer));
     select = (DmlSelectUnionStatement)parser.SelectUnion();
     Assert.AreEqual(2, @select.FirstDistinctIndex);
     Assert.AreEqual(3, @select.SelectStmtList.Count);
     output = Output2MySql(select, sql);
     Assert.AreEqual("(SELECT id FROM t1) UNION (SELECT id FROM t2) UNION (SELECT id FROM t3)", output);
 }