From acea845a7f77158bb12d9e35ff56698d769ad947 Mon Sep 17 00:00:00 2001 From: Andreas Albrecht Date: Thu, 22 Oct 2009 13:43:38 +0200 Subject: Improved case detection for CASE structures without WHEN in first case. --- sqlparse/sql.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'sqlparse/sql.py') 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: -- cgit v1.2.1