Skip to content

Commit

Permalink
Recognize MSSQL temp tables and distinguish from MySQL comments (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andialbrecht committed Jul 26, 2015
1 parent c66fbac commit 8b5a957
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Bug Fixes
* Fix a regression in get_alias() introduced in 0.1.15 (issue185).
* Fix a bug in the splitter regarding DECLARE (issue193).
* sqlformat command line tool doesn't duplicat newlines anymore (issue191).
* Don't mix up MySQL comments starting with hash and MSSQL
temp tables (issue192).


Release 0.1.15 (Apr 15, 2015)
Expand Down
6 changes: 3 additions & 3 deletions sqlparse/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ class Lexer(object):

tokens = {
'root': [
(r'(--|#).*?(\r\n|\r|\n)', tokens.Comment.Single),
(r'(--|# ).*?(\r\n|\r|\n)', tokens.Comment.Single),
# $ matches *before* newline, therefore we have two patterns
# to match Comment.Single
(r'(--|#).*?$', tokens.Comment.Single),
(r'(--|# ).*?$', tokens.Comment.Single),
(r'(\r\n|\r|\n)', tokens.Newline),
(r'\s+', tokens.Whitespace),
(r'/\*', tokens.Comment.Multiline, 'multiline-comments'),
Expand All @@ -185,7 +185,7 @@ class Lexer(object):
# FIXME(andi): VALUES shouldn't be listed here
# see https://github.com/andialbrecht/sqlparse/pull/64
(r'VALUES', tokens.Keyword),
(r'@[^\W\d_]\w+', tokens.Name),
(r'(@|##|#)[^\W\d_]\w+', tokens.Name),
# IN is special, it may be followed by a parenthesis, but
# is never a functino, see issue183
(r'in\b(?=[ (])?', tokens.Keyword),
Expand Down
10 changes: 10 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,13 @@ def test_single_line_comments(sql):
assert p.tokens[-1].ttype == T.Comment.Single


@pytest.mark.parametrize('sql', [
'foo',
'@foo',
'#foo', # see issue192
'##foo'
])
def test_names_and_special_names(sql):
p = sqlparse.parse(sql)[0]
assert len(p.tokens) == 1
assert isinstance(p.tokens[0], sqlparse.sql.Identifier)

0 comments on commit 8b5a957

Please sign in to comment.