Exemplo n.º 1
0
        public static DataObject EvaluateAll(SqlExpressionType plainType, DataObject ob1, DataObject ob2,
                                             EvaluateContext context)
        {
            if (ob2.Type is QueryType)
            {
                // The sub-query plan
                var planObj = (SqlQueryObject)ob2.Value;

                // Discover the correlated variables for this plan.
                var list = planObj.QueryPlan.DiscoverQueryReferences(1);

                if (list.Count > 0)
                {
                    // Set the correlated variables from the IVariableResolver
                    foreach (var variable in list)
                    {
                        variable.Evaluate(context.VariableResolver);
                    }

                    // Clear the cache in the context
                    context.Request.Query.ClearCachedTables();
                }

                // Evaluate the plan,
                var t = planObj.QueryPlan.Evaluate(context.Request);

                var revPlainOp = plainType.Reverse();
                return(DataObject.Boolean(t.AllRowsMatchColumnValue(0, revPlainOp, ob1)));
            }
            if (ob2.Type is ArrayType)
            {
                var expList = (SqlArray)ob2.Value;

                // Assume true unless otherwise found to be false or NULL.
                DataObject retVal = DataObject.BooleanTrue;
                foreach (var exp in expList)
                {
                    var expItem = exp.Evaluate(context);

                    if (expItem.ExpressionType != SqlExpressionType.Constant)
                    {
                        throw new InvalidOperationException();
                    }

                    var evalItem = (SqlConstantExpression)expItem;

                    // If there is a null item, we return null if not otherwise found to
                    // be false.
                    if (evalItem.Value.IsNull)
                    {
                        retVal = DataObject.BooleanNull;
                    }
                    else if (!IsTrue(Evaluate(ob1, plainType, evalItem.Value, context)))
                    {
                        // If it doesn't match return false
                        return(DataObject.BooleanFalse);
                    }
                }

                // Otherwise return true or null.  If all match and no NULLs return
                // true.  If all match and there are NULLs then return NULL.
                return(retVal);
            }

            throw new InvalidOperationException("Unknown RHS of ALL.");
        }
Exemplo n.º 2
0
 private static bool IsTrue(DataObject b)
 {
     return(!b.IsNull &&
            b.Type is BooleanType &&
            b.Value.Equals(SqlBoolean.True));
 }
Exemplo n.º 3
0
        public static DataObject EvaluateAny(SqlExpressionType plainType, DataObject ob1, DataObject ob2, EvaluateContext context)
        {
            if (ob2.Type is QueryType)
            {
                // The sub-query plan
                var plan = ((SqlQueryObject)ob2.Value).QueryPlan;
                // Discover the correlated variables for this plan.
                var list = plan.DiscoverQueryReferences(1);

                if (list.Count > 0)
                {
                    // Set the correlated variables from the IVariableResolver
                    foreach (var variable in list)
                    {
                        variable.Evaluate(context.VariableResolver);
                    }

                    // Clear the cache in the context
                    context.Request.Query.ClearCachedTables();
                }

                // Evaluate the plan,
                var t = plan.Evaluate(context.Request);

                // The ANY operation
                var revPlainOp = plainType.Reverse();
                // TODO: return t.ColumnMatchesValue(0, revPlainOp, ob1);
                throw new NotImplementedException();
            }

            if (ob2.Type is ArrayType)
            {
                var expList = (SqlArray)ob2.Value;
                // Assume there are no matches
                var retVal = DataObject.BooleanFalse;
                foreach (var exp in expList)
                {
                    var expItem = exp.Evaluate(context);
                    if (expItem.ExpressionType != SqlExpressionType.Constant)
                    {
                        throw new InvalidOperationException();
                    }

                    var evalItem = (SqlConstantExpression)expItem;

                    // If null value, return null if there isn't otherwise a match found.
                    if (evalItem.Value.IsNull)
                    {
                        retVal = DataObject.BooleanNull;
                    }
                    else if (IsTrue(Evaluate(ob1, plainType, evalItem.Value, context)))
                    {
                        // If there is a match, the ANY set test is true
                        return(DataObject.BooleanTrue);
                    }
                }
                // No matches, so return either false or NULL.  If there are no matches
                // and no nulls, return false.  If there are no matches and there are
                // nulls present, return null.
                return(retVal);
            }

            throw new InvalidOperationException("Unknown RHS of ANY.");
        }
Exemplo n.º 4
0
        private static DataObject Evaluate(DataObject left, SqlExpressionType binaryType, DataObject right, EvaluateContext context)
        {
            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));
            }
        }
Exemplo n.º 5
0
 public override DataObject Evaluate(DataObject ob1, DataObject ob2,
                                     IGroupResolver group, IVariableResolver resolver,
                                     IQueryContext context)
 {
     return(ob1.Is(ob2));
 }
Exemplo n.º 6
0
 public DataObject Evaluate(DataObject obj1, DataObject obj2)
 {
     return(Evaluate(obj1, obj2, null, null, null));
 }
Exemplo n.º 7
0
 public abstract DataObject Evaluate(DataObject ob1, DataObject ob2, IGroupResolver group, IVariableResolver resolver, IQueryContext context);
Exemplo n.º 8
0
 public override DataObject Evaluate(DataObject ob1, DataObject ob2,
                                     IGroupResolver group, IVariableResolver resolver,
                                     IQueryContext context)
 {
     throw new ApplicationException("SimpleOperator should never be evaluated!");
 }