Improve collations support for MariaDB 10.10+ (#18760)
* 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>
This commit is contained in:
parent
270a40f7c0
commit
ef92f1f484
@ -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);
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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 */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user