phpmyadmin / phpmyadmin/sql-parser
[Bug]: Problem exporting an unsual index (IFNULL expression)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- PHP
- Sterne
- 485
- Forks
- 119
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Describe the bug
I added this index to a table:
ALTER TABLE drafts
ADD UNIQUE unique_draft (type,user,(IFNULL(touser,'_CHAT_'))) USING BTREE;
and when I try to export it fails with this error (on hosting phpmyadmin version 5.1.0, mysql is Percona 8.0.43-34):
Fatal error: Uncaught TypeError: str_replace(): Argument phpmyadmin/phpmyadmin#3 ($subject) must be of type array|string, null given in /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Context.php:608
Stack trace:
#0 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Context.php(608): str_replace()
phpmyadmin/phpmyadmin#1 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Components/Key.php(203): PhpMyAdmin\SqlParser\Context::escape()
phpmyadmin/phpmyadmin#2 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Component.php(74): PhpMyAdmin\SqlParser\Components\Key::build()
phpmyadmin/phpmyadmin#3 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Components/CreateDefinition.php(360): PhpMyAdmin\SqlParser\Component->__toString()
phpmyadmin/phpmyadmin#4 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Component.php(74): PhpMyAdmin\SqlParser\Components\CreateDefinition::build()
phpmyadmin/phpmyadmin#5 [internal function]: PhpMyAdmin\SqlParser\Component->__toString()
phpmyadmin/phpmyadmin#6 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Components/CreateDefinition.php(339): implode()
phpmyadmin/phpmyadmin#7 /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Statements/CreateStatement.php(380): PhpMyAdmin\SqlParser\Components\CreateDefinition::build()
phpmyadmin/phpmyadmin#8 /var/www/html/phpMyAdmin/libraries/classes/Plugins/Export/ExportSql.php(2951): PhpMyAdmin\SqlParser\Statements\CreateStatement->build()
phpmyadmin/phpmyadmin#9 /var/www/html/phpMyAdmin/libraries/classes/Plugins/Export/ExportSql.php(1638): PhpMyAdmin\Plugins\Export\ExportSql->replaceWithAliases()
phpmyadmin/phpmyadmin#10 /var/www/html/phpMyAdmin/libraries/classes/Plugins/Export/ExportSql.php(2138): PhpMyAdmin\Plugins\Export\ExportSql->getTableDef()
phpmyadmin/phpmyadmin#11 /var/www/html/phpMyAdmin/libraries/classes/Export.php(813): PhpMyAdmin\Plugins\Export\ExportSql->exportStructure()
phpmyadmin/phpmyadmin#12 /var/www/html/phpMyAdmin/libraries/classes/Controllers/ExportController.php(549): PhpMyAdmin\Export->exportDatabase()
phpmyadmin/phpmyadmin#13 /var/www/html/phpMyAdmin/libraries/classes/Routing.php(186): PhpMyAdmin\Controllers\ExportController->index()
phpmyadmin/phpmyadmin#14 /var/www/html/phpMyAdmin/index.php(50): PhpMyAdmin\Routing::callControllerForRoute()
phpmyadmin/phpmyadmin#15 {main}
thrown in /var/www/html/phpMyAdmin/vendor/phpmyadmin/sql-parser/src/Context.php on line 608
On version 5.2.1 with mysql 8.0.41 it won't fails but the export result is like this
ALTER TABLE drafts ADD UNIQUE KEY unique_draft (type,user,(_CHAT_));
which is wrong.
How to Reproduce
Table structure is:
CREATE TABLE drafts (
type enum('CHAT','MSGS') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
user varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
touser varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
text text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
date datetime NOT NULL
);
ALTER TABLE drafts ADD UNIQUE unique_draft (type, user,(IFNULL(touser,'_CHAT_'))) USING BTREE;
Expected behavior
I expect it to export the index like the original one
Screenshots
No response
Operating System
No response
Web Server
No response
Database Server
MySQL
Database version
No response
PHP version
No response
phpMyAdmin version
5.1.0
browser
No response
Additional context
No response
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Der Fehler wird über vendor/phpmyadmin/sql-parser/src/Context.php:608 und Components/Key.php:203 während des Exportpfads von ExportSql.php gemeldet. Reproduzieren Sie ihn mit der bereitgestellten drafts-Tabelle und Indexdefinition und untersuchen Sie anschließend den Parser-/Build-Pfad; die Aufgabe ist abgeschlossen, wenn der Export keine Exception mehr auslöst und IFNULL(touser,'CHAT') beibehält, statt CHAT auszugeben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- mysql, php
- Bereich
- databases
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100