From 693d7a31c1fff960763ff3ba485142ce67ff708f Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 24 Jul 2011 00:37:47 +0200 Subject: Split statements with IF as functions correctly (fixes issue33). --- sqlparse/engine/filter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'sqlparse/engine') diff --git a/sqlparse/engine/filter.py b/sqlparse/engine/filter.py index 241f5ea..89d9b15 100644 --- a/sqlparse/engine/filter.py +++ b/sqlparse/engine/filter.py @@ -21,11 +21,13 @@ class StatementFilter(TokenFilter): self._in_declare = False self._in_dbldollar = False self._is_create = False + self._begin_depth = 0 def _reset(self): self._in_declare = False self._in_dbldollar = False self._is_create = False + self._begin_depth = 0 def _change_splitlevel(self, ttype, value): # PostgreSQL @@ -51,6 +53,7 @@ class StatementFilter(TokenFilter): return 1 if unified == 'BEGIN': + self._begin_depth += 1 if self._in_declare: # FIXME(andi): This makes no sense. return 0 return 0 @@ -58,13 +61,14 @@ class StatementFilter(TokenFilter): if unified == 'END': # Should this respect a preceeding BEGIN? # In CASE ... WHEN ... END this results in a split level -1. + self._begin_depth = max(0, self._begin_depth-1) return -1 if ttype is T.Keyword.DDL and unified.startswith('CREATE'): self._is_create = True return 0 - if unified in ('IF', 'FOR') and self._is_create: + if unified in ('IF', 'FOR') and self._is_create and self._begin_depth > 0: return 1 # Default -- cgit v1.2.1