Esempio n. 1
0
        public void Create_False()
        {
            var obj = DataObject.Boolean(false);

            Assert.IsNotNull(obj);
            Assert.IsInstanceOf <SqlBoolean>(obj.Value);
            Assert.AreEqual(false, (bool)obj.AsBoolean());
        }
Esempio n. 2
0
        public void Convert_False_ToNumber()
        {
            var obj = DataObject.Boolean(false);

            Assert.IsNotNull(obj);
            Assert.IsInstanceOf <SqlBoolean>(obj.Value);
            Assert.AreEqual(false, (bool)obj.AsBoolean());

            DataObject numObj = null;

            Assert.DoesNotThrow(() => numObj = obj.AsInteger());
            Assert.IsNotNull(numObj);
            Assert.AreEqual(0, (int)numObj);
        }
Esempio n. 3
0
            public override DataObject Evaluate(DataObject ob1, DataObject ob2,
                                                IGroupResolver group, IVariableResolver resolver,
                                                IQueryContext context)
            {
                if (ob1.IsNull)
                {
                    return(ob1);
                }
                if (ob2.IsNull)
                {
                    return(ob2);
                }
                String val     = ob1.CastTo(PrimitiveTypes.String()).ToStringValue();
                String pattern = ob2.CastTo(PrimitiveTypes.String()).ToStringValue();

                return(DataObject.Boolean(PatternSearch.FullPatternMatch(pattern, val, '\\')));
            }
Esempio n. 4
0
            public override DataObject Evaluate(DataObject ob1, DataObject ob2, IGroupResolver group, IVariableResolver resolver, IQueryContext context)
            {
                bool?b1 = ob1.ToBoolean();
                bool?b2 = ob2.ToBoolean();

                // If either ob1 or ob2 are null
                if (!b1.HasValue)
                {
                    return(b2.HasValue && b2.Equals(false) ? DataObject.BooleanFalse : DataObject.BooleanNull);
                }
                if (!b2.HasValue)
                {
                    return(b1.Equals(false) ? DataObject.BooleanFalse : DataObject.BooleanNull);
                }

                // If both true.
                return(DataObject.Boolean(b1.Equals(true) && b2.Equals(true)));
            }
Esempio n. 5
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.");
        }