From ea60c287ff95a699359feca1ffc9abfb72370d26 Mon Sep 17 00:00:00 2001 From: Damian Dlugosz Date: Thu, 16 Feb 2017 22:06:02 +0100 Subject: [PATCH] Inline JOINs --- src/Utils/Formatter.php | 10 ++++++++++ tests/Utils/FormatterTest.php | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php index 16c0778a4..e07394c0f 100644 --- a/src/Utils/Formatter.php +++ b/src/Utils/Formatter.php @@ -6,6 +6,7 @@ namespace PhpMyAdmin\SqlParser\Utils; +use PhpMyAdmin\SqlParser\Components\JoinKeyword; use PhpMyAdmin\SqlParser\Lexer; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Token; @@ -383,6 +384,15 @@ public function formatList($list) } } + // Inline JOINs + if (($prev->type === Token::TYPE_KEYWORD && isset(JoinKeyword::$JOINS[$prev->value])) + || (in_array($curr->value, array('ON', 'USING'), true) && isset(JoinKeyword::$JOINS[$list->tokens[$list->idx - 2]->value])) + || (isset($list->tokens[$list->idx - 4]) && isset(JoinKeyword::$JOINS[$list->tokens[$list->idx - 4]->value])) + || (isset($list->tokens[$list->idx - 6]) && isset(JoinKeyword::$JOINS[$list->tokens[$list->idx - 6]->value])) + ) { + $lineEnded = false; + } + // Indenting BEGIN ... END blocks. if ($prev->type === Token::TYPE_KEYWORD && $prev->keyword === 'BEGIN') { $lineEnded = true; diff --git a/tests/Utils/FormatterTest.php b/tests/Utils/FormatterTest.php index b8a8ff28c..c209d2759 100644 --- a/tests/Utils/FormatterTest.php +++ b/tests/Utils/FormatterTest.php @@ -508,6 +508,13 @@ public function formatQueries() '    `query` TEXT NOT NULL,' . '
' . '    PRIMARY KEY(`id`)', ), + 'join' => array( + 'query' => 'join tbl2 on c1=c2', + 'text' => 'JOIN tbl2 ON c1 = c2', + 'cli' => "\x1b[35mJOIN \x1b[39mtbl2 \x1b[35mON \x1b[39mc1 \x1b[39m= \x1b[39mc2" . + "\x1b[0m", + 'html' => 'JOIN tbl2 ON c1 = c2', + ), ); } }