diff options
author | Andi Albrecht <albrecht.andi@gmail.com> | 2015-07-26 14:35:32 +0200 |
---|---|---|
committer | Andi Albrecht <albrecht.andi@gmail.com> | 2015-07-26 14:35:32 +0200 |
commit | 5df394485efbbbc5413b21b9efd6f039ff18fae1 (patch) | |
tree | 17a4cd907c79d5e7e75de7cf8c68dbb7dd9f1895 /sqlparse | |
parent | d463a753216b5c9e2c7f2b3c8a48fa76cbdb73c2 (diff) | |
parent | 8987a3a6b540ea35bbb1f9c5f49f3306501289cd (diff) | |
download | sqlparse-v0.2.0.tar.gz |
Merge branch 'master' into v0.2.0v0.2.0
Diffstat (limited to 'sqlparse')
-rw-r--r-- | sqlparse/__init__.py | 2 | ||||
-rw-r--r-- | sqlparse/engine/filter.py | 2 | ||||
-rw-r--r-- | sqlparse/lexer.py | 6 | ||||
-rw-r--r-- | sqlparse/sql.py | 15 |
4 files changed, 17 insertions, 8 deletions
diff --git a/sqlparse/__init__.py b/sqlparse/__init__.py index 79dd83f..d943956 100644 --- a/sqlparse/__init__.py +++ b/sqlparse/__init__.py @@ -6,7 +6,7 @@ """Parse SQL statements.""" -__version__ = '0.1.14' +__version__ = '0.1.17-dev' # Setup namespace from sqlparse import compat 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 diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py index 602d275..7ce6d36 100644 --- a/sqlparse/lexer.py +++ b/sqlparse/lexer.py @@ -141,10 +141,10 @@ class Lexer(compat.with_metaclass(LexerMeta)): 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'), @@ -162,7 +162,7 @@ class Lexer(compat.with_metaclass(LexerMeta)): # 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/sqlparse/sql.py b/sqlparse/sql.py index 89d1059..8601537 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -233,15 +233,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): @@ -390,7 +395,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 @@ -460,8 +466,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. |