| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,12 @@ | |||
| 12 | 12 | ||
| 13 | 13 | - Add Translator::setLocale() method (#599) | |
| 14 | 14 | ||
| 15 | + # [5.10.3] - YYYY-MM-DD | ||
| 16 | + | ||
| 17 | + ### Fixed | ||
| 18 | + | ||
| 19 | + - Add "RECURSIVE" on build() for "WITH RECURSIVE" on the WithStatement class (#605) | ||
| 20 | + | ||
| 15 | 21 | ## [5.10.2] - 2024-12-05 | |
| 16 | 22 | ||
| 17 | 23 | ### Added | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -716,22 +716,22 @@ parameters: | |||
| 716 | 716 | path: src/Parsers/OptionsArrays.php | |
| 717 | 717 | ||
| 718 | 718 | - | |
| 719 | - message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:\\$options \\(array\\<int, array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\) does not accept non\\-empty\\-array\\<int\\|string, array\\{name\\: bool\\|float\\|int\\|string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\.$#" | ||
| 719 | + message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:\\$options \\(array\\<int, array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\) does not accept non\\-empty\\-array\\<array\\{name\\: bool\\|float\\|int\\|string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\.$#" | ||
| 720 | 720 | count: 2 | |
| 721 | 721 | path: src/Parsers/OptionsArrays.php | |
| 722 | 722 | ||
| 723 | 723 | - | |
| 724 | - message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:\\$options \\(array\\<int, array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\) does not accept non\\-empty\\-array\\<int\\|string, array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|bool\\|float\\|int\\|string\\>\\.$#" | ||
| 724 | + message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:\\$options \\(array\\<int, array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\) does not accept non\\-empty\\-array\\<array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|bool\\|float\\|int\\|string\\>\\.$#" | ||
| 725 | 725 | count: 1 | |
| 726 | 726 | path: src/Parsers/OptionsArrays.php | |
| 727 | 727 | ||
| 728 | 728 | - | |
| 729 | - message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:\\$options \\(array\\<int, array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\) does not accept non\\-empty\\-array\\<int\\|string, array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\.$#" | ||
| 729 | + message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:\\$options \\(array\\<int, array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\) does not accept non\\-empty\\-array\\<array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\.$#" | ||
| 730 | 730 | count: 3 | |
| 731 | 731 | path: src/Parsers/OptionsArrays.php | |
| 732 | 732 | ||
| 733 | 733 | - | |
| 734 | - message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:\\$options \\(array\\<int, array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\) does not accept non\\-empty\\-array\\<int\\|string, mixed\\>\\.$#" | ||
| 734 | + message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:\\$options \\(array\\<int, array\\{name\\: string, equals\\: bool, expr\\: PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string, value\\: string\\|null\\}\\|string\\>\\) does not accept non\\-empty\\-array\\<mixed\\>\\.$#" | ||
| 735 | 735 | count: 3 | |
| 736 | 736 | path: src/Parsers/OptionsArrays.php | |
| 737 | 737 | ||
@@ -1722,7 +1722,7 @@ parameters: | |||
| 1722 | 1722 | ||
| 1723 | 1723 | - | |
| 1724 | 1724 | message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" | |
| 1725 | - count: 33 | ||
| 1725 | + count: 34 | ||
| 1726 | 1726 | path: tests/Builder/CreateStatementTest.php | |
| 1727 | 1727 | ||
| 1728 | 1728 | - | |
@@ -1977,7 +1977,7 @@ parameters: | |||
| 1977 | 1977 | ||
| 1978 | 1978 | - | |
| 1979 | 1979 | message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" | |
| 1980 | - count: 8 | ||
| 1980 | + count: 9 | ||
| 1981 | 1981 | path: tests/Components/OptionsArrayTest.php | |
| 1982 | 1982 | ||
| 1983 | 1983 | - | |
@@ -2212,12 +2212,12 @@ parameters: | |||
| 2212 | 2212 | ||
| 2213 | 2213 | - | |
| 2214 | 2214 | message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertCount\\(\\)\\.$#" | |
| 2215 | - count: 8 | ||
| 2215 | + count: 14 | ||
| 2216 | 2216 | path: tests/Parser/WithStatementTest.php | |
| 2217 | 2217 | ||
| 2218 | 2218 | - | |
| 2219 | 2219 | message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" | |
| 2220 | - count: 3 | ||
| 2220 | + count: 5 | ||
| 2221 | 2221 | path: tests/Parser/WithStatementTest.php | |
| 2222 | 2222 | ||
| 2223 | 2223 | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -269,11 +269,17 @@ public function parse(Parser $parser, TokensList $list): void | |||
| 269 | 269 | ||
| 270 | 270 | public function build(): string | |
| 271 | 271 | { | |
| 272 | - $str = 'WITH '; | ||
| 272 | + $initial = true; | ||
| 273 | + $str = 'WITH'; | ||
| 274 | + | ||
| 275 | + if ($this->options !== null && $this->options->options !== []) { | ||
| 276 | + $str .= ' ' . $this->options->build(); | ||
| 277 | + } | ||
| 273 | 278 | ||
| 274 | 279 | foreach ($this->withers as $wither) { | |
| 275 | - $str .= $str === 'WITH ' ? '' : ', '; | ||
| 280 | + $str .= $initial ? ' ' : ', '; | ||
| 276 | 281 | $str .= $wither->build(); | |
| 282 | + $initial = false; | ||
| 277 | 283 | } | |
| 278 | 284 | ||
| 279 | 285 | $str .= ' '; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,8 @@ | |||
| 19 | 19 | use PhpMyAdmin\SqlParser\TokenType; | |
| 20 | 20 | use PHPUnit\Framework\Attributes\DataProvider; | |
| 21 | 21 | ||
| 22 | + use function implode; | ||
| 23 | + | ||
| 22 | 24 | class CreateStatementTest extends TestCase | |
| 23 | 25 | { | |
| 24 | 26 | public function testBuilder(): void | |
@@ -401,6 +403,33 @@ public function testBuilderView(): void | |||
| 401 | 403 | . ' AS (SELECT 1 UNION ALL SELECT 2) SELECT col1 FROM cte AS `d` ', | |
| 402 | 404 | $stmt->build(), | |
| 403 | 405 | ); | |
| 406 | + | ||
| 407 | + $parser = new Parser( | ||
| 408 | + implode("\n", [ | ||
| 409 | + 'CREATE VIEW number_sequence_view AS', | ||
| 410 | + 'WITH RECURSIVE number_sequence AS (', | ||
| 411 | + ' SELECT 1 AS `number`', | ||
| 412 | + ' UNION ALL', | ||
| 413 | + ' SELECT `number` + 1', | ||
| 414 | + ' FROM number_sequence', | ||
| 415 | + ' WHERE `number` < 5', | ||
| 416 | + ')', | ||
| 417 | + 'SELECT * FROM number_sequence;', | ||
| 418 | + ]), | ||
| 419 | + ); | ||
| 420 | + $stmt = $parser->statements[0]; | ||
| 421 | + $this->assertEquals( | ||
| 422 | + 'CREATE VIEW number_sequence_view AS' | ||
| 423 | + . ' WITH RECURSIVE number_sequence AS (' | ||
| 424 | + . 'SELECT 1 AS `number`' | ||
| 425 | + . ' UNION ALL' | ||
| 426 | + . ' SELECT `number`+ 1' | ||
| 427 | + . ' FROM number_sequence' | ||
| 428 | + . ' WHERE `number` < 5' | ||
| 429 | + . ')' | ||
| 430 | + . ' SELECT * FROM number_sequence ', | ||
| 431 | + $stmt->build(), | ||
| 432 | + ); | ||
| 404 | 433 | } | |
| 405 | 434 | ||
| 406 | 435 | public function testBuilderViewComplex(): void | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,4 +136,17 @@ public function testBuild(): void | |||
| 136 | 136 | $component->build(), | |
| 137 | 137 | ); | |
| 138 | 138 | } | |
| 139 | + | ||
| 140 | + public function testBuildWithRecursive(): void | ||
| 141 | + { | ||
| 142 | + $component = OptionsArrays::parse( | ||
| 143 | + new Parser(), | ||
| 144 | + $this->getTokensList('RECURSIVE'), | ||
| 145 | + ['RECURSIVE' => 1], | ||
| 146 | + ); | ||
| 147 | + $this->assertEquals( | ||
| 148 | + 'RECURSIVE', | ||
| 149 | + $component->build(), | ||
| 150 | + ); | ||
| 151 | + } | ||
| 139 | 152 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,6 +70,70 @@ public function testWith(): void | |||
| 70 | 70 | $this->assertEquals($expected, $parser->statements[0]->build()); | |
| 71 | 71 | } | |
| 72 | 72 | ||
| 73 | + public function testWithRecursive(): void | ||
| 74 | + { | ||
| 75 | + $sql = <<<'SQL' | ||
| 76 | + WITH RECURSIVE number_sequence AS ( | ||
| 77 | + SELECT 1 AS `number` | ||
| 78 | + UNION ALL | ||
| 79 | + SELECT `number` + 1 | ||
| 80 | + FROM number_sequence | ||
| 81 | + WHERE `number` < 5 | ||
| 82 | + ) | ||
| 83 | + SELECT * FROM number_sequence; | ||
| 84 | + SQL; | ||
| 85 | + | ||
| 86 | + $lexer = new Lexer($sql); | ||
| 87 | + | ||
| 88 | + $lexerErrors = $this->getErrorsAsArray($lexer); | ||
| 89 | + $this->assertCount(0, $lexerErrors); | ||
| 90 | + $parser = new Parser($lexer->list); | ||
| 91 | + $parserErrors = $this->getErrorsAsArray($parser); | ||
| 92 | + $this->assertCount(0, $parserErrors); | ||
| 93 | + $this->assertCount(1, $parser->statements); | ||
| 94 | + | ||
| 95 | + // phpcs:disable Generic.Files.LineLength.TooLong | ||
| 96 | + $expected = <<<'SQL' | ||
| 97 | + WITH RECURSIVE number_sequence AS (SELECT 1 AS `number` UNION ALL SELECT `number`+ 1 FROM number_sequence WHERE `number` < 5) SELECT * FROM number_sequence | ||
| 98 | + SQL; | ||
| 99 | + // phpcs:enable | ||
| 100 | + $this->assertEquals($expected, $parser->statements[0]->build()); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public function testWithRecursiveWithers(): void | ||
| 104 | + { | ||
| 105 | + $sql = <<<'SQL' | ||
| 106 | + WITH RECURSIVE cte AS | ||
| 107 | + ( | ||
| 108 | + SELECT 1 AS n, CAST('abc' AS CHAR(20)) AS str | ||
| 109 | + UNION ALL | ||
| 110 | + SELECT n + 1, CONCAT(str, str) FROM cte WHERE n < 3 | ||
| 111 | + ), cte2 AS | ||
| 112 | + ( | ||
| 113 | + SELECT 1 AS n, CAST('def' AS CHAR(20)) AS str | ||
| 114 | + UNION ALL | ||
| 115 | + SELECT n + 1, CONCAT(str, str) FROM cte WHERE n < 3 | ||
| 116 | + ) | ||
| 117 | + SELECT * FROM cte UNION SELECT * FROM cte2; | ||
| 118 | + SQL; | ||
| 119 | + | ||
| 120 | + $lexer = new Lexer($sql); | ||
| 121 | + | ||
| 122 | + $lexerErrors = $this->getErrorsAsArray($lexer); | ||
| 123 | + $this->assertCount(0, $lexerErrors); | ||
| 124 | + $parser = new Parser($lexer->list); | ||
| 125 | + $parserErrors = $this->getErrorsAsArray($parser); | ||
| 126 | + $this->assertCount(0, $parserErrors); | ||
| 127 | + $this->assertCount(1, $parser->statements); | ||
| 128 | + | ||
| 129 | + // phpcs:disable Generic.Files.LineLength.TooLong | ||
| 130 | + $expected = <<<'SQL' | ||
| 131 | + WITH RECURSIVE cte AS (SELECT 1 AS `n`, CAST('abc' AS CHAR(20)) AS `str` UNION ALL SELECT n+ 1, CONCAT(str, str) FROM cte WHERE n < 3), cte2 AS (SELECT 1 AS `n`, CAST('def' AS CHAR(20)) AS `str` UNION ALL SELECT n+ 1, CONCAT(str, str) FROM cte WHERE n < 3) SELECT * FROM cte UNION SELECT * FROM cte2 | ||
| 132 | + SQL; | ||
| 133 | + // phpcs:enable | ||
| 134 | + $this->assertEquals($expected, $parser->statements[0]->build()); | ||
| 135 | + } | ||
| 136 | + | ||
| 73 | 137 | public function testWithHasErrors(): void | |
| 74 | 138 | { | |
| 75 | 139 | $sql = <<<'SQL' | |
| Back | FazBrowse Home | New Git URL |
0 commit comments