Skip to content

Commit fac431b

Browse files
committed
Fix an issue with trailing whitespaces (reported by Kris).
1 parent ed2d254 commit fac431b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Bug Fixes
66
reported and initial patch by andyboyko).
77
* Stricter detection of identfier aliases (issue8, reported by estama).
88
* WHERE grouping consumed closing parenthesis (issue9, reported by estama).
9+
* Fixed an issue with trailing whitespaces (reported by Kris).
910

1011

1112
Release 0.1.1 (May 6, 2009)
@@ -25,4 +26,4 @@ Other
2526

2627
Release 0.1.0 (Apr 8, 2009)
2728
---------------------------
28-
* Initial release.
29+
* Initial release.

sqlparse/sql.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,11 @@ def get_type(self):
323323
isn't a DML or DDL keyword "UNKNOWN" is returned.
324324
"""
325325
first_token = self.token_first()
326-
if first_token.ttype in (T.Keyword.DML, T.Keyword.DDL):
326+
if first_token is None:
327+
# An "empty" statement that either has not tokens at all
328+
# or only whitespace tokens.
329+
return 'UNKNOWN'
330+
elif first_token.ttype in (T.Keyword.DML, T.Keyword.DDL):
327331
return first_token.value.upper()
328332
else:
329333
return 'UNKNOWN'

tests/test_grouping.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,7 @@ def test_get_type(self):
176176
self.assertEqual(f(' update foo').get_type(), 'UPDATE')
177177
self.assertEqual(f('\nupdate foo').get_type(), 'UPDATE')
178178
self.assertEqual(f('foo').get_type(), 'UNKNOWN')
179+
# Statements that have a whitespace after the closing semicolon
180+
# are parsed as two statements where later only consists of the
181+
# trailing whitespace.
182+
self.assertEqual(f('\n').get_type(), 'UNKNOWN')

0 commit comments

Comments
 (0)