diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2015-07-26 11:05:58 +0200 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2015-07-26 11:05:58 +0200 |
| commit | 8b5a957f4dad82fda0dc174538fdaf0860a9256a (patch) | |
| tree | 282cd4a60f32b886f63e5adc0857b3e6bca07843 | |
| parent | c66fbacf8b3095c6de264657362e403920edace2 (diff) | |
| download | sqlparse-8b5a957f4dad82fda0dc174538fdaf0860a9256a.tar.gz | |
Recognize MSSQL temp tables and distinguish from MySQL comments (fixes #192).
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | sqlparse/lexer.py | 6 | ||||
| -rw-r--r-- | tests/test_parse.py | 10 |
3 files changed, 15 insertions, 3 deletions
@@ -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) diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py index 9533e8a..fd29f5c 100644 --- a/sqlparse/lexer.py +++ b/sqlparse/lexer.py @@ -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'), @@ -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), diff --git a/tests/test_parse.py b/tests/test_parse.py index 857685b..6c9d6a6 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -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) |
