Esempio n. 1
0
		public override AstElement Clone(Dictionary<AstElement, AstElement> alreadyClonedElements)
		{
			InExpression result = new InExpression();
			result._left = (ExpressionNode)_left.Clone(alreadyClonedElements);
			result._rightExpressions = new ExpressionNode[_rightExpressions.Length];
			
			for (int i = 0; i < _rightExpressions.Length; i++)
				result._rightExpressions[i] = (ExpressionNode)_rightExpressions[i].Clone(alreadyClonedElements);
			
			return result;
		}
Esempio n. 2
0
        public override AstElement Clone(Dictionary <AstElement, AstElement> alreadyClonedElements)
        {
            InExpression result = new InExpression();

            result._left             = (ExpressionNode)_left.Clone(alreadyClonedElements);
            result._rightExpressions = new ExpressionNode[_rightExpressions.Length];

            for (int i = 0; i < _rightExpressions.Length; i++)
            {
                result._rightExpressions[i] = (ExpressionNode)_rightExpressions[i].Clone(alreadyClonedElements);
            }

            return(result);
        }
Esempio n. 3
0
        public override ExpressionNode VisitInExpression(InExpression expression)
        {
            // First visit right expressions
            base.VisitInExpression(expression);

            // Check if the IN expression should have been expr = ANY (suquery)

            if (expression.RightExpressions.Length == 1)
            {
                SingleRowSubselect firstElemenAsSubselect = expression.RightExpressions[0] as SingleRowSubselect;

                if (firstElemenAsSubselect != null)
                {
                    AllAnySubselect result = new AllAnySubselect();
                    result.Type  = AllAnySubselect.AllAnyType.Any;
                    result.Left  = expression.Left;
                    result.Op    = BinaryOperator.Equal;
                    result.Query = firstElemenAsSubselect.Query;
                    return(result);
                }
            }

            // IN-expressions can be written as a chain of OR and = expressions:
            //
            // leftExpr IN (rightExpr1 , ... , rightExprN)
            //
            // (leftExpr = rightExpr1) OR (...) OR (leftExpr = rightExprN)

            ExpressionNode resultNode = null;

            foreach (ExpressionNode rightExpression in expression.RightExpressions)
            {
                ExpressionNode   clonedLeft      = (ExpressionNode)expression.Left.Clone();
                BinaryExpression comparisionNode = new BinaryExpression(BinaryOperator.Equal, clonedLeft, rightExpression);

                if (resultNode == null)
                {
                    resultNode = comparisionNode;
                }
                else
                {
                    BinaryExpression orNode = new BinaryExpression(BinaryOperator.LogicalOr, resultNode, comparisionNode);
                    resultNode = orNode;
                }
            }

            // Visit resulting expression.
            return(VisitExpression(resultNode));
        }
Esempio n. 4
0
        public override ExpressionNode VisitInExpression(InExpression expression)
        {
            _xmlWriter.WriteStartElement("inExpression");
            WriteTypeAttribute(expression.ExpressionType);

            WriteAstNode("left", expression.Left);

            for (int i = 0; i < expression.RightExpressions.Length; i++)
            {
                _xmlWriter.WriteStartElement("rightExpression");
                _xmlWriter.WriteAttributeString("index", XmlConvert.ToString(i));
                Visit(expression.RightExpressions[i]);
                _xmlWriter.WriteEndElement();
            }

            _xmlWriter.WriteEndElement();

            return(expression);
        }
Esempio n. 5
0
        public override ExpressionNode VisitInExpression(InExpression expression)
        {
            Visit(expression.Left);
            _writer.Write(" IN (");

            for (int i = 0; i < expression.RightExpressions.Length; i++)
            {
                if (i > 0)
                {
                    _writer.Write(", ");
                }

                Visit(expression.RightExpressions[i]);
            }

            _writer.Write(")");

            return(expression);
        }
