Ejemplo n.º 1
0
        public bool Read()
        {
            CheckDisposed();

            if (_hasMore)
            {
                while (
                    _tokenizer.Read() &&
                    (
                        _tokenizer.Current.Type == TSQLTokenType.SingleLineComment ||
                        _tokenizer.Current.Type == TSQLTokenType.MultilineComment ||
                        _tokenizer.Current.Type == TSQLTokenType.Whitespace ||
                        (
                            _tokenizer.Current.Type == TSQLTokenType.Character &&
                            _tokenizer.Current.AsCharacter.Character == TSQLCharacters.Semicolon
                        )
                    ))

                {
                }

                if (_tokenizer.Current == null)
                {
                    _hasMore = false;

                    return(_hasMore);
                }

                _current = new TSQLStatementParserFactory().Create(_tokenizer.Current).Parse(_tokenizer);
            }

            return(_hasMore);
        }
Ejemplo n.º 2
0
        public static List <TSqlTable> GetAllTables(this TSQLStatement statement)
        {
            var tables     = new List <TSqlTable>();
            var tableNames = GetPreTableIndexes(statement);

            foreach (var tableName in tableNames)
            {
                if (!tables.Exists(e => e.TableName == tableName))
                {
                    var table = new TSqlTable
                    {
                        TableName = tableName
                    };
                    tables.Add(table);
                }
            }
            return(tables);
        }
Ejemplo n.º 3
0
        public bool MoveNext()
        {
            CheckDisposed();

            if (_hasMore)
            {
                // push the tokenizer to the next token

                // eat up any tokens inbetween statements until we get to something that might start a new statement
                // which should be a keyword if the batch is valid

                // if the last statement parser did not swallow the final semicolon, or there were multiple semicolons, we will swallow it also
                while (
                    _tokenizer.MoveNext() &&
                    (
                        _tokenizer.Current.Type == TSQLTokenType.SingleLineComment ||
                        _tokenizer.Current.Type == TSQLTokenType.MultilineComment ||
                        _tokenizer.Current.Type == TSQLTokenType.Whitespace ||
                        (
                            _tokenizer.Current.Type == TSQLTokenType.Character &&
                            _tokenizer.Current.AsCharacter.Character == TSQLCharacters.Semicolon
                        )
                    ))
                {
                    ;
                }

                if (_tokenizer.Current == null)
                {
                    _hasMore = false;

                    return(_hasMore);
                }

                _current = new TSQLStatementParserFactory().Create(_tokenizer).Parse();
            }

            return(_hasMore);
        }
Ejemplo n.º 4
0
#pragma warning disable S1541 // Methods and properties should not be too complex
        private static List <string> GetPreTableIndexes(TSQLStatement statement)
#pragma warning restore S1541 // Methods and properties should not be too complex
        {
            var tokens        = statement.Tokens;
            var countOfTokens = tokens.Count;
            var canProcess    = false;
            var tableNames    = new List <string>();

            for (int i = 0; i < countOfTokens; i++)
            {
                var tokenValue = tokens[i].Text.ToUpper(CultureInfo.InvariantCulture);
                switch (tokenValue)
                {
                case "FROM":
                case "JOIN":
                case "INNER":
                case "OUTER":
                case "NATURAL":
                case "UPDATE":
                case "INSERT":
                case "CROSS":
                case "INTO":
                    if (tokens[i].Type == TSQLTokenType.Keyword)
                    {
                        canProcess = true;
                        continue;
                    }
                    break;

                case "SET":
                case "WHERE":
                case "ON":
                case "USING":
                case "DELETE":
                case "SELECT":
                case "ORDER":
                case "GROUP":
                case "HAVING":
                    if (tokens[i].Type == TSQLTokenType.Keyword)
                    {
                        canProcess = false;
                    }
                    break;

                case ")":
                case "OFFSET":
                case "(":
                    canProcess = false;
                    break;

                default:
                    break;
                }
                if (canProcess)
                {
                    if (SkipToken(tokens[i - 1]))
                    {
                        continue;
                    }
                    tableNames.Add(tokens[i].Text);
                }
            }
            return(tableNames);
        }