diff options
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | sqlparse/sql.py | 6 | ||||
| -rw-r--r-- | tests/test_grouping.py | 4 |
3 files changed, 11 insertions, 2 deletions
@@ -6,6 +6,7 @@ Bug Fixes reported and initial patch by andyboyko). * Stricter detection of identfier aliases (issue8, reported by estama). * WHERE grouping consumed closing parenthesis (issue9, reported by estama). + * Fixed an issue with trailing whitespaces (reported by Kris). Release 0.1.1 (May 6, 2009) @@ -25,4 +26,4 @@ Other Release 0.1.0 (Apr 8, 2009) --------------------------- - * Initial release.
\ No newline at end of file + * Initial release. diff --git a/sqlparse/sql.py b/sqlparse/sql.py index a28cf8b..cc4f434 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -323,7 +323,11 @@ class Statement(TokenList): isn't a DML or DDL keyword "UNKNOWN" is returned. """ first_token = self.token_first() - if first_token.ttype in (T.Keyword.DML, T.Keyword.DDL): + if first_token is None: + # An "empty" statement that either has not tokens at all + # or only whitespace tokens. + return 'UNKNOWN' + elif first_token.ttype in (T.Keyword.DML, T.Keyword.DDL): return first_token.value.upper() else: return 'UNKNOWN' diff --git a/tests/test_grouping.py b/tests/test_grouping.py index 119f574..dcc1309 100644 --- a/tests/test_grouping.py +++ b/tests/test_grouping.py @@ -176,3 +176,7 @@ class TestStatement(TestCaseBase): self.assertEqual(f(' update foo').get_type(), 'UPDATE') self.assertEqual(f('\nupdate foo').get_type(), 'UPDATE') self.assertEqual(f('foo').get_type(), 'UNKNOWN') + # Statements that have a whitespace after the closing semicolon + # are parsed as two statements where later only consists of the + # trailing whitespace. + self.assertEqual(f('\n').get_type(), 'UNKNOWN') |
