Summary
When CreateStatement::build() reconstructs a CREATE VIEW ... AS SELECT ... UNION ...
statement, the output misses the whitespace between the built SELECT and the
trailing body tokens. Result: invalid SQL such as ... WHERE 3 = 3union all (...).
This was previously reported downstream in phpMyAdmin:
Reproduction
use PhpMyAdmin\SqlParser\Parser;
$sql = "CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER "
. "VIEW `v1` AS select 1 AS `a` where 3 = 3 union all (select 2 AS `a`)";
echo (new Parser($sql))->statements[0]->build();
Actual output:
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS SELECT 1 AS `a` WHERE 3 = 3union all (select 2 AS `a`)
(note: 3 = 3union all — no space).
Expected: a space before union all, producing valid SQL.
Environment
- Library version: current
master (head f440917e)
- PHP: 8.4
Summary
When
CreateStatement::build()reconstructs aCREATE VIEW ... AS SELECT ... UNION ...statement, the output misses the whitespace between the built
SELECTand thetrailing body tokens. Result: invalid SQL such as
... WHERE 3 = 3union all (...).This was previously reported downstream in phpMyAdmin:
Reproduction
Actual output:
(note:
3 = 3union all— no space).Expected: a space before
union all, producing valid SQL.Environment
master(headf440917e)