public static SqlExpressionType SubQueryPlainType(this SqlExpressionType type)
        {
            if (type.IsAny())
            {
                if (type == SqlExpressionType.AnyEqual)
                {
                    return(SqlExpressionType.Equal);
                }
                if (type == SqlExpressionType.AnyNotEqual)
                {
                    return(SqlExpressionType.NotEqual);
                }
                if (type == SqlExpressionType.AnyGreaterThan)
                {
                    return(SqlExpressionType.GreaterThan);
                }
                if (type == SqlExpressionType.AnyGreaterOrEqualThan)
                {
                    return(SqlExpressionType.GreaterOrEqualThan);
                }
                if (type == SqlExpressionType.AnySmallerThan)
                {
                    return(SqlExpressionType.AnySmallerThan);
                }
                if (type == SqlExpressionType.AnySmallerOrEqualThan)
                {
                    return(SqlExpressionType.SmallerOrEqualThan);
                }
            }

            if (type.IsAll())
            {
                if (type == SqlExpressionType.AllEqual)
                {
                    return(SqlExpressionType.Equal);
                }
                if (type == SqlExpressionType.AllNotEqual)
                {
                    return(SqlExpressionType.NotEqual);
                }
                if (type == SqlExpressionType.AllGreaterThan)
                {
                    return(SqlExpressionType.GreaterThan);
                }
                if (type == SqlExpressionType.AllGreaterOrEqualThan)
                {
                    return(SqlExpressionType.GreaterOrEqualThan);
                }
                if (type == SqlExpressionType.AllSmallerThan)
                {
                    return(SqlExpressionType.AllSmallerThan);
                }
                if (type == SqlExpressionType.AllSmallerOrEqualThan)
                {
                    return(SqlExpressionType.SmallerOrEqualThan);
                }
            }

            throw new ArgumentException();
        }
        public static SqlExpressionType Inverse(this SqlExpressionType type)
        {
            if (type.IsSubQuery())
            {
                var plainType = type.SubQueryPlainType();
                var invType   = plainType.Inverse();

                if (type.IsAny())
                {
                    return(invType.Any());
                }
                if (type.IsAll())
                {
                    return(invType.All());
                }
            }

            switch (type)
            {
            case SqlExpressionType.Equal:
                return(SqlExpressionType.NotEqual);

            case SqlExpressionType.NotEqual:
                return(SqlExpressionType.Equal);

            case SqlExpressionType.GreaterThan:
                return(SqlExpressionType.SmallerOrEqualThan);

            case SqlExpressionType.SmallerThan:
                return(SqlExpressionType.GreaterOrEqualThan);

            case SqlExpressionType.GreaterOrEqualThan:
                return(SqlExpressionType.SmallerThan);

            case SqlExpressionType.SmallerOrEqualThan:
                return(SqlExpressionType.GreaterThan);

            case SqlExpressionType.And:
                return(SqlExpressionType.Or);

            case SqlExpressionType.Or:
                return(SqlExpressionType.And);

            case SqlExpressionType.Like:
                return(SqlExpressionType.NotLike);

            case SqlExpressionType.NotLike:
                return(SqlExpressionType.Like);

            case SqlExpressionType.Is:
                return(SqlExpressionType.IsNot);

            case SqlExpressionType.IsNot:
                return(SqlExpressionType.Is);
            }

            throw new ArgumentException();
        }
        private DataObject EvaluateBinary(DataObject left, SqlExpressionType binaryType, DataObject right)
        {
            if (binaryType.IsAll())
                return left.Any(binaryType.SubQueryPlainType(), right, context);
            if (binaryType.IsAny())
                return left.All(binaryType.SubQueryPlainType(), right, context);

            switch (binaryType) {
                case SqlExpressionType.Add:
                    return left.Add(right);
                case SqlExpressionType.Subtract:
                    return left.Subtract(right);
                case SqlExpressionType.Multiply:
                    return left.Multiply(right);
                case SqlExpressionType.Divide:
                    return left.Divide(right);
                case SqlExpressionType.Modulo:
                    return left.Modulus(right);
                case SqlExpressionType.GreaterThan:
                    return left.IsGreaterThan(right);
                case SqlExpressionType.GreaterOrEqualThan:
                    return left.IsGreterOrEqualThan(right);
                case SqlExpressionType.SmallerThan:
                    return left.IsSmallerThan(right);
                case SqlExpressionType.SmallerOrEqualThan:
                    return left.IsSmallerOrEqualThan(right);
                case SqlExpressionType.Equal:
                    return left.IsEqualTo(right);
                case SqlExpressionType.NotEqual:
                    return left.IsNotEqualTo(right);
                case SqlExpressionType.Is:
                    return left.Is(right);
                case SqlExpressionType.IsNot:
                    return left.IsNot(right);
                case SqlExpressionType.Like:
                    return left.IsLike(right);
                case SqlExpressionType.NotLike:
                    return left.IsNotLike(right);
                case SqlExpressionType.And:
                    return left.And(right);
                case SqlExpressionType.Or:
                    return left.Or(right);
                case SqlExpressionType.XOr:
                    return left.XOr(right);
                // TODO: ANY and ALL
                default:
                    throw new ExpressionEvaluateException(String.Format("The type {0} is not a binary expression or is not supported.", binaryType));
            }
        }
 public static bool IsSubQuery(this SqlExpressionType type)
 {
     return(type.IsAny() || type.IsAll());
 }
