Esempio n. 1
0
        private int Eval(BinaryNode expr, DataRow row, DataRowVersion version)
        {
            if (expr.op == Operators.And)
            {
                int lResult = Eval((BinaryNode)expr.left, row, version);
                if (lResult != 0)
                {
                    return(lResult);
                }
                int rResult = Eval((BinaryNode)expr.right, row, version);
                if (rResult != 0)
                {
                    return(rResult);
                }
                return(0);
            }

            long   c     = 0;
            object vLeft = expr.left.Eval(row, version);

            if (expr.op != Operators.Is && expr.op != Operators.IsNot)
            {
                object vRight   = expr.right.Eval(row, version);
                bool   isLConst = (expr.left is ConstNode);
                bool   isRConst = (expr.right is ConstNode);

                if (vLeft == DBNull.Value)
                {
                    return(-1);
                }
                if (vRight == DBNull.Value)
                {
                    return(1);
                }

                if (vLeft.GetType() == typeof(char))
                {
                    vRight = Convert.ToChar(vRight);
                }

                Type result = expr.ResultType(vLeft.GetType(), vRight.GetType(), isLConst, isRConst, expr.op);
                if (result == null)
                {
                    expr.SetTypeMismatchError(expr.op, vLeft.GetType(), vRight.GetType());
                }

                c = expr.Compare(vLeft, vRight, result, expr.op);
            }
            switch (expr.op)
            {
            case Operators.EqualTo:         c = (c == 0 ? 0 : c < 0  ? -1 :  1); break;

            case Operators.GreaterThen:     c = (c > 0  ? 0 : -1); break;

            case Operators.LessThen:        c = (c < 0  ? 0 : 1); break;

            case Operators.GreaterOrEqual:  c = (c >= 0 ? 0 : -1); break;

            case Operators.LessOrEqual:     c = (c <= 0 ? 0 : 1); break;

            case Operators.Is:              c = (vLeft == DBNull.Value ? 0 : -1); break;

            case Operators.IsNot:           c = (vLeft != DBNull.Value ? 0 : 1);  break;

            default:                        Debug.Assert(true, "Unsupported Binary Search Operator!"); break;
            }
            return((int)c);
        }