Skip to content

Commit

Permalink
Merge branch '3.9.x' into 4.1.x
Browse files Browse the repository at this point in the history
* 3.9.x:
  Simplify signature of fetchTableOptionsByTable
  Add MariaDb1010Platform for fetchTableOptionsByTable
  • Loading branch information
derrabus committed Jun 19, 2024
2 parents 31fc090 + 955ec99 commit df2fc59
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 30 deletions.
5 changes: 3 additions & 2 deletions docs/en/reference/platforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ MariaDB
^^^^^

- ``MariaDBPlatform`` for version 10.4.3 and above.
- ``MariaDb1052Platform`` for version 10.5.2 and above.
- ``MariaDb1060Platform`` for version 10.6 and above.
- ``MariaDB1052Platform`` for version 10.5.2 and above.
- ``MariaDB1060Platform`` for version 10.6 and above.
- ``MariaDB1010Platform`` for version 10.10 and above.

Oracle
^^^^^^
Expand Down
5 changes: 5 additions & 0 deletions src/Driver/AbstractMySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion;
use Doctrine\DBAL\Platforms\MariaDB1010Platform;
use Doctrine\DBAL\Platforms\MariaDB1052Platform;
use Doctrine\DBAL\Platforms\MariaDB1060Platform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
Expand Down Expand Up @@ -37,6 +38,10 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): Abs
$version = $versionProvider->getServerVersion();
if (stripos($version, 'mariadb') !== false) {
$mariaDbVersion = $this->getMariaDbMysqlVersionNumber($version);
if (version_compare($mariaDbVersion, '10.10.0', '>=')) {
return new MariaDB1010Platform();
}

if (version_compare($mariaDbVersion, '10.6.0', '>=')) {
return new MariaDB1060Platform();
}
Expand Down
26 changes: 26 additions & 0 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -839,4 +839,30 @@ private function indexAssetsByLowerCaseName(array $assets): array

return $result;
}

public function fetchTableOptionsByTable(bool $includeTableName): string
{
$sql = <<<'SQL'
SELECT t.TABLE_NAME,
t.ENGINE,
t.AUTO_INCREMENT,
t.TABLE_COMMENT,
t.CREATE_OPTIONS,
t.TABLE_COLLATION,
ccsa.CHARACTER_SET_NAME
FROM information_schema.TABLES t
INNER JOIN information_schema.COLLATION_CHARACTER_SET_APPLICABILITY ccsa
ON ccsa.COLLATION_NAME = t.TABLE_COLLATION
SQL;

$conditions = ['t.TABLE_SCHEMA = ?'];

if ($includeTableName) {
$conditions[] = 't.TABLE_NAME = ?';
}

$conditions[] = "t.TABLE_TYPE = 'BASE TABLE'";

return $sql . ' WHERE ' . implode(' AND ', $conditions);
}
}
49 changes: 49 additions & 0 deletions src/Platforms/MariaDB1010Platform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Platforms;

use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;

use function implode;

/**
* Provides the behavior, features and SQL dialect of the MariaDB 10.10 database platform.
*/
class MariaDB1010Platform extends MariaDB1060Platform
{
public function createSelectSQLBuilder(): SelectSQLBuilder
{
return AbstractPlatform::createSelectSQLBuilder();
}

public function fetchTableOptionsByTable(bool $includeTableName): string
{
// MariaDB-10.10.1 added FULL_COLLATION_NAME to the information_schema.COLLATION_CHARACTER_SET_APPLICABILITY.
// A base collation like uca1400_ai_ci can refer to multiple character sets. The value in the
// information_schema.TABLES.TABLE_COLLATION corresponds to the full collation name.
$sql = <<<'SQL'
SELECT t.TABLE_NAME,
t.ENGINE,
t.AUTO_INCREMENT,
t.TABLE_COMMENT,
t.CREATE_OPTIONS,
t.TABLE_COLLATION,
ccsa.CHARACTER_SET_NAME
FROM information_schema.TABLES t
INNER JOIN information_schema.COLLATION_CHARACTER_SET_APPLICABILITY ccsa
ON ccsa.FULL_COLLATION_NAME = t.TABLE_COLLATION
SQL;

$conditions = ['t.TABLE_SCHEMA = ?'];

if ($includeTableName) {
$conditions[] = 't.TABLE_NAME = ?';
}

$conditions[] = "t.TABLE_TYPE = 'BASE TABLE'";

return $sql . ' WHERE ' . implode(' AND ', $conditions);
}
}
30 changes: 3 additions & 27 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,37 +460,13 @@ protected function selectForeignKeyColumns(string $databaseName, ?string $tableN
*/
protected function fetchTableOptionsByTable(string $databaseName, ?string $tableName = null): array
{
// MariaDB-10.10.1 added FULL_COLLATION_NAME to the information_schema.COLLATION_CHARACTER_SET_APPLICABILITY.
// A base collation like uca1400_ai_ci can refer to multiple character sets. The value in the
// information_schema.TABLES.TABLE_COLLATION corresponds to the full collation name.
// The MariaDB executable comment syntax with version, /*M!101001, is exclusively executed on
// MariaDB-10.10.1+ servers for backwards compatibility, and compatiblity to MySQL servers.
$sql = <<<'SQL'
SELECT t.TABLE_NAME,
t.ENGINE,
t.AUTO_INCREMENT,
t.TABLE_COMMENT,
t.CREATE_OPTIONS,
t.TABLE_COLLATION,
ccsa.CHARACTER_SET_NAME
FROM information_schema.TABLES t
INNER JOIN information_schema.COLLATION_CHARACTER_SET_APPLICABILITY ccsa
ON /*M!101001 ccsa.FULL_COLLATION_NAME = t.TABLE_COLLATION OR */
ccsa.COLLATION_NAME = t.TABLE_COLLATION
SQL;

$conditions = ['t.TABLE_SCHEMA = ?'];
$params = [$databaseName];
$sql = $this->platform->fetchTableOptionsByTable($tableName !== null);

$params = [$databaseName];
if ($tableName !== null) {
$conditions[] = 't.TABLE_NAME = ?';
$params[] = $tableName;
$params[] = $tableName;
}

$conditions[] = "t.TABLE_TYPE = 'BASE TABLE'";

$sql .= ' WHERE ' . implode(' AND ', $conditions);

/** @var array<string,array<string,mixed>> $metadata */
$metadata = $this->connection->executeQuery($sql, $params)
->fetchAllAssociativeIndexed();
Expand Down
3 changes: 2 additions & 1 deletion tests/Driver/VersionAwarePlatformDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Connection\StaticServerVersionProvider;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MariaDB1010Platform;
use Doctrine\DBAL\Platforms\MariaDB1052Platform;
use Doctrine\DBAL\Platforms\MariaDB1060Platform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
Expand Down Expand Up @@ -44,7 +45,7 @@ public static function mySQLVersionProvider(): array
['10.2.8-MariaDB-1~lenny-log', MariaDBPlatform::class],
['10.5.2-MariaDB-1~lenny-log', MariaDB1052Platform::class],
['10.6.0-MariaDB-1~lenny-log', MariaDB1060Platform::class],
['11.0.2-MariaDB-1:11.0.2+maria~ubu2204', MariaDB1060Platform::class],
['11.0.2-MariaDB-1:11.0.2+maria~ubu2204', MariaDB1010Platform::class],
];
}

Expand Down

0 comments on commit df2fc59

Please sign in to comment.