Esempio n. 1
0
        public virtual DbEval ParseBase()
        {
#if DEBUG
            //System.Diagnostics.Debugger.Launch();
#endif

            bool NOT = false;
            if (0 == string.Compare("NOT", PeekPart(), true))
            {
                NextPart(); // Eat the "NOT".
                NOT = true;
            }

            string op;
            DbValue val1, val2;
            {

                {
                    if ("(" == PeekPart())
                    {
                        NextPart(); // Eat the "(".
                        DbEval leval = ParseBase();
                        leval = ParsingCheckCondOp(leval);
                        string srp = NextPart();
                        if (")" != srp)
                        {
                            throw new Exception("Expected ) not " + srp);
                        }
                        if (NOT)
                        {
                            leval = new DbEvalNot(leval);
                        }
                        return ParsingCheckCondOp(leval);
                    }
                    Types.ExpressionType letype;
                    string lvalue = Types.ReadNextBasicExpression(this, out letype);
                    val1 = ExpressionToDbValue(lvalue, letype);
                }

                op = NextPart();
                if (">" == op)
                {
                    if (PeekPart() == "=")
                    {
                        NextPart();
                        op = ">=";
                    }
                }
                else if ("<" == op)
                {
                    string np = PeekPart();
                    if (np == "=")
                    {
                        NextPart();
                        op = "<=";
                    }
                    else if (np == ">")
                    {
                        NextPart();
                        op = "<>";
                    }
                }
                else if (0 == string.Compare("IS", op, true))
                {
                    string isx = NextPart();
                    if (0 == string.Compare("NULL", isx, true))
                    {
                        // IS NULL...?
                        DbValue val = new FuncEvalValue(this, "ISNULL", val1);
                        DbEval isresult = new DbEvalIntBoolValue(this, val);
                        if (NOT)
                        {
                            isresult = new DbEvalNot(isresult);
                        }
                        return ParsingCheckCondOp(isresult);
                    }
                    else if (0 == string.Compare("NOT", isx, true))
                    {
                        isx = NextPart();
                        if (0 == string.Compare("NULL", isx, true))
                        {
                            // IS NOT NULL...?
                            DbValue val = new FuncEvalValue(this, "ISNOTNULL", val1);
                            DbEval isresult = new DbEvalIntBoolValue(this, val);
                            if (NOT)
                            {
                                isresult = new DbEvalNot(isresult);
                            }
                            return ParsingCheckCondOp(isresult);
                        }
                        else
                        {
                            throw new Exception("Expected NULL after IS NOT, not " + isx);
                        }
                    }
                    else
                    {
                        throw new Exception("Expected NULL or NOT NULL after IS, not " + isx);
                    }
                }

                {
                    if ("(" == PeekPart())
                    {
                        NextPart(); // Eat the "(".
                        DbEval reval = ParseBase();
                        reval = ParsingCheckCondOp(reval);
                        string srp = NextPart();
                        if (")" != srp)
                        {
                            throw new Exception("Expected ) not " + srp);
                        }
                        if (NOT)
                        {
                            reval = new DbEvalNot(reval);
                        }
                        return ParsingCheckCondOp(reval);
                    }
                    Types.ExpressionType retype;
                    string rvalue = Types.ReadNextBasicExpression(this, out retype);
                    val2 = ExpressionToDbValue(rvalue, retype);
                }

            }

            DbEval result;

            if ("=" == op)
            {
                result = new CompareEval(this, val1, val2);
            }
            else if (">" == op)
            {
                result = new GreaterThanEval(this, val1, val2);
            }
            else if (">=" == op)
            {
                result = new GreaterThanOrEqualEval(this, val1, val2);
            }
            else if ("<" == op)
            {
                result = new LessThanEval(this, val1, val2);
            }
            else if ("<=" == op)
            {
                result = new LessThanOrEqualEval(this, val1, val2);
            }
            else if ("<>" == op)
            {
                result = new CompareNotEqualEval(this, val1, val2);
            }
            else if (0 == string.Compare(op, "LIKE", true))
            {
                DbValue val = new FuncEvalValue(this, "ISLIKE", val1, val2);
                result = new DbEvalIntBoolValue(this, val);
            }
            else
            {
                throw new Exception("Unknown operation: " + op);
            }

            if (NOT)
            {
                result = new DbEvalNot(result);
            }
            return ParsingCheckCondOp(result);

        }
