From 4b7b0d3a01d8061572137f82a53de7365f3a241c Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Wed, 15 Apr 2015 18:17:57 +0200 Subject: Update version number. --- sqlparse/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlparse') diff --git a/sqlparse/__init__.py b/sqlparse/__init__.py index c956f66..21028a4 100644 --- a/sqlparse/__init__.py +++ b/sqlparse/__init__.py @@ -6,7 +6,7 @@ """Parse SQL statements.""" -__version__ = '0.1.14' +__version__ = '0.1.15' # Setup namespace -- cgit v1.2.1 From 4f5195481a89e87a07a064d2c253bb6f74e911d4 Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Wed, 15 Apr 2015 18:23:04 +0200 Subject: Switch back to development mode. --- sqlparse/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlparse') diff --git a/sqlparse/__init__.py b/sqlparse/__init__.py index 21028a4..6c0590a 100644 --- a/sqlparse/__init__.py +++ b/sqlparse/__init__.py @@ -6,7 +6,7 @@ """Parse SQL statements.""" -__version__ = '0.1.15' +__version__ = '0.1.16-dev' # Setup namespace -- cgit v1.2.1 From d9b717a12da7805d5a37b6b659300e449c42bd2f Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 19 Apr 2015 02:11:39 +0200 Subject: Improve detection of aliased identifiers (fixes #185). --- sqlparse/sql.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sqlparse') diff --git a/sqlparse/sql.py b/sqlparse/sql.py index 9fcb546..717661f 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -397,7 +397,8 @@ class TokenList(Token): return self._get_first_name(kw, keywords=True) # "name alias" or "complicated column expression alias" - if len(self.tokens) > 2: + if len(self.tokens) > 2 \ + and self.token_next_by_type(0, T.Whitespace) is not None: return self._get_first_name(reverse=True) return None -- cgit v1.2.1 From 621e1d84607a158491ce80c47814e51a8c366498 Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 26 Jul 2015 10:38:54 +0200 Subject: Don't treat DECLARE within BEGIN blocks as relevant to split level (fixes #193). --- sqlparse/engine/filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlparse') diff --git a/sqlparse/engine/filter.py b/sqlparse/engine/filter.py index 9af2f99..e7ea0ec 100644 --- a/sqlparse/engine/filter.py +++ b/sqlparse/engine/filter.py @@ -40,7 +40,7 @@ class StatementFilter: unified = value.upper() - if unified == 'DECLARE' and self._is_create: + if unified == 'DECLARE' and self._is_create and self._begin_depth == 0: self._in_declare = True return 1 -- cgit v1.2.1 From 8b5a957f4dad82fda0dc174538fdaf0860a9256a Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 26 Jul 2015 11:05:58 +0200 Subject: Recognize MSSQL temp tables and distinguish from MySQL comments (fixes #192). --- sqlparse/lexer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sqlparse') 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), -- cgit v1.2.1 From fb6b59dece40a608a1c6cf741a4ac6ee88d85d2f Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 26 Jul 2015 11:20:49 +0200 Subject: Ignore comments at beginning of statement when calling Statement.get_type (fixes #186). --- sqlparse/sql.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'sqlparse') diff --git a/sqlparse/sql.py b/sqlparse/sql.py index 717661f..5ecfbdc 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -240,15 +240,20 @@ class TokenList(Token): def _groupable_tokens(self): return self.tokens - def token_first(self, ignore_whitespace=True): + def token_first(self, ignore_whitespace=True, ignore_comments=False): """Returns the first child token. If *ignore_whitespace* is ``True`` (the default), whitespace tokens are ignored. + + if *ignore_comments* is ``True`` (default: ``False``), comments are + ignored too. """ for token in self.tokens: if ignore_whitespace and token.is_whitespace(): continue + if ignore_comments and isinstance(token, Comment): + continue return token def token_next_by_instance(self, idx, clss): @@ -468,8 +473,11 @@ class Statement(TokenList): The returned value is a string holding an upper-cased reprint of the first DML or DDL keyword. If the first token in this group isn't a DML or DDL keyword "UNKNOWN" is returned. + + Whitespaces and comments at the beginning of the statement + are ignored. """ - first_token = self.token_first() + first_token = self.token_first(ignore_comments=True) if first_token is None: # An "empty" statement that either has not tokens at all # or only whitespace tokens. -- cgit v1.2.1 From 14ddedee47808ac1cc8e21f32907b01af6af4efc Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 26 Jul 2015 11:23:44 +0200 Subject: Prepare next release. --- sqlparse/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlparse') diff --git a/sqlparse/__init__.py b/sqlparse/__init__.py index 6c0590a..b9aadc5 100644 --- a/sqlparse/__init__.py +++ b/sqlparse/__init__.py @@ -6,7 +6,7 @@ """Parse SQL statements.""" -__version__ = '0.1.16-dev' +__version__ = '0.1.16' # Setup namespace -- cgit v1.2.1 From 8987a3a6b540ea35bbb1f9c5f49f3306501289cd Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 26 Jul 2015 11:25:00 +0200 Subject: Switch back to development. --- sqlparse/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sqlparse') diff --git a/sqlparse/__init__.py b/sqlparse/__init__.py index b9aadc5..83bb684 100644 --- a/sqlparse/__init__.py +++ b/sqlparse/__init__.py @@ -6,7 +6,7 @@ """Parse SQL statements.""" -__version__ = '0.1.16' +__version__ = '0.1.17-dev' # Setup namespace -- cgit v1.2.1