예제 #1
0
        /// <summary>
        /// Recupera o termo condicional contido no reader.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        internal static protected ConditionalTerm GetConditionalTerm(Colosoft.Serialization.IO.CompactReader reader)
        {
            var             type = reader.ReadString();
            ConditionalTerm term = null;

            if (string.IsNullOrEmpty(type))
            {
                term = new Constant();
            }
            else
            {
                if (type == "Conditional")
                {
                    term = new Conditional();
                }
                else if (type == "ConditionalContainer")
                {
                    term = new ConditionalContainer();
                }
                else if (type == "Operator")
                {
                    term = new Operator();
                }
                else if (type == "Constant")
                {
                    term = new Constant();
                }
                else if (type == "Column")
                {
                    term = new Column();
                }
                else if (type == "Variable")
                {
                    term = new Variable();
                }
                else if (type == "ValuesArray")
                {
                    term = new ValuesArray();
                }
                else if (type == "QueryTerm")
                {
                    term = new QueryTerm();
                }
                else if (type == "FunctionCall")
                {
                    term = new FunctionCall();
                }
                else if (type == "MinusTerm")
                {
                    term = new MinusTerm();
                }
                else if (type == "Formula")
                {
                    term = new Formula();
                }
                else if (type == "Empty")
                {
                    return(null);
                }
                else
                {
                    throw new QueryInvalidOperationException("Invalid conditional type");
                }
            }
            ((ICompactSerializable)term).Deserialize(reader);
            return(term);
        }
예제 #2
0
        /// <summary>
        /// Recupera uma condição.
        /// </summary>
        /// <param name="enumerator"></param>
        /// <param name="configuration"></param>
        /// <param name="containerStop">Caracter que identifica o fim da condicional.</param>
        /// <returns></returns>
        private static ConditionalTerm GetConditional(ref IEnumerator <Text.InterpreterExpression.Expression> enumerator, Text.InterpreterExpression.ILexerConfiguration configuration, char?containerStop)
        {
            var left           = GetTerm(ref enumerator, configuration);
            var isLeftNotToken = enumerator.Current != null && (enumerator.Current.Token == (int)Parser.SqlTokenID.kNot);
            int leftToken      = enumerator.Current != null ? (int)enumerator.Current.Token : -1;

            if (!enumerator.MoveNext() || enumerator.Current.Token == (int)Text.InterpreterExpression.TokenID.And || enumerator.Current.Token == (int)Parser.SqlTokenID.kAnd || enumerator.Current.Token == (int)Text.InterpreterExpression.TokenID.Or || enumerator.Current.Token == (int)Parser.SqlTokenID.kOr)
            {
                return(left);
            }
            if (containerStop != null && enumerator.Current.Text[0] == containerStop)
            {
                return(left);
            }
            var oper = enumerator.Current;

            if (Formula.IsArithmeticOperator(oper))
            {
                left = GetFormula(ref enumerator, configuration, left);
                oper = enumerator.Current;
                if (enumerator.Current == null || (containerStop != null && enumerator.Current.Text[0] == containerStop))
                {
                    return(left);
                }
            }
            var operToken = _conditionalLexer.TokenParser.Parse(oper.Text);

            if (left is Constant && operToken == (int)Text.InterpreterExpression.TokenID.LParen && (leftToken == (int)Parser.SqlTokenID.kDay || leftToken == (int)Parser.SqlTokenID.kMonth || leftToken == (int)Parser.SqlTokenID.kYear || leftToken == (int)Parser.SqlTokenID.kHour || leftToken == (int)Parser.SqlTokenID.kMinute || leftToken == (int)Parser.SqlTokenID.kSecond))
            {
                left = new Column(((Constant)left).Text);
            }
            if (isLeftNotToken && operToken == (int)Parser.SqlTokenID.kExists)
            {
                enumerator.MoveNext();
                left = GetFunctionCall(ref enumerator, configuration, containerStop, new Column("NOT EXISTS"));
                return(new Conditional(left, new Operator("NOT EXISTS"), null));
            }
            else if ((operToken == (int)Text.InterpreterExpression.TokenID.LParen) && (left is Column))
            {
                left = GetFunctionCall(ref enumerator, configuration, containerStop, (Column)left);
                var function = (FunctionCall)left;
                if (StringComparer.InvariantCultureIgnoreCase.Equals(((Column)function.Call).Name, "exists"))
                {
                    function.Call = new Constant("EXISTS");
                    return(new Conditional(left, new Operator("EXISTS"), null));
                }
                oper = enumerator.Current;
                if (oper == null)
                {
                    return(function);
                }
                operToken = _conditionalLexer.TokenParser.Parse(oper.Text);
            }
            else if (operToken == (int)Colosoft.Text.InterpreterExpression.TokenID.Comma)
            {
                return(GetValuesArray(ref enumerator, configuration, containerStop, left));
            }
            if (!enumerator.MoveNext())
            {
                if (left is FunctionCall)
                {
                    return(left);
                }
                throw new ConditionalParserException("Right conditional not found");
            }
            if (left is FunctionCall && enumerator.Current.Token == (int)Colosoft.Query.Parser.SqlTokenID.kEnd)
            {
                return(left);
            }
            var  optOper      = enumerator.Current;
            var  optOperToken = _conditionalLexer.TokenParser.Parse(optOper.Text);
            bool isOptOper    = (optOperToken == (int)Colosoft.Query.Parser.SqlTokenID.kNot) || (operToken == (int)Colosoft.Query.Parser.SqlTokenID.kNot);

            if (isOptOper)
            {
                if (!enumerator.MoveNext())
                {
                    throw new ConditionalParserException("Right conditional not found");
                }
            }
            var right = GetTerm(ref enumerator, configuration);

            enumerator.MoveNext();
            if ((enumerator.Current != null) && (enumerator.Current.Text[0] == '(') && (right is Column))
            {
                right = GetFunctionCall(ref enumerator, configuration, containerStop, (Column)right);
            }
            else if (operToken == (int)Colosoft.Query.Parser.SqlTokenID.kIn || optOperToken == (int)Colosoft.Query.Parser.SqlTokenID.kIn)
            {
                if (!(right is ValuesArray))
                {
                    var rcc = right as ConditionalContainer;
                    if (rcc != null)
                    {
                        right = new ValuesArray()
                        {
                            Values = rcc.Conditionals.ToArray()
                        };
                    }
                    else
                    {
                        right = new ValuesArray {
                            Values = new ConditionalTerm[] {
                                right
                            }
                        }
                    };
                }
            }
            return(new Conditional(left, new Operator((isOptOper) ? oper.Text + ' ' + optOper.Text : oper.Text), right));
        }