Esempio n. 6
0
		private static bool VisitInExpression(InExpression node1, InExpression node2)
		{
			if (node2 == null)
				return false;

			if (!Visit(node1.Left, node2.Left))
				return false;

			if (node1.RightExpressions.Length != node2.RightExpressions.Length)
				return false;

			for (int i = 0; i < node1.RightExpressions.Length; i++)
				if (!Visit(node1.RightExpressions[i], node2.RightExpressions[i]))
					return false;
		
			return true;
		}
Esempio n. 7
0
		public override ExpressionNode VisitInExpression(InExpression expression)
		{
			Visit(expression.Left);
			_writer.Write(" IN (");

			for (int i = 0; i < expression.RightExpressions.Length; i++)
			{
				if (i > 0)
					_writer.Write(", ");

				Visit(expression.RightExpressions[i]);
			}

			_writer.Write(")");

			return expression;
		}
Esempio n. 8
0
        private ExpressionNode ParseSubExpression(ExpressionNode left, int precedence)
        {
            if (left == null)
            {
                // No left operand, so we parse one and take care about leading unary operators

                if (_token.Info.UnaryOperator != null)
                {
                    UnaryOperator op = _token.Info.UnaryOperator;

                    NextToken();

                    ExpressionNode expr = ParseSubExpression(null, op.Precedence);
                    left = new UnaryExpression(op, expr);
                }
                else
                {
                    left = ParseSimpleExpression();
                }
            }

            while (_token.Id != TokenId.Eof)
            {
                // Special handling for NOT BETWEEN, NOT IN, NOT LIKE, NOT SIMILAR TO, and NOT SOUNDSLIKE.

                bool negated = false;

                if (_token.Id == TokenId.NOT)
                {
                    if (_lookahead.Id == TokenId.BETWEEN ||
                        _lookahead.Id == TokenId.IN ||
                        _lookahead.Id == TokenId.LIKE ||
                        _lookahead.Id == TokenId.SIMILAR ||
                        _lookahead.Id == TokenId.SOUNDSLIKE)
                    {
                        NextToken();
                        negated = true;
                    }
                }

                // Special handling for the only ternary operator BETWEEN

                if (_token.Id == TokenId.BETWEEN)
                {
                    NextToken();
                    ExpressionNode lowerBound = ParseSubExpression(null, Operator.BETWEEN_PRECEDENCE);
                    Match(TokenId.AND);
                    ExpressionNode upperBound = ParseSubExpression(null, Operator.BETWEEN_PRECEDENCE);

                    left = new BetweenExpression(left, lowerBound, upperBound);
                }
                else
                {
                    // If there is no binary operator we are finished

                    if (_token.Info.BinaryOperator == null)
                        break;

                    BinaryOperator binaryOp = _token.Info.BinaryOperator;

                    // Precedence is lower, parse it later

                    if (binaryOp.Precedence < precedence)
                        break;

                    // Precedence is equal, but operator ist not right associative, parse it later

                    if (binaryOp.Precedence == precedence && !binaryOp.IsRightAssociative)
                        break;

                    // Precedence is higher

                    NextToken();

                    // Special handling for SIMILAR TO

                    if (binaryOp == BinaryOperator.SimilarTo)
                        Match(TokenId.TO);

                    if (binaryOp == BinaryOperator.In)
                    {
                        // Special handling for IN

                        InExpression inExpression = new InExpression();
                        inExpression.Left = left;
                        inExpression.RightExpressions = ParseSimpleQueryExpressionList();
                        left = inExpression;
                    }
                    else if (_token.Id == TokenId.ANY || _token.Id == TokenId.SOME || _token.Id == TokenId.ALL)
                    {
                        // Special handling for ANY (SOME) and ALL

                        if (binaryOp != BinaryOperator.Equal &&
                            binaryOp != BinaryOperator.NotEqual &&
                            binaryOp != BinaryOperator.Less &&
                            binaryOp != BinaryOperator.LessOrEqual &&
                            binaryOp != BinaryOperator.Greater &&
                            binaryOp != BinaryOperator.GreaterOrEqual)
                        {
                            _errorReporter.InvalidOperatorForAllAny(_token.Range, binaryOp);
                        }

                        AllAnySubselect allAnySubselect = new AllAnySubselect();
                        allAnySubselect.Left = left;
                        allAnySubselect.Op = binaryOp;
                        allAnySubselect.Type = (_token.Id == TokenId.ALL) ? AllAnySubselect.AllAnyType.All : AllAnySubselect.AllAnyType.Any;
                        NextToken();
                        Match(TokenId.LeftParentheses);
                        allAnySubselect.Query = ParseQuery();
                        Match(TokenId.RightParentheses);
                        left = allAnySubselect;
                    }
                    else
                    {
                        left = new BinaryExpression(binaryOp, left, ParseSubExpression(null, binaryOp.Precedence));
                    }
                }

                // Special handling for negated expressions (see above)

                if (negated)
                    left = new UnaryExpression(UnaryOperator.LogicalNot, left);
            }

            return left;
        }
