Exemplo n.º 1
0
        protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context)
        {
            var op = Operator;

            if (ob2.DataType is QueryType)
            {
                // The sub-query plan
                IQueryPlanNode plan = (IQueryPlanNode)ob2.Value;
                // Discover the correlated variables for this plan.
                IList <CorrelatedVariable> list = plan.DiscoverCorrelatedVariables(1, new List <CorrelatedVariable>());

                if (list.Count > 0)
                {
                    // Set the correlated variables from the IVariableResolver
                    foreach (CorrelatedVariable variable in list)
                    {
                        variable.SetFromResolver(context.VariableResolver);
                    }
                    // Clear the cache in the context
                    context.QueryContext.ClearCache();
                }

                // Evaluate the plan,
                ITable t = plan.Evaluate(context.QueryContext);

                // The ANY operation
                Operator revPlainOp = op.Plain().Reverse();
                return(DataObject.Boolean(t.ColumnMatchesValue(0, revPlainOp, ob1)));
            }

            if (ob2.DataType is ArrayType)
            {
                Operator plainOp = op.Plain();
                var      expList = (IEnumerable <Expression>)ob2.Value;
                // Assume there are no matches
                DataObject retVal = DataObject.BooleanFalse;
                foreach (Expression exp in expList)
                {
                    DataObject expItem = exp.Evaluate(context.GroupResolver, context.VariableResolver, context.QueryContext);
                    // If null value, return null if there isn't otherwise a match found.
                    if (expItem.IsNull)
                    {
                        retVal = DataObject.BooleanNull;
                    }
                    else
                    {
                        var opExp = Expression.Operator(ob1, plainOp, expItem);
                        if (IsTrue(opExp.Evaluate()))
                        {
                            // 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 ApplicationException("Unknown RHS of ANY.");
        }
Exemplo n.º 2
0
 public static bool ColumnContainsValue(this ITable table, int column, DataObject value)
 {
     return(table.ColumnMatchesValue(column, Operator.Equal, value));
 }