예제 #5
0
        private DataObject EvaluateBinary(DataObject left, SqlExpressionType binaryType, DataObject right)
        {
            if (binaryType.IsAll())
            {
                return(left.Any(binaryType.SubQueryPlainType(), right, context));
            }
            if (binaryType.IsAny())
            {
                return(left.All(binaryType.SubQueryPlainType(), right, context));
            }

            switch (binaryType)
            {
            case SqlExpressionType.Add:
                return(left.Add(right));

            case SqlExpressionType.Subtract:
                return(left.Subtract(right));

            case SqlExpressionType.Multiply:
                return(left.Multiply(right));

            case SqlExpressionType.Divide:
                return(left.Divide(right));

            case SqlExpressionType.Modulo:
                return(left.Modulus(right));

            case SqlExpressionType.GreaterThan:
                return(left.IsGreaterThan(right));

            case SqlExpressionType.GreaterOrEqualThan:
                return(left.IsGreterOrEqualThan(right));

            case SqlExpressionType.SmallerThan:
                return(left.IsSmallerThan(right));

            case SqlExpressionType.SmallerOrEqualThan:
                return(left.IsSmallerOrEqualThan(right));

            case SqlExpressionType.Equal:
                return(left.IsEqualTo(right));

            case SqlExpressionType.NotEqual:
                return(left.IsNotEqualTo(right));

            case SqlExpressionType.Is:
                return(left.Is(right));

            case SqlExpressionType.IsNot:
                return(left.IsNot(right));

            case SqlExpressionType.Like:
                return(left.IsLike(right));

            case SqlExpressionType.NotLike:
                return(left.IsNotLike(right));

            case SqlExpressionType.And:
                return(left.And(right));

            case SqlExpressionType.Or:
                return(left.Or(right));

            case SqlExpressionType.XOr:
                return(left.XOr(right));

            // TODO: ANY and ALL
            default:
                throw new ExpressionEvaluateException(String.Format("The type {0} is not a binary expression or is not supported.", binaryType));
            }
        }
