public void Test_can_parse_single_condition_as_expression()
        {
            CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery("where foo != 'bar'");

            CmsqlParser.WhereClauseContext parseTree = cmsqlParser.whereClause();

            WhereClauseVisitor    visitor    = new WhereClauseVisitor();
            ICmsqlQueryExpression expression = visitor.VisitWhereClause(parseTree);

            expression.Should().BeOfType <CmsqlQueryCondition>();
        }
        public void Test_can_parse_grouped_expression_and_condition()
        {
            CmsqlParser cmsqlParser = CmsqlParserFactory.CreateParserForQuery("where (bar = 'foo' and foo = 'bar') or foo != 'bar'");

            CmsqlParser.WhereClauseContext parseTree = cmsqlParser.whereClause();

            WhereClauseVisitor         visitor          = new WhereClauseVisitor();
            CmsqlQueryBinaryExpression binaryExpression = visitor.VisitWhereClause(parseTree) as CmsqlQueryBinaryExpression;

            binaryExpression.Operator.ShouldBeEquivalentTo(ConditionalOperator.Or);
            binaryExpression.LeftExpression.Should().BeOfType <CmsqlQueryBinaryExpression>();
            binaryExpression.RightExpression.Should().BeOfType <CmsqlQueryCondition>();
        }
Beispiel #3
0
        public override CmsqlQuery VisitQuery(CmsqlParser.QueryContext context)
        {
            CmsqlQuery query = new CmsqlQuery();

            SelectClauseVisitor selectClauseVisitor = new SelectClauseVisitor();

            query.ContentType = context.selectClause().Accept(selectClauseVisitor);

            FromClauseVisitor fromClauseVisitor = new FromClauseVisitor();

            query.StartNode = context.fromClause().Accept(fromClauseVisitor);

            CmsqlParser.WhereClauseContext whereClauseContext = context.whereClause();
            if (whereClauseContext != null)
            {
                WhereClauseVisitor whereClauseVisitor = new WhereClauseVisitor();
                query.Criteria = whereClauseContext.Accept(whereClauseVisitor);
            }

            return(query);
        }
Beispiel #4
0
        public override ICmsqlQueryExpression VisitWhereClause(CmsqlParser.WhereClauseContext context)
        {
            ExpressionVisitor expressionVisitor = new ExpressionVisitor();

            return(context.expression().Accept(expressionVisitor));
        }