Exemple #1
0
        /// <summary>
        /// Test condition for True or False value.
        /// </summary>
        /// <returns></returns>
        public bool Test()
        {
            switch (_type)
            {
            case ExpressionType.True:
                return(true);

            case ExpressionType.Not:
                Trace.Assert(eArg2 == null, "Expression.test");

                return(!eArg.Test());

            case ExpressionType.And:
                return(eArg.Test() && eArg2.Test());

            case ExpressionType.Or:
                return(eArg.Test() || eArg2.Test());

            case ExpressionType.Like:

                // todo: now for all tests a new 'like' object required!
                string     s    = (string)eArg2.GetValue(ColumnType.VarChar);
                ColumnType type = eArg._columnType;
                Like       l    = new Like(s, cLikeEscape, type == ColumnType.VarCharIgnoreCase);
                string     c    = (string)eArg.GetValue(ColumnType.VarChar);

                return(l.Compare(c));

            case ExpressionType.In:
                return(eArg2.TestValueList(eArg.GetValue(), eArg._columnType));

            case ExpressionType.Exists:
                Result r = eArg.sSelect.GetResult(1, null);                            // 1 is already enough

                return(r.Root != null);
            }

            Trace.Check(eArg != null, Trace.GENERAL_ERROR);

            object     o     = eArg.GetValue();
            ColumnType dtype = eArg._columnType;

            Trace.Check(eArg2 != null, Trace.GENERAL_ERROR);

            object o2     = eArg2.GetValue(dtype);
            int    result = Column.Compare(o, o2, dtype);

            switch (_type)
            {
            case ExpressionType.Equal:
                return(result == 0);

            case ExpressionType.Bigger:
                return(result > 0);

            case ExpressionType.BiggerEqual:
                return(result >= 0);

            case ExpressionType.SmallerEqual:
                return(result <= 0);

            case ExpressionType.Smaller:
                return(result < 0);

            case ExpressionType.NotEqual:
                return(result != 0);
            }

            Trace.Assert(false, "Expression.test2");

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Test condition for True or False value.
        /// </summary>
        /// <returns></returns>
        public bool Test()
        {
            switch (_type)
            {

                case ExpressionType.True:
                    return true;

                case ExpressionType.Not:
                    TracingHelper.Assert(eArg2 == null, "Expression.test");

                    return !eArg.Test();

                case ExpressionType.And:
                    return eArg.Test() && eArg2.Test();

                case ExpressionType.Or:
                    return eArg.Test() || eArg2.Test();

                case ExpressionType.Like:

                    // todo: now for all tests a new 'like' object required!
                    string s = (string) eArg2.GetValue(ColumnType.VarChar);
                    ColumnType  type = eArg._columnType;
                    Like   l = new Like(s, cLikeEscape,	type == ColumnType.VarCharIgnoreCase);
                    string c = (string) eArg.GetValue(ColumnType.VarChar);

                    return l.Compare(c);

                case ExpressionType.In:
                    return eArg2.TestValueList(eArg.GetValue(), eArg._columnType);

                case ExpressionType.Exists:
                    Result r = eArg.sSelect.GetResult(1, null);    // 1 is already enough

                    return r.Root != null;
            }

            TracingHelper.Check(eArg != null, TracingHelper.GENERAL_ERROR);

            object o = eArg.GetValue();
            ColumnType dtype = eArg._columnType;

            TracingHelper.Check(eArg2 != null, TracingHelper.GENERAL_ERROR);

            object o2 = eArg2.GetValue(dtype);
            int    result = Column.Compare(o, o2, dtype);

            switch (_type)
            {

                case ExpressionType.Equal:
                    return result == 0;

                case ExpressionType.Bigger:
                    return result > 0;

                case ExpressionType.BiggerEqual:
                    return result >= 0;

                case ExpressionType.SmallerEqual:
                    return result <= 0;

                case ExpressionType.Smaller:
                    return result < 0;

                case ExpressionType.NotEqual:
                    return result != 0;
            }

            TracingHelper.Assert(false, "Expression.test2");

            return false;
        }