Skip to content

Commit

Permalink
Improve collations support for MariaDB 10.10+ (#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>

Fixes #18769

---------

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>
(cherry picked from commit ef92f1f)
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
Simbiat and MauricioFauth committed Oct 31, 2023
1 parent 437d751 commit 4bdf519
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
35 changes: 25 additions & 10 deletions libraries/classes/Charsets.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,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
11 changes: 11 additions & 0 deletions test/classes/CharsetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,15 @@ public function testFindCollationByName(): void

$this->assertSame('utf8_general_ci', $actual->getName());
}

public function testGetCollationsMariaDB(): void
{
$this->dbi->setVersion(['@@version' => '10.10.0-MariaDB']);
$collations = Charsets::getCollations($this->dbi, false);
$this->assertCount(4, $collations);
$this->assertContainsOnly('array', $collations);
foreach ($collations as $collation) {
$this->assertContainsOnlyInstancesOf(Charsets\Collation::class, $collation);
}
}
}
19 changes: 19 additions & 0 deletions test/classes/Stubs/DbiDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3084,6 +3084,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 4bdf519

Please sign in to comment.