phpmyadmin / phpmyadmin/sql-parser

Missing space before UNION when building CREATE VIEW

Offen Anfängerfreundlich
#655 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
PHP
Sterne
485
Forks
119
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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:

  • phpmyadmin/phpmyadmin#19692
  • phpmyadmin/phpmyadmin#18515 (same bug, older)

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne bei CreateStatement::build() und reproduziere das Problem mit dem SQL-Beispiel über PhpMyAdmin\SqlParser\Parser. Überprüfe, dass das erneute Erstellen von CREATE VIEW den Leerraum vor dem abschließenden UNION-Body beibehält und gültiges SQL statt 3union all erzeugt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
mysql, php
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.