diff --git a/src/Charsets.php b/src/Charsets.php index bc8b7656df..6850676b92 100644 --- a/src/Charsets.php +++ b/src/Charsets.php @@ -109,16 +109,31 @@ class Charsets return; } - $sql = 'SELECT `COLLATION_NAME` AS `Collation`,' - . ' `CHARACTER_SET_NAME` AS `Charset`,' - . ' `ID` AS `Id`,' - . ' `IS_DEFAULT` AS `Default`,' - . ' `IS_COMPILED` AS `Compiled`,' - . ' `SORTLEN` AS `Sortlen`' - . ' FROM `information_schema`.`COLLATIONS`'; + if ($dbi->isMariaDB() && $dbi->getVersion() >= 101000) { + /* Use query to accommodate new structure of MariaDB collations. + Note, that SHOW COLLATION command is not applicable at the time of writing. + Refer https://jira.mariadb.org/browse/MDEV-27009 */ + $sql = 'SELECT `collapp`.`FULL_COLLATION_NAME` AS `Collation`,' + . ' `collapp`.`CHARACTER_SET_NAME` AS `Charset`,' + . ' `collapp`.`ID` AS `Id`,' + . ' `collapp`.`IS_DEFAULT` AS `Default`,' + . ' `coll`.`IS_COMPILED` AS `Compiled`,' + . ' `coll`.`SORTLEN` AS `Sortlen`' + . ' FROM `information_schema`.`COLLATION_CHARACTER_SET_APPLICABILITY` `collapp`' + . ' LEFT JOIN `information_schema`.`COLLATIONS` `coll`' + . ' ON `collapp`.`COLLATION_NAME`=`coll`.`COLLATION_NAME`'; + } else { + $sql = 'SELECT `COLLATION_NAME` AS `Collation`,' + . ' `CHARACTER_SET_NAME` AS `Charset`,' + . ' `ID` AS `Id`,' + . ' `IS_DEFAULT` AS `Default`,' + . ' `IS_COMPILED` AS `Compiled`,' + . ' `SORTLEN` AS `Sortlen`' + . ' FROM `information_schema`.`COLLATIONS`'; - if ($disableIs) { - $sql = 'SHOW COLLATION'; + if ($disableIs) { + $sql = 'SHOW COLLATION'; + } } $res = $dbi->query($sql); diff --git a/test/classes/CharsetsTest.php b/test/classes/CharsetsTest.php index eb589c55d5..a5894c6f53 100644 --- a/test/classes/CharsetsTest.php +++ b/test/classes/CharsetsTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests; use PhpMyAdmin\Charsets; +use PhpMyAdmin\DatabaseInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; @@ -100,6 +101,18 @@ class CharsetsTest extends AbstractTestCase } } + public function testGetCollationsMariaDB(): void + { + $dbi = $this->createDatabaseInterface(); + $dbi->setVersion(['@@version' => '10.10.0-MariaDB']); + $collations = Charsets::getCollations($dbi, false); + $this->assertCount(4, $collations); + $this->assertContainsOnly('array', $collations); + foreach ($collations as $collation) { + $this->assertContainsOnlyInstancesOf(Charsets\Collation::class, $collation); + } + } + public function testGetCollationsWithoutIS(): void { $dummyDbi = $this->createDbiDummy(); diff --git a/test/classes/Stubs/DbiDummy.php b/test/classes/Stubs/DbiDummy.php index d9e27e5a96..c77eafdeb1 100644 --- a/test/classes/Stubs/DbiDummy.php +++ b/test/classes/Stubs/DbiDummy.php @@ -2227,6 +2227,25 @@ class DbiDummy implements DbiExtension 'columns' => ['row_count'], 'result' => [['984']], ], + [ + 'query' => 'SELECT `collapp`.`FULL_COLLATION_NAME` AS `Collation`,' + . ' `collapp`.`CHARACTER_SET_NAME` AS `Charset`,' + . ' `collapp`.`ID` AS `Id`,' + . ' `collapp`.`IS_DEFAULT` AS `Default`,' + . ' `coll`.`IS_COMPILED` AS `Compiled`,' + . ' `coll`.`SORTLEN` AS `Sortlen`' + . ' FROM `information_schema`.`COLLATION_CHARACTER_SET_APPLICABILITY` `collapp`' + . ' LEFT JOIN `information_schema`.`COLLATIONS` `coll`' + . ' ON `collapp`.`COLLATION_NAME`=`coll`.`COLLATION_NAME`', + 'columns' => ['Collation', 'Charset', 'Id', 'Default', 'Compiled', 'Sortlen'], + 'result' => [ + ['utf8mb4_general_ci', 'utf8mb4', '45', 'Yes', 'Yes', '1'], + ['armscii8_general_ci', 'armscii8', '32', 'Yes', 'Yes', '1'], + ['utf8_general_ci', 'utf8', '33', 'Yes', 'Yes', '1'], + ['utf8_bin', 'utf8', '83', '', 'Yes', '1'], + ['latin1_swedish_ci', 'latin1', '8', 'Yes', 'Yes', '1'], + ], + ], ]; /* Some basic setup for dummy driver */