Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Improve collations support for MariaDB 10.10+ (phpmyadmin#18760)
Browse files Browse the repository at this point in the history
* Added new charset queries

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Improve collations support for MariaDB 10.10+

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Using dbi to check for MariaDB

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Removed unnecessary query

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Cleanup

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Whitespaces

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Whitespaces

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Switched to getVersion()

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Removed use of version_compare

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Test for MariaDB 10.10+

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>

* Update test/classes/CharsetsTest.php

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>

---------

Signed-off-by: Dmitrii Kustov <simbiat@outlook.com>
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Co-authored-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
Simbiat and MauricioFauth committed Oct 31, 2023
1 parent 270a40f commit ef92f1f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/Charsets.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,31 @@ private static function loadCollations(DatabaseInterface $dbi, bool $disableIs):
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 ($disableIs) {
$sql = 'SHOW COLLATION';
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';
}
}

$res = $dbi->query($sql);
Expand Down
13 changes: 13 additions & 0 deletions test/classes/CharsetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PhpMyAdmin\Tests;

use PhpMyAdmin\Charsets;
use PhpMyAdmin\DatabaseInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
Expand Down Expand Up @@ -100,6 +101,18 @@ public function testGetCollationsWithIS(): void
}
}

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();
Expand Down
19 changes: 19 additions & 0 deletions test/classes/Stubs/DbiDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,25 @@ private function init(): void
'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 */
Expand Down

0 comments on commit ef92f1f

Please sign in to comment.