From b27fa0259288e1deec2eb0795657bb14b991c024 Mon Sep 17 00:00:00 2001 From: Oleg Subotin Date: Wed, 19 Nov 2014 12:04:16 +0200 Subject: [PATCH] fix incorrect splitting of create procedure statement --- lib/SqlFormatter.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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]; }