Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MariaDb1010Platform for fetchTableOptionsByTable #6434

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en/reference/platforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ MariaDB
- ``MariaDb1043Platform`` for version 10.4.3 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 @@ -8,6 +8,7 @@
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MariaDb1010Platform;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MariaDb1043Platform;
use Doctrine\DBAL\Platforms\MariaDb1052Platform;
Expand Down Expand Up @@ -41,6 +42,10 @@ public function createDatabasePlatformForVersion($version)

if ($mariadb) {
$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 @@ -1468,4 +1468,30 @@

return $result;
}

public function fetchTableOptionsByTable(bool $includeTableName): string

Check warning on line 1472 in src/Platforms/AbstractMySQLPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/AbstractMySQLPlatform.php#L1472

Added line #L1472 was not covered by tests
{
$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 = ?'];

Check warning on line 1487 in src/Platforms/AbstractMySQLPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/AbstractMySQLPlatform.php#L1487

Added line #L1487 was not covered by tests

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

Check warning on line 1490 in src/Platforms/AbstractMySQLPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/AbstractMySQLPlatform.php#L1489-L1490

Added lines #L1489 - L1490 were not covered by tests
}

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

Check warning on line 1493 in src/Platforms/AbstractMySQLPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/AbstractMySQLPlatform.php#L1493

Added line #L1493 was not covered by tests

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

Check warning on line 1495 in src/Platforms/AbstractMySQLPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/AbstractMySQLPlatform.php#L1495

Added line #L1495 was not covered by tests
}
}
47 changes: 47 additions & 0 deletions src/Platforms/MariaDb1010Platform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

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

Check warning on line 14 in src/Platforms/MariaDb1010Platform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/MariaDb1010Platform.php#L14

Added line #L14 was not covered by tests
{
return AbstractPlatform::createSelectSQLBuilder();

Check warning on line 16 in src/Platforms/MariaDb1010Platform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/MariaDb1010Platform.php#L16

Added line #L16 was not covered by tests
}

public function fetchTableOptionsByTable(bool $includeTableName): string

Check warning on line 19 in src/Platforms/MariaDb1010Platform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/MariaDb1010Platform.php#L19

Added line #L19 was not covered by tests
{
// 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 = ?'];

Check warning on line 37 in src/Platforms/MariaDb1010Platform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/MariaDb1010Platform.php#L37

Added line #L37 was not covered by tests

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

Check warning on line 40 in src/Platforms/MariaDb1010Platform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/MariaDb1010Platform.php#L39-L40

Added lines #L39 - L40 were not covered by tests
}

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

Check warning on line 43 in src/Platforms/MariaDb1010Platform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/MariaDb1010Platform.php#L43

Added line #L43 was not covered by tests

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

Check warning on line 45 in src/Platforms/MariaDb1010Platform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/MariaDb1010Platform.php#L45

Added line #L45 was not covered by tests
}
}
30 changes: 3 additions & 27 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,37 +557,13 @@
*/
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);

Check warning on line 560 in src/Schema/MySQLSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/MySQLSchemaManager.php#L560

Added line #L560 was not covered by tests

$params = [$databaseName];

Check warning on line 562 in src/Schema/MySQLSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/MySQLSchemaManager.php#L562

Added line #L562 was not covered by tests
if ($tableName !== null) {
$conditions[] = 't.TABLE_NAME = ?';
$params[] = $tableName;
$params[] = $tableName;

Check warning on line 564 in src/Schema/MySQLSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/MySQLSchemaManager.php#L564

Added line #L564 was not covered by tests
}

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

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

/** @var array<string,array<string,mixed>> $metadata */
$metadata = $this->_conn->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 @@ -8,6 +8,7 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2111Platform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Platforms\MariaDb1010Platform;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MariaDb1052Platform;
use Doctrine\DBAL\Platforms\MariaDb1060Platform;
Expand Down Expand Up @@ -65,7 +66,7 @@ public static function mySQLVersionProvider(): array
['10.5.2-MariaDB-1~lenny-log', MariaDB1052Platform::class],
['mariadb-10.6.0', MariaDb1060Platform::class],
['mariadb-10.9.3', 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
3 changes: 2 additions & 1 deletion tests/Functional/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Platforms\MariaDb1010Platform;
use Doctrine\DBAL\Platforms\MariaDb1060Platform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQL80Platform;
Expand Down Expand Up @@ -117,7 +118,7 @@ private function platformSupportsSkipLocked(): bool

if ($platform instanceof MySQLPlatform) {
if ($platform instanceof MariaDBPlatform) {
if (! $platform instanceof MariaDb1060Platform) {
if (! ($platform instanceof MariaDb1060Platform || $platform instanceof MariaDb1010Platform)) {
return false;
}
} elseif (! $platform instanceof MySQL80Platform) {
Expand Down
Loading