Пример #1
0
 /// <summary>
 /// Adiciona uma condição do tipo OR.
 /// </summary>
 /// <param name="expression"></param>
 /// <returns></returns>
 public virtual ConditionalContainer Or(string expression)
 {
     expression.Require("expression").NotNull();
     _conditionals.Add(Conditional.ParseTerm(expression));
     if (_conditionals.Count > 1)
     {
         _logicalOperators.Add(LogicalOperator.Or);
     }
     return(this);
 }
Пример #2
0
 /// <summary>
 /// Adiciona a condição inicial. Essa operação limpa todas a outras condições já existentes.
 /// </summary>
 /// <param name="expression"></param>
 /// <returns></returns>
 public virtual ConditionalContainer Start(string expression)
 {
     if (expression == null)
     {
         throw new ArgumentNullException("expression");
     }
     _conditionals.Clear();
     _logicalOperators.Clear();
     _conditionals.Add(Conditional.ParseTerm(expression));
     return(this);
 }
Пример #3
0
        /// <summary>
        /// Recupera a chamada de função.
        /// </summary>
        /// <param name="enumerator"></param>
        /// <param name="configuration"></param>
        /// <param name="containerStop"></param>
        /// <param name="callName"></param>
        /// <returns></returns>
        private static ConditionalTerm GetFunctionCall(ref IEnumerator <Text.InterpreterExpression.Expression> enumerator, Text.InterpreterExpression.ILexerConfiguration configuration, char?containerStop, Column callName)
        {
            var call            = callName;
            var pars            = new List <ConditionalTerm>();
            var commaExpression = _conditionalLexer.TokenParser.GetTerm((int)Colosoft.Text.InterpreterExpression.TokenID.Comma);
            var token           = enumerator.Current;
            var distinctFlag    = false;

            while (!token.ToString().Equals(")"))
            {
                if (!enumerator.MoveNext())
                {
                    break;
                }
                token = enumerator.Current;
                if (token.ToString().Equals(")"))
                {
                    enumerator.MoveNext();
                    break;
                }
                var             termText = enumerator.Current.Text;
                ConditionalTerm term     = null;
                while (true)
                {
                    term = GetTerm(ref enumerator, configuration);
                    if (term is Column && StringComparer.InvariantCultureIgnoreCase.Equals(((Column)term).Name, "DISTINCT"))
                    {
                        enumerator.MoveNext();
                        distinctFlag = true;
                    }
                    else
                    {
                        break;
                    }
                }
                if (StringComparer.InvariantCultureIgnoreCase.Equals(call.Name, "CAST") && pars.Count == 1 && term is Column)
                {
                    term = new Constant(((Column)term).Name);
                }
                if (!enumerator.MoveNext())
                {
                    pars.Add(term);
                    break;
                }
                if (Conditional.IsConditionalOperator(enumerator.Current))
                {
                    var left  = term;
                    var oper  = new Operator(enumerator.Current.Text);
                    var right = GetTerm(ref enumerator);
                    term = new Conditional(left, oper, right);
                    if (!enumerator.MoveNext())
                    {
                        pars.Add(term);
                        break;
                    }
                }
                if (Formula.IsArithmeticOperator(enumerator.Current))
                {
                    term = GetFormula(ref enumerator, configuration, term);
                }
                if ((token.Token == (int)Colosoft.Text.InterpreterExpression.TokenID.Identifier || Colosoft.Query.Parser.SqlTokenParser.IsSqlAnsiFunction(token.Token)) && enumerator.Current.Token == (int)Colosoft.Text.InterpreterExpression.TokenID.LParen)
                {
                    var columnExpression = ParserColumnExpression(termText);
                    term = GetFunctionCall(ref enumerator, configuration, ')', (columnExpression as Column) ?? new Column(termText));
                    if (Formula.IsArithmeticOperator(enumerator.Current))
                    {
                        term = GetFormula(ref enumerator, configuration, term);
                    }
                    pars.Add(term);
                    token = enumerator.Current;
                }
                else
                {
                    pars.Add(term);
                    token = enumerator.Current;
                }
                if (token.ToString().Equals(")"))
                {
                    enumerator.MoveNext();
                    break;
                }
                if (!token.ToString().Equals(commaExpression))
                {
                    throw new ConditionalParserException(string.Format("Expected comma after '{0}'", pars.Last().ToString()));
                }
            }
            return(new FunctionCall()
            {
                Call = call,
                Parameters = pars.ToArray(),
                Options = distinctFlag ? FunctionCallOptions.Distinct : FunctionCallOptions.None
            });
        }
Пример #4
0
 /// <summary>
 /// Adiciona uma condição do tipo OR.
 /// </summary>
 /// <param name="conditional"></param>
 /// <returns></returns>
 public virtual IWhereClause Or(Conditional conditional)
 {
     Container.Or(conditional);
     return(this);
 }
Пример #5
0
 /// <summary>
 /// Adiciona a condição inicial. Essa operação limpa todas a outras condições já existentes.
 /// </summary>
 /// <param name="conditional"></param>
 /// <returns></returns>
 public virtual IWhereClause Start(Conditional conditional)
 {
     Container.Start(conditional);
     return(this);
 }
Пример #6
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);
        }
Пример #7
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);
        }