Skip to content

Commit 8b5a957

Browse files
committed
Recognize MSSQL temp tables and distinguish from MySQL comments (fixes andialbrecht#192).
1 parent c66fbac commit 8b5a957

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Bug Fixes
55
* Fix a regression in get_alias() introduced in 0.1.15 (issue185).
66
* Fix a bug in the splitter regarding DECLARE (issue193).
77
* sqlformat command line tool doesn't duplicat newlines anymore (issue191).
8+
* Don't mix up MySQL comments starting with hash and MSSQL
9+
temp tables (issue192).
810

911

1012
Release 0.1.15 (Apr 15, 2015)

sqlparse/lexer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ class Lexer(object):
164164

165165
tokens = {
166166
'root': [
167-
(r'(--|#).*?(\r\n|\r|\n)', tokens.Comment.Single),
167+
(r'(--|# ).*?(\r\n|\r|\n)', tokens.Comment.Single),
168168
# $ matches *before* newline, therefore we have two patterns
169169
# to match Comment.Single
170-
(r'(--|#).*?$', tokens.Comment.Single),
170+
(r'(--|# ).*?$', tokens.Comment.Single),
171171
(r'(\r\n|\r|\n)', tokens.Newline),
172172
(r'\s+', tokens.Whitespace),
173173
(r'/\*', tokens.Comment.Multiline, 'multiline-comments'),
@@ -185,7 +185,7 @@ class Lexer(object):
185185
# FIXME(andi): VALUES shouldn't be listed here
186186
# see https://github.com/andialbrecht/sqlparse/pull/64
187187
(r'VALUES', tokens.Keyword),
188-
(r'@[^\W\d_]\w+', tokens.Name),
188+
(r'(@|##|#)[^\W\d_]\w+', tokens.Name),
189189
# IN is special, it may be followed by a parenthesis, but
190190
# is never a functino, see issue183
191191
(r'in\b(?=[ (])?', tokens.Keyword),

tests/test_parse.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,13 @@ def test_single_line_comments(sql):
293293
assert p.tokens[-1].ttype == T.Comment.Single
294294

295295

296+
@pytest.mark.parametrize('sql', [
297+
'foo',
298+
'@foo',
299+
'#foo', # see issue192
300+
'##foo'
301+
])
302+
def test_names_and_special_names(sql):
303+
p = sqlparse.parse(sql)[0]
304+
assert len(p.tokens) == 1
305+
assert isinstance(p.tokens[0], sqlparse.sql.Identifier)

0 commit comments

Comments
 (0)