Esempio n. 9
0
		public override ExpressionNode VisitInExpression(InExpression expression)
		{
			// First visit right expressions
			base.VisitInExpression(expression);
			
			// Check if the IN expression should have been expr = ANY (suquery)
			
			if (expression.RightExpressions.Length == 1)
			{
				SingleRowSubselect firstElemenAsSubselect = expression.RightExpressions[0] as SingleRowSubselect;
				
				if (firstElemenAsSubselect != null)
				{
                    AllAnySubselect result = new AllAnySubselect();
                    result.Type = AllAnySubselect.AllAnyType.Any;
                    result.Left = expression.Left;
                    result.Op = BinaryOperator.Equal;
                    result.Query = firstElemenAsSubselect.Query;
					return result;
				}
			}
			
			// IN-expressions can be written as a chain of OR and = expressions:
			//
			// leftExpr IN (rightExpr1 , ... , rightExprN)
			//
			// (leftExpr = rightExpr1) OR (...) OR (leftExpr = rightExprN)

			ExpressionNode resultNode = null;

			foreach (ExpressionNode rightExpression in expression.RightExpressions)
			{
				ExpressionNode clonedLeft = (ExpressionNode) expression.Left.Clone();
				BinaryExpression comparisionNode = new BinaryExpression(BinaryOperator.Equal, clonedLeft, rightExpression);
				
				if (resultNode == null)
					resultNode = comparisionNode;
				else
				{
					BinaryExpression orNode = new BinaryExpression(BinaryOperator.LogicalOr, resultNode, comparisionNode);
					resultNode = orNode;
				}
			}

			// Visit resulting expression.
			return VisitExpression(resultNode);
		}
Esempio n. 10
0
		public virtual ExpressionNode VisitInExpression(InExpression expression)
		{
			for (int i = 0; i < expression.RightExpressions.Length; i++)
				expression.RightExpressions[i] = VisitExpression(expression.RightExpressions[i]);

			return expression;
		}
