summaryrefslogtreecommitdiff
path: root/sqlparse/sql.py
diff options
context:
space:
mode:
authorAndreas Albrecht <andreas.albrecht@prounix.de>2009-10-22 13:43:38 +0200
committerAndreas Albrecht <andreas.albrecht@prounix.de>2009-10-22 13:43:38 +0200
commitacea845a7f77158bb12d9e35ff56698d769ad947 (patch)
tree8cecbb6115e54f160382c97a05ffc1718eddead0 /sqlparse/sql.py
parentb4fe0f2e8aece1a5eb8d6d5260dd092c48ac6a46 (diff)
downloadsqlparse-acea845a7f77158bb12d9e35ff56698d769ad947.tar.gz
Improved case detection for CASE structures without WHEN in first case.
Diffstat (limited to 'sqlparse/sql.py')
-rw-r--r--sqlparse/sql.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
index 195696e..a28cf8b 100644
--- a/sqlparse/sql.py
+++ b/sqlparse/sql.py
@@ -471,9 +471,12 @@ class Case(TokenList):
If an ELSE exists condition is None.
"""
ret = []
- in_condition = in_value = False
+ in_value = False
+ in_condition = True
for token in self.tokens:
- if token.match(T.Keyword, 'WHEN'):
+ if token.match(T.Keyword, 'CASE'):
+ continue
+ elif token.match(T.Keyword, 'WHEN'):
ret.append(([], []))
in_condition = True
in_value = False
@@ -487,6 +490,9 @@ class Case(TokenList):
elif token.match(T.Keyword, 'END'):
in_condition = False
in_value = False
+ if (in_condition or in_value) and not ret:
+ # First condition withou preceding WHEN
+ ret.append(([], []))
if in_condition:
ret[-1][0].append(token)
elif in_value: