Beispiel #1
0
        private void PeekTenChars(char c, char c2, char c3, char c4, char c5,
                                  char c6, char c7, char c8, char c9, char c10)
        {
            if ((c == 'f' || c == 'F') && (c2 == 'o' || c2 == 'O') &&
                (c3 == 'r' || c3 == 'R') && (SqlTokenHelper.IsWhitespace(c4)) &&
                (c5 == 'u' || c5 == 'U') && (c6 == 'p' || c6 == 'P') &&
                (c7 == 'd' || c7 == 'D') && (c8 == 'a' || c8 == 'A') &&
                (c9 == 't' || c9 == 'T') && (c10 == 'e' || c10 == 'E'))
            {
                _tokenType = SqlTokenType.FOR_UPDATE_WORD;
                if (IsWordEnded())
                {
                    return;
                }
            }

            _charPosition = _charPosition - 1;
            PeekNineChars(c, c2, c3, c4, c5, c6, c7, c8, c9);
        }
Beispiel #2
0
        private void PeekEightChars(char c, char c2, char c3, char c4, char c5,
                                    char c6, char c7, char c8)
        {
            if ((c == 'g' || c == 'G') && (c2 == 'r' || c2 == 'R') &&
                (c3 == 'o' || c3 == 'O') && (c4 == 'u' || c4 == 'U') &&
                (c5 == 'p' || c5 == 'P') && (SqlTokenHelper.IsWhitespace(c6)) &&
                (c7 == 'b' || c7 == 'B') && (c8 == 'y' || c8 == 'Y'))
            {
                _tokenType = SqlTokenType.GROUP_BY_WORD;
                if (IsWordEnded())
                {
                    return;
                }
            }
            else if ((c == 'o' || c == 'O') && (c2 == 'r' || c2 == 'R') &&
                     (c3 == 'd' || c3 == 'D') && (c4 == 'e' || c4 == 'E') &&
                     (c5 == 'r' || c5 == 'R') && (char.IsWhiteSpace(c6)) &&
                     (c7 == 'b' || c7 == 'B') && (c8 == 'y' || c8 == 'Y'))
            {
                _tokenType = SqlTokenType.ORDER_BY_WORD;
                if (IsWordEnded())
                {
                    return;
                }
            }
            else if ((c == 'o' || c == 'O') && (c2 == 'p' || c2 == 'P') &&
                     (c3 == 't' || c3 == 'T') && (c4 == 'i' || c4 == 'I') &&
                     (c5 == 'o' || c5 == 'O') && (c6 == 'n' || c6 == 'N') &&
                     (SqlTokenHelper.IsWhitespace(c7)) && (c8 == '('))
            {
                _tokenType    = SqlTokenType.OPTION_WORD;
                _charPosition = _charPosition - 2;
                return;
            }

            _charPosition = _charPosition - 1;
            PeekSevenChars(c, c2, c3, c4, c5, c6, c7);
        }
Beispiel #3
0
        private void PeekOneChar(char c)
        {
            if (SqlTokenHelper.IsWhitespace(c))
            {
                _tokenType = SqlTokenType.WHITESPACE;
            }
            else if (c == '(')
            {
                _tokenType = SqlTokenType.OPENED_PARENS;
            }
            else if (c == ')')
            {
                _tokenType = SqlTokenType.CLOSED_PARENS;
            }
            else if (c == ';')
            {
                _tokenType = SqlTokenType.DELIMITER;
            }
            else if (c == '\'')
            {
                _tokenType = SqlTokenType.QUOTE;
                var closed = false;
                while (HasRemaining())
                {
                    _charPosition++;
                    var c2 = _sql[_charPosition];
                    if (c2 == '\'')
                    {
                        if (_charPosition + 1 < _stringLength)
                        {
                            _charPosition++;
                            var c3 = _sql[_charPosition];
                            if (c3 != '\'')
                            {
                                _charPosition = _charPosition - 1;
                                closed        = true;
                                break;
                            }
                        }
                        else
                        {
                            closed = true;
                        }
                    }
                }

                if (closed)
                {
                    return;
                }
                CalcPosition();
                throw new SqlParseException(ExceptionMessageId.Esp2101, _sql, LineNumber, Position);
            }
            else if (IsWordStarted(c))
            {
                _tokenType = SqlTokenType.WORD;
                while (HasRemaining())
                {
                    _charPosition++;
                    var c2 = _sql[_charPosition];
                    if (c2 == '\'')
                    {
                        var closed = false;
                        while (HasRemaining())
                        {
                            _charPosition++;
                            var c3 = _sql[_charPosition];
                            if (c3 == '\'')
                            {
                                if (_charPosition + 2 < _stringLength)
                                {
                                    _charPosition++;
                                    var c4 = _sql[_charPosition + 1];
                                    if (c4 != '\'')
                                    {
                                        _charPosition = _charPosition - 1;
                                        closed        = true;
                                        break;
                                    }
                                }
                                else
                                {
                                    closed = true;
                                }
                            }
                        }

                        if (closed)
                        {
                            return;
                        }
                        CalcPosition();
                        throw new SqlParseException(ExceptionMessageId.Esp2101, _sql, LineNumber, Position);
                    }

                    if (!SqlTokenHelper.IsWordPart(c2))
                    {
                        _charPosition = _charPosition - 1;
                        return;
                    }
                }
            }
            else if (c == '\r' || c == '\n')
            {
                _tokenType = SqlTokenType.EOL;
                _currentLineNumber++;
            }
            else
            {
                _tokenType = SqlTokenType.OTHER;
            }
        }