예제 #3
0
        /// <summary>
        /// Recupera o termo condicional contido no reader.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        internal protected static ConditionalTerm GetConditionalTerm(System.Xml.XmlReader reader)
        {
            var type = reader.GetAttribute("type", Namespaces.SchemaInstance);

            if (string.IsNullOrEmpty(type))
            {
                type = reader.LocalName;
            }
            ConditionalTerm term = null;

            if (string.IsNullOrEmpty(type))
            {
                term = new Constant();
            }
            else
            {
                var index1 = type.IndexOf(":");
                if (index1 >= 0)
                {
                    type = type.Substring(index1 + 1);
                }
                var startPoint = type.IndexOf('.');
                if (startPoint >= 0)
                {
                    type = type.Substring(startPoint + 1);
                }
                if (type == "Conditional")
                {
                    term = new Conditional();
                }
                else if (type == "ConditionalContainer")
                {
                    term = new ConditionalContainer();
                }
                else if (type == "Operator")
                {
                    term = new Operator();
                }
                else if (type == "Constant")
                {
                    term = new Constant();
                }
                else if (type == "Column")
                {
                    term = new Column();
                }
                else if (type == "Variable")
                {
                    term = new Variable();
                }
                else if (type == "ValuesArray")
                {
                    term = new ValuesArray();
                }
                else if (type == "QueryTerm")
                {
                    term = new QueryTerm();
                }
                else if (type == "FunctionCall")
                {
                    term = new FunctionCall();
                }
                else if (type == "MinusTerm")
                {
                    term = new MinusTerm();
                }
                else if (type == "Formula")
                {
                    term = new Formula();
                }
                else if (type == "Empty")
                {
                    return(null);
                }
                else if (type == "Case")
                {
                    term = new CaseConditional();
                }
                else
                {
                    throw new QueryInvalidOperationException("Invalid conditional type");
                }
            }
            ((System.Xml.Serialization.IXmlSerializable)term).ReadXml(reader);
            return(term);
        }