phpmyadmin / phpmyadmin/sql-parser

[Bug]: Problem exporting an unsual index (IFNULL expression)

Ouverte
#640 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug
Langage dominant
PHP
Étoiles
485
Forks
119
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

L’échec est signalé via vendor/phpmyadmin/sql-parser/src/Context.php:608 et Components/Key.php:203 lors du chemin d’exportation de ExportSql.php. Reproduisez-le avec la table drafts et la définition d’index fournies, puis inspectez le chemin du parser/build ; c’est terminé lorsque l’exportation ne lève plus d’exception et préserve IFNULL(touser,'CHAT') au lieu d’émettre CHAT.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
mysql, php
Domaine
databases
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
48/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.