コード例 #1
0
        /// <exception cref="System.SqlSyntaxErrorException" />
        public static void InitRouteRule(ISchemaLoader loader)
        {
            var functions       = loader.Functions;
            var functionManager = new MySqlFunctionManager(true);

            BuildFuncManager(functionManager, functions);
            foreach (var conf in loader.RuleConfigList)
            {
                var algorithmString = conf.Algorithm;
                var lexer           = new MySqlLexer(algorithmString);
                var parser          = new MySqlExprParser(lexer, functionManager, false, MySqlParser.DefaultCharset);
                var expression      = parser.Expression();
                if (lexer.Token() != MySqlToken.Eof)
                {
                    throw new ConfigException("route algorithm not end with EOF: " + algorithmString);
                }
                IRuleAlgorithm algorithm;
                if (expression is IRuleAlgorithm)
                {
                    algorithm = (IRuleAlgorithm)expression;
                }
                else
                {
                    algorithm = new ExpressionAdapter(expression);
                }
                conf.RuleAlgorithm = algorithm;
            }
        }
コード例 #2
0
        /// <summary>nothing has been pre-consumed</summary>
        /// <returns>null if there is no order by</returns>
        /// <exception cref="System.SqlSyntaxErrorException" />
        protected internal virtual GroupBy GroupBy()
        {
            if (lexer.Token() != MySqlToken.KwGroup)
            {
                return(null);
            }
            lexer.NextToken();
            Match(MySqlToken.KwBy);
            var     expr  = exprParser.Expression();
            var     order = SortOrder.Asc;
            GroupBy groupBy;

            switch (lexer.Token())
            {
            case MySqlToken.KwDesc:
            {
                order = SortOrder.Desc;
                goto case MySqlToken.KwAsc;
            }

            case MySqlToken.KwAsc:
            {
                lexer.NextToken();
                goto default;
            }

            default:
            {
                break;
            }
            }
            switch (lexer.Token())
            {
            case MySqlToken.KwWith:
            {
                lexer.NextToken();
                MatchIdentifier("ROLLUP");
                return(new GroupBy(expr, order, true));
            }

            case MySqlToken.PuncComma:
            {
                break;
            }

            default:
            {
                return(new GroupBy(expr, order, false));
            }
            }
            for (groupBy = new GroupBy().AddOrderByItem(expr, order);
                 lexer.Token() == MySqlToken.PuncComma;)
            {
                lexer.NextToken();
                order = SortOrder.Asc;
                expr  = exprParser.Expression();
                switch (lexer.Token())
                {
                case MySqlToken.KwDesc:
                {
                    order = SortOrder.Desc;
                    goto case MySqlToken.KwAsc;
                }

                case MySqlToken.KwAsc:
                {
                    lexer.NextToken();
                    goto default;
                }

                default:
                {
                    break;
                }
                }
                groupBy.AddOrderByItem(expr, order);
                if (lexer.Token() == MySqlToken.KwWith)
                {
                    lexer.NextToken();
                    MatchIdentifier("ROLLUP");
                    return(groupBy.SetWithRollup());
                }
            }
            return(groupBy);
        }