Esempio n. 2
0
        public virtual DbEval ParseBase()
        {
#if DEBUG
            //System.Diagnostics.Debugger.Launch();
#endif

            bool NOT = false;
            if (0 == string.Compare("NOT", PeekPart(), true))
            {
                NextPart(); // Eat the "NOT".
                NOT = true;
            }

            string  op;
            DbValue val1, val2;
            {
                {
                    if ("(" == PeekPart())
                    {
                        NextPart(); // Eat the "(".
                        DbEval leval = ParseBase();
                        leval = ParsingCheckCondOp(leval);
                        string srp = NextPart();
                        if (")" != srp)
                        {
                            throw new Exception("Expected ) not " + srp);
                        }
                        if (NOT)
                        {
                            leval = new DbEvalNot(leval);
                        }
                        return(ParsingCheckCondOp(leval));
                    }
                    Types.ExpressionType letype;
                    string lvalue = Types.ReadNextBasicExpression(this, out letype);
                    val1 = ExpressionToDbValue(lvalue, letype);
                }

                op = NextPart();
                if (">" == op)
                {
                    if (PeekPart() == "=")
                    {
                        NextPart();
                        op = ">=";
                    }
                }
                else if ("<" == op)
                {
                    string np = PeekPart();
                    if (np == "=")
                    {
                        NextPart();
                        op = "<=";
                    }
                    else if (np == ">")
                    {
                        NextPart();
                        op = "<>";
                    }
                }
                else if (0 == string.Compare("IS", op, true))
                {
                    string isx = NextPart();
                    if (0 == string.Compare("NULL", isx, true))
                    {
                        // IS NULL...?
                        DbValue val      = new FuncEvalValue(this, "ISNULL", val1);
                        DbEval  isresult = new DbEvalIntBoolValue(this, val);
                        if (NOT)
                        {
                            isresult = new DbEvalNot(isresult);
                        }
                        return(ParsingCheckCondOp(isresult));
                    }
                    else if (0 == string.Compare("NOT", isx, true))
                    {
                        isx = NextPart();
                        if (0 == string.Compare("NULL", isx, true))
                        {
                            // IS NOT NULL...?
                            DbValue val      = new FuncEvalValue(this, "ISNOTNULL", val1);
                            DbEval  isresult = new DbEvalIntBoolValue(this, val);
                            if (NOT)
                            {
                                isresult = new DbEvalNot(isresult);
                            }
                            return(ParsingCheckCondOp(isresult));
                        }
                        else
                        {
                            throw new Exception("Expected NULL after IS NOT, not " + isx);
                        }
                    }
                    else
                    {
                        throw new Exception("Expected NULL or NOT NULL after IS, not " + isx);
                    }
                }

                {
                    if ("(" == PeekPart())
                    {
                        NextPart(); // Eat the "(".
                        DbEval reval = ParseBase();
                        reval = ParsingCheckCondOp(reval);
                        string srp = NextPart();
                        if (")" != srp)
                        {
                            throw new Exception("Expected ) not " + srp);
                        }
                        if (NOT)
                        {
                            reval = new DbEvalNot(reval);
                        }
                        return(ParsingCheckCondOp(reval));
                    }
                    Types.ExpressionType retype;
                    string rvalue = Types.ReadNextBasicExpression(this, out retype);
                    val2 = ExpressionToDbValue(rvalue, retype);
                }
            }

            DbEval result;

            if ("=" == op)
            {
                result = new CompareEval(this, val1, val2);
            }
            else if (">" == op)
            {
                result = new GreaterThanEval(this, val1, val2);
            }
            else if (">=" == op)
            {
                result = new GreaterThanOrEqualEval(this, val1, val2);
            }
            else if ("<" == op)
            {
                result = new LessThanEval(this, val1, val2);
            }
            else if ("<=" == op)
            {
                result = new LessThanOrEqualEval(this, val1, val2);
            }
            else if ("<>" == op)
            {
                result = new CompareNotEqualEval(this, val1, val2);
            }
            else if (0 == string.Compare(op, "LIKE", true))
            {
                DbValue val = new FuncEvalValue(this, "ISLIKE", val1, val2);
                result = new DbEvalIntBoolValue(this, val);
            }
            else
            {
                throw new Exception("Unknown operation: " + op);
            }

            if (NOT)
            {
                result = new DbEvalNot(result);
            }
            return(ParsingCheckCondOp(result));
        }