Пример #1
0
        public override void Build(ParsedSql ret, List <string> tokens, ref int i)
        {
            TableField t = new TableField();

            if (tokens[i] == "(")
            {
                t.Name = ParenBlockBuilder.ConsumeParenBlock(tokens, ref i);
            }
            else
            {
                t.Name = tokens[i++];
            }

            var on   = new On();
            var join = new Join();

            var where = new Where();
            if (!join.Match(tokens[i], tokens, i) &&
                !on.Match(tokens[i], tokens, i) &&
                !where.Match(tokens[i], tokens, i))
            {
                var token = tokens[i++];
                if (token == "as")
                {
                    token = tokens[i++];
                }
                t.Alias = token;
            }


            ret.Select.Tables.Add(t);
        }
Пример #2
0
        public static string ConsumeFunctionBlock(List <string> tokens, ref int i)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(tokens[i++] + " ");
            sb.Append(ParenBlockBuilder.ConsumeParenBlock(tokens, ref i));
            return(sb.ToString());
        }
Пример #3
0
        public override void Build(ParsedSql ret, List <string> tokens, ref int i)
        {
            var token = tokens[i];

            var sf = new T();

            if (token == "(")
            {
                sf.Name = ParenBlockBuilder.ConsumeParenBlock(tokens, ref i);
            }
            else if (FunctionBlockBuilder.Match(token, tokens, i))
            {
                sf.Name = FunctionBlockBuilder.ConsumeFunctionBlock(tokens, ref i);
            }
            else
            {
                sf.Name = tokens[i++];
            }

            ContinuedBuildAppend(ret, tokens, ref i, sf);
        }
Пример #4
0
        private static void DecomposeChunk(ChunkedBools current)
        {
            bool didSplit = false;

            if (current.Statement.StartsWith("("))
            {
                var index = 0;
                var block = ParenBlockBuilder.ConsumeParenBlock(current.Statement, ref index);
                current.Children = new List <ChunkedBools>();
                current.Children.Add(new ChunkedBools(block.Substring(1, block.Length - 2)));
                var remaining  = current.Statement.Substring(block.Length).Trim();
                var firstSpace = remaining.IndexOf(" ");
                var op         = remaining.Substring(0, firstSpace);
                var statement  = remaining.Substring(firstSpace + 1);
                current.Children.Add(new ChunkedBools(statement, op));
                didSplit = true;
            }
            else if (current.Statement.Contains("("))
            {
                var index = 0;
                var block = ParenBlockBuilder.ConsumeParenBlock(current.Statement, ref index);
                current.Children = new List <ChunkedBools>();
                var remaining = current.Statement.Substring(0, index).Trim();
                var space     = remaining.LastIndexOf(" ");
                var statement = remaining.Substring(0, space);
                var op        = remaining.Substring(space + 1);
                current.Children.Add(new ChunkedBools(statement));
                current.Children.Add(new ChunkedBools(block.Substring(1, block.Length - 2), op));
                didSplit = true;
            }
            else
            {
                didSplit = CheckForOpAndSplit(current.Statement, "and", current) || CheckForOpAndSplit(current.Statement, "or", current);
            }

            if (didSplit && current.Children != null)
            {
                current.Children.ForEach(c => DecomposeChunk(c));
            }
        }
Пример #5
0
        public override void Build(ParsedSql ret, List <string> tokens, ref int i)
        {
            var token = tokens[i];

            if (Constants.ComparisonOperators.Contains(token))
            {
                _ws.Operator = token;
                _onLeft      = false;
                i++;
            }
            else if (Constants.BooleanOperators.Contains(token))
            {
                _ws = new WhereStatement
                {
                    PrecedingOperator = token,
                };
                _onLeft = true;
                i++;
            }
            else if (token == "(")
            {
                _ws.LeftClause = ParenBlockBuilder.ConsumeParenBlock(tokens, ref i);
                ret.Select.Wheres.Add(_ws);
            }
            else if (_onLeft)
            {
                _ws.LeftClause = token;
                i++;
            }
            else
            {
                _ws.RightClause = token;
                ret.Select.Wheres.Add(_ws);
                i++;
            }
        }