Exemplo n.º 1
0
        public void TestSelectStarFromTableWithAlias()
        {
            StatementList statementList = new StatementList()
            {
                Statements = new List <Statement>()
                {
                    new SelectStatement()
                    {
                        SelectElements = new List <Expressions.SelectExpression>()
                        {
                            new SelectStarExpression()
                        },
                        FromClause = new Clauses.FromClause()
                        {
                            TableReference = new FromTableReference()
                            {
                                TableName = "test",
                                Alias     = "t"
                            }
                        }
                    }
                }
            };

            var expected = "SELECT * FROM test t";
            var actual   = statementList.Print();

            actual.Should().Be(expected);
        }
Exemplo n.º 2
0
 public string Print(string prefix)
 {
     if (_elseBranchStatements != null)
     {
         return(string.Format("If ({0}) Then\n {1} Else {2}", _conditionExpr.Print(prefix), _ifBranchStatements.Print(prefix),
                              _elseBranchStatements.Print(prefix)));
     }
     return(string.Format("If ({0}) Then\n {1}", _conditionExpr.Print(prefix), _ifBranchStatements.Print(prefix)));
 }
Exemplo n.º 3
0
 public string Print(string prefix)
 {
     if (_elseBranchStatements != null)
     {
         return(string.Format("Case ({0}) Then\n {1} Else {2}", _conditionExpr.Print(prefix), String.Join("\n", _whenBranchStatements.Select(x => String.Format("WHEN {0}: {1}", x.Key.Print(prefix), x.Value.Print(prefix)))),
                              _elseBranchStatements.Print(prefix)));
     }
     return(string.Format("If ({0}) Then\n {1}", _conditionExpr.Print(prefix), String.Join("\n", _whenBranchStatements.Select(x => String.Format("WHEN {0}: {1}", x.Key.Print(prefix), x.Value.Print(prefix))))));
 }
Exemplo n.º 4
0
        public void TestSelectBinaryBitwiseSubtract()
        {
            StatementList statementList = GetBinaryTestStructure(BinaryType.Subtract);

            var expected = "SELECT c1 - 'a'";
            var actual   = statementList.Print();

            actual.Should().Be(expected);
        }
Exemplo n.º 5
0
        public void TestSelectWhereComparison()
        {
            StatementList statementList = new StatementList()
            {
                Statements = new List <Statement>()
                {
                    new SelectStatement()
                    {
                        SelectElements = new List <Expressions.SelectExpression>()
                        {
                            new SelectStarExpression()
                        },
                        FromClause = new Clauses.FromClause()
                        {
                            TableReference = new FromTableReference()
                            {
                                TableName = "test"
                            }
                        },
                        WhereClause = new Clauses.WhereClause()
                        {
                            Expression = new BooleanComparisonExpression()
                            {
                                Left = new ColumnReference()
                                {
                                    Identifiers = new List <string>()
                                    {
                                        "c1"
                                    }
                                },
                                Right = new StringLiteral()
                                {
                                    Value = "a"
                                },
                                Type = BooleanComparisonType.Equals
                            }
                        }
                    }
                }
            };

            var expected = "SELECT * FROM test WHERE c1 = 'a'";
            var actual   = statementList.Print();

            actual.Should().Be(expected);
        }
Exemplo n.º 6
0
        public void TestSelecColumnsWithAlias()
        {
            StatementList statementList = new StatementList()
            {
                Statements = new List <Statement>()
                {
                    new SelectStatement()
                    {
                        SelectElements = new List <Expressions.SelectExpression>()
                        {
                            new SelectScalarExpression()
                            {
                                Expression = new ColumnReference()
                                {
                                    Identifiers = new List <string>()
                                    {
                                        "c1"
                                    }
                                },
                                Alias = "a"
                            },
                            new SelectScalarExpression()
                            {
                                Expression = new ColumnReference()
                                {
                                    Identifiers = new List <string>()
                                    {
                                        "c2"
                                    }
                                },
                                Alias = "b"
                            }
                        }
                    }
                }
            };

            var expected = "SELECT c1 AS a, c2 AS b";
            var actual   = statementList.Print();

            actual.Should().Be(expected);
        }
Exemplo n.º 7
0
        public void TestSelectStar()
        {
            StatementList statementList = new StatementList()
            {
                Statements = new List <Statement>()
                {
                    new SelectStatement()
                    {
                        SelectElements = new List <Expressions.SelectExpression>()
                        {
                            new SelectStarExpression()
                        }
                    }
                }
            };

            var expected = "SELECT *";
            var actual   = statementList.Print();

            actual.Should().Be(expected);
        }
Exemplo n.º 8
0
 public string Print(string prefix)
 {
     return(String.Format("{0}FOR {1} IN {2}\n{3}\n{4}", prefix, _var, _value.Print(""), _attributes.Print(prefix + ": "), _statements.Print(prefix + "    ")));
 }
Exemplo n.º 9
0
 public string Print(string prefix)
 {
     return(prefix + String.Format("CAPTURE {0}\n{1}", _var, _captureList.Print(prefix + "    ")));
 }
Exemplo n.º 10
0
 public string Print(string prefix)
 {
     return(prefix +
            String.Format("TableRow {0} IN {1}\n{2}\n{3}", _var, _value.Print(""),
                          _attributes.Print(prefix + ": "), _statements.Print(prefix + "    ")));
 }