Esempio n. 11
0
        private ExpressionNode ParseSubExpression(ExpressionNode left, int precedence)
        {
            if (left == null)
            {
                // No left operand, so we parse one and take care about leading unary operators

                if (_token.Info.UnaryOperator != null)
                {
                    UnaryOperator op = _token.Info.UnaryOperator;

                    NextToken();

                    ExpressionNode expr = ParseSubExpression(null, op.Precedence);
                    left = new UnaryExpression(op, expr);
                }
                else
                {
                    left = ParseSimpleExpression();
                }
            }

            while (_token.Id != TokenId.Eof)
            {
                // Special handling for NOT BETWEEN, NOT IN, NOT LIKE, NOT SIMILAR TO, and NOT SOUNDSLIKE.

                bool negated = false;

                if (_token.Id == TokenId.NOT)
                {
                    if (_lookahead.Id == TokenId.BETWEEN ||
                        _lookahead.Id == TokenId.IN ||
                        _lookahead.Id == TokenId.LIKE ||
                        _lookahead.Id == TokenId.SIMILAR ||
                        _lookahead.Id == TokenId.SOUNDSLIKE)
                    {
                        NextToken();
                        negated = true;
                    }
                }

                // Special handling for the only ternary operator BETWEEN

                if (_token.Id == TokenId.BETWEEN)
                {
                    NextToken();
                    ExpressionNode lowerBound = ParseSubExpression(null, Operator.BETWEEN_PRECEDENCE);
                    Match(TokenId.AND);
                    ExpressionNode upperBound = ParseSubExpression(null, Operator.BETWEEN_PRECEDENCE);

                    left = new BetweenExpression(left, lowerBound, upperBound);
                }
                else
                {
                    // If there is no binary operator we are finished

                    if (_token.Info.BinaryOperator == null)
                    {
                        break;
                    }

                    BinaryOperator binaryOp = _token.Info.BinaryOperator;

                    // Precedence is lower, parse it later

                    if (binaryOp.Precedence < precedence)
                    {
                        break;
                    }

                    // Precedence is equal, but operator ist not right associative, parse it later

                    if (binaryOp.Precedence == precedence && !binaryOp.IsRightAssociative)
                    {
                        break;
                    }

                    // Precedence is higher

                    NextToken();

                    // Special handling for SIMILAR TO

                    if (binaryOp == BinaryOperator.SimilarTo)
                    {
                        Match(TokenId.TO);
                    }

                    if (binaryOp == BinaryOperator.In)
                    {
                        // Special handling for IN

                        InExpression inExpression = new InExpression();
                        inExpression.Left             = left;
                        inExpression.RightExpressions = ParseSimpleQueryExpressionList();
                        left = inExpression;
                    }
                    else if (_token.Id == TokenId.ANY || _token.Id == TokenId.SOME || _token.Id == TokenId.ALL)
                    {
                        // Special handling for ANY (SOME) and ALL

                        if (binaryOp != BinaryOperator.Equal &&
                            binaryOp != BinaryOperator.NotEqual &&
                            binaryOp != BinaryOperator.Less &&
                            binaryOp != BinaryOperator.LessOrEqual &&
                            binaryOp != BinaryOperator.Greater &&
                            binaryOp != BinaryOperator.GreaterOrEqual)
                        {
                            _errorReporter.InvalidOperatorForAllAny(_token.Range, binaryOp);
                        }

                        AllAnySubselect allAnySubselect = new AllAnySubselect();
                        allAnySubselect.Left = left;
                        allAnySubselect.Op   = binaryOp;
                        allAnySubselect.Type = (_token.Id == TokenId.ALL) ? AllAnySubselect.AllAnyType.All : AllAnySubselect.AllAnyType.Any;
                        NextToken();
                        Match(TokenId.LeftParentheses);
                        allAnySubselect.Query = ParseQuery();
                        Match(TokenId.RightParentheses);
                        left = allAnySubselect;
                    }
                    else
                    {
                        left = new BinaryExpression(binaryOp, left, ParseSubExpression(null, binaryOp.Precedence));
                    }
                }

                // Special handling for negated expressions (see above)

                if (negated)
                {
                    left = new UnaryExpression(UnaryOperator.LogicalNot, left);
                }
            }

            return(left);
        }
Esempio n. 12
0
		public override ExpressionNode VisitInExpression(InExpression expression)
		{
			_xmlWriter.WriteStartElement("inExpression");
			WriteTypeAttribute(expression.ExpressionType);

			WriteAstNode("left", expression.Left);

			for (int i = 0; i < expression.RightExpressions.Length; i++)
			{
				_xmlWriter.WriteStartElement("rightExpression");
				_xmlWriter.WriteAttributeString("index", XmlConvert.ToString(i));
				Visit(expression.RightExpressions[i]);
				_xmlWriter.WriteEndElement();
			}

			_xmlWriter.WriteEndElement();

			return expression;
		}