diff --git a/lib/SqlFormatter.php b/lib/SqlFormatter.php index 82927e4..4f550f3 100644 --- a/lib/SqlFormatter.php +++ b/lib/SqlFormatter.php @@ -753,12 +753,18 @@ public static function splitQuery($string) $queries = array(); $current_query = ''; $empty = true; + $lookForEnd = false; $tokens = self::tokenize($string); foreach ($tokens as $token) { + + if ($token[self::TOKEN_VALUE] === 'BEGIN') { + $lookForEnd = true; + } + // If this is a query separator - if ($token[self::TOKEN_VALUE] === ';') { + if ($token[self::TOKEN_VALUE] === ';' && !$lookForEnd) { if (!$empty) { $queries[] = $current_query.';'; } @@ -772,6 +778,10 @@ public static function splitQuery($string) $empty = false; } + if ($token[self::TOKEN_VALUE] === 'END') { + $lookForEnd = false; + } + $current_query .= $token[self::TOKEN_VALUE]; }