예제 #6
0
        public static SqlBinaryExpression Binary(SqlExpression left, SqlExpressionType expressionType, SqlExpression right)
        {
            if (expressionType == SqlExpressionType.Add)
                return Add(left, right);
            if (expressionType == SqlExpressionType.Subtract)
                return Subtract(left, right);
            if (expressionType == SqlExpressionType.Multiply)
                return Multiply(left, right);
            if (expressionType == SqlExpressionType.Divide)
                return Divide(left, right);
            if (expressionType == SqlExpressionType.Modulo)
                return Modulo(left, right);

            if (expressionType == SqlExpressionType.Equal)
                return Equal(left, right);
            if (expressionType == SqlExpressionType.NotEqual)
                return NotEqual(left, right);
            if (expressionType == SqlExpressionType.Is)
                return Is(left, right);
            if (expressionType == SqlExpressionType.IsNot)
                return IsNot(left, right);
            if (expressionType == SqlExpressionType.GreaterThan)
                return GreaterThan(left, right);
            if (expressionType == SqlExpressionType.GreaterOrEqualThan)
                return GreaterOrEqualThan(left, right);
            if (expressionType == SqlExpressionType.SmallerThan)
                return SmallerThan(left, right);
            if (expressionType == SqlExpressionType.SmallerOrEqualThan)
                return SmallerOrEqualThan(left, right);

            if (expressionType == SqlExpressionType.Like)
                return Like(left, right);
            if (expressionType == SqlExpressionType.NotLike)
                return NotLike(left, right);

            if (expressionType == SqlExpressionType.And)
                return And(left, right);
            if (expressionType == SqlExpressionType.Or)
                return Or(left, right);
            if (expressionType == SqlExpressionType.XOr)
                return XOr(left, right);

            if (expressionType.IsAny())
                return Any(left, expressionType.SubQueryPlainType(), right);
            if (expressionType.IsAll())
                return All(left, expressionType.SubQueryPlainType(), right);

            throw new ArgumentException(String.Format("Expression type {0} is not a Binary", expressionType));
        }
예제 #7
0
        public static SqlBinaryExpression Binary(SqlExpression left, SqlExpressionType expressionType, SqlExpression right)
        {
            if (expressionType == SqlExpressionType.Add)
            {
                return(Add(left, right));
            }
            if (expressionType == SqlExpressionType.Subtract)
            {
                return(Subtract(left, right));
            }
            if (expressionType == SqlExpressionType.Multiply)
            {
                return(Multiply(left, right));
            }
            if (expressionType == SqlExpressionType.Divide)
            {
                return(Divide(left, right));
            }
            if (expressionType == SqlExpressionType.Modulo)
            {
                return(Modulo(left, right));
            }

            if (expressionType == SqlExpressionType.Equal)
            {
                return(Equal(left, right));
            }
            if (expressionType == SqlExpressionType.NotEqual)
            {
                return(NotEqual(left, right));
            }
            if (expressionType == SqlExpressionType.Is)
            {
                return(Is(left, right));
            }
            if (expressionType == SqlExpressionType.IsNot)
            {
                return(IsNot(left, right));
            }
            if (expressionType == SqlExpressionType.GreaterThan)
            {
                return(GreaterThan(left, right));
            }
            if (expressionType == SqlExpressionType.GreaterOrEqualThan)
            {
                return(GreaterOrEqualThan(left, right));
            }
            if (expressionType == SqlExpressionType.SmallerThan)
            {
                return(SmallerThan(left, right));
            }
            if (expressionType == SqlExpressionType.SmallerOrEqualThan)
            {
                return(SmallerOrEqualThan(left, right));
            }

            if (expressionType == SqlExpressionType.Like)
            {
                return(Like(left, right));
            }
            if (expressionType == SqlExpressionType.NotLike)
            {
                return(NotLike(left, right));
            }

            if (expressionType == SqlExpressionType.And)
            {
                return(And(left, right));
            }
            if (expressionType == SqlExpressionType.Or)
            {
                return(Or(left, right));
            }
            if (expressionType == SqlExpressionType.XOr)
            {
                return(XOr(left, right));
            }

            if (expressionType.IsAny())
            {
                return(Any(left, expressionType.SubQueryPlainType(), right));
            }
            if (expressionType.IsAll())
            {
                return(All(left, expressionType.SubQueryPlainType(), right));
            }

            throw new ArgumentException(String.Format("Expression type {0} is not a Binary", expressionType));
        }