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

MariaDB 10.2 initial support #2825

Merged
merged 45 commits into from
Nov 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
baa454c
Updated mariadb 10.2 support
belgattitude Sep 26, 2017
1664051
Removed unused use statement
belgattitude Sep 26, 2017
1f9deec
Fixed $this->assert*
belgattitude Sep 26, 2017
4fff976
Test JSON default values and refactoring
belgattitude Sep 27, 2017
f5ca458
Removed debug comment
belgattitude Sep 27, 2017
d2ddd2f
Cleanup
belgattitude Sep 27, 2017
0a34a67
More tests for escaping
belgattitude Sep 27, 2017
f6cb853
Updated tests
belgattitude Sep 27, 2017
0d20c85
Added more tests for CURRENT_* defaults
belgattitude Sep 27, 2017
a4d3068
Minor cleanup
belgattitude Sep 27, 2017
c86b622
Fixed typings
belgattitude Oct 11, 2017
61bed75
Fixed strict assert for default int values
belgattitude Oct 11, 2017
2dda57a
Added final tests for default escaping
belgattitude Oct 11, 2017
d4c2be8
csfix: There must be a single space before the colon on return types
belgattitude Oct 11, 2017
4ddc496
Fixes from @lcobucci review
belgattitude Oct 11, 2017
6b9ead7
Review from @morozov about nulls
belgattitude Oct 12, 2017
2c2169e
@morozov review: According to MySqlPlatform::getListTableColumnsSQL()…
belgattitude Oct 13, 2017
e3bec40
morozov review, revert regexp constant introduced after lcobucci revi…
belgattitude Oct 13, 2017
065386d
morozov review: revert to MariaDb1027Platform name
belgattitude Oct 13, 2017
f81afb1
morozov removed type doc: AbstractPlatform cover everything
belgattitude Oct 13, 2017
5422bae
Majkl578 fix bc-break with return type
belgattitude Oct 13, 2017
4747fd0
Latest reviews fixes: morozov, Majkl578
belgattitude Oct 13, 2017
4f876ef
RegExp change from @Majkl578 suggestion
belgattitude Oct 15, 2017
d57f69e
Updated from @Majkl578 review
belgattitude Oct 15, 2017
d2543ca
Updated comment for mariadb null handling
belgattitude Oct 30, 2017
b075331
Removes introduced quoting literal support
belgattitude Oct 30, 2017
70924a8
Removed unused use statement
belgattitude Oct 30, 2017
4ee52db
Removed unused use statement
belgattitude Oct 30, 2017
36b98e2
CS fixes
belgattitude Oct 30, 2017
9ca9589
CS fixes
belgattitude Oct 30, 2017
345b650
Removes mariadb supports for TEXT/BLOB default values
belgattitude Oct 30, 2017
63348cc
CS-FIX
belgattitude Oct 30, 2017
335d58f
BC, removed return types on non-final classes
belgattitude Oct 31, 2017
2d14ac5
Revert untouched file
belgattitude Oct 31, 2017
afee87d
Revert untouched file
belgattitude Oct 31, 2017
a07f3d3
Removes backslash escaping (still present)
belgattitude Nov 1, 2017
b1937b0
minor phpdoc fix
belgattitude Nov 1, 2017
7f2cd3d
Fixed unused use statement
belgattitude Nov 1, 2017
45ea287
Unescaping re-added, support limited to schema introspection (#2850 w…
belgattitude Nov 15, 2017
e9c9932
Improves readability of escape sequences
belgattitude Nov 15, 2017
a04d804
Fixed CS
belgattitude Nov 17, 2017
6fa8549
Fixed CS
belgattitude Nov 18, 2017
52b4692
Disable native JSON support for MariaDB 10.2.x
lcobucci Nov 19, 2017
ea56fce
Simplify platform detection test
lcobucci Nov 19, 2017
628e846
Remove duplicated entry
lcobucci Nov 19, 2017
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
34 changes: 33 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ before_install:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"

before_script:
- if [[ "$DB" == "mysql" || "$DB" == "mysqli" || "$DB" == "mariadb" ]]; then mysql < tests/travis/create-mysql-schema.sql; fi;
- if [[ "$DB" == "mysql" || "$DB" == "mysqli" || "$DB" == *"mariadb"* ]]; then mysql < tests/travis/create-mysql-schema.sql; fi;

install:
- travis_retry composer -n install
Expand Down Expand Up @@ -103,6 +103,38 @@ jobs:
addons:
mariadb: 10.1

- stage: Test
php: 7.1
env: DB=mariadb MARIADB_VERSION=10.2
addons:
mariadb: 10.2
- stage: Test
php: 7.2
env: DB=mariadb MARIADB_VERSION=10.2
addons:
mariadb: 10.2
- stage: Test
php: nightly
env: DB=mariadb MARIADB_VERSION=10.2
addons:
mariadb: 10.2

- stage: Test
php: 7.1
env: DB=mariadb.mysqli MARIADB_VERSION=10.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sort of breaks the purpose of the $DB variable - it's DB + driver now. Maybe adding 2nd optional variable $DRIVER would be better in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, what name for the 2nd variable ?

`MARIADB_DRIVER' ?

Do you know where to set it as default (I assume not under env: MARIADB_DRIVER=mysql ? Not sure with travis jobs) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply $DRIVER would be enough. But I see there's already DB=mysqli which is not really a DB. Feel free to leave it as is it for now, we can handle this after this PR is merged. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I leave it like this then ;) @Majkl578 I'm about to drop some parts of this P/R, just detailed 3 questions in the last comment. Would be wonderful to have your advices on this.

addons:
mariadb: 10.2
- stage: Test
php: 7.2
env: DB=mariadb.mysqli MARIADB_VERSION=10.2
addons:
mariadb: 10.2
- stage: Test
php: nightly
env: DB=mariadb.mysqli MARIADB_VERSION=10.2
addons:
mariadb: 10.2

- stage: Test
php: 7.1
env: DB=pgsql POSTGRESQL_VERSION=9.2
Expand Down
68 changes: 55 additions & 13 deletions lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\MySqlSchemaManager;
Expand Down Expand Up @@ -123,35 +124,74 @@ public function convertException($message, DriverException $exception)

/**
* {@inheritdoc}
*
* @throws DBALException
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>'
);
$mariadb = false !== stripos($version, 'mariadb');
if ($mariadb && version_compare($this->getMariaDbMysqlVersionNumber($version), '10.2.7', '>=')) {
return new MariaDb1027Platform();
}

if (false !== stripos($version, 'mariadb')) {
return $this->getDatabasePlatform();
if ( ! $mariadb && version_compare($this->getOracleMysqlVersionNumber($version), '5.7.9', '>=')) {
return new MySQL57Platform();
}

return $this->getDatabasePlatform();
}

/**
* Get a normalized 'version number' from the server string
* returned by Oracle MySQL servers.
*
* @param string $versionString Version string returned by the driver, i.e. '5.7.10'
* @throws DBALException
*/
private function getOracleMysqlVersionNumber(string $versionString) : string
{
if ( ! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/',
$versionString,
$versionParts
)) {
throw DBALException::invalidPlatformVersionSpecified(
$versionString,
'<major_version>.<minor_version>.<patch_version>'
);
}
$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : null;
$minorVersion = $versionParts['minor'] ?? 0;
$patchVersion = $versionParts['patch'] ?? null;

if ('5' === $majorVersion && '7' === $minorVersion && null === $patchVersion) {
$patchVersion = '9';
}

$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
return $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
}

if (version_compare($version, '5.7.9', '>=')) {
return new MySQL57Platform();
/**
* Detect MariaDB server version, including hack for some mariadb distributions
* that starts with the prefix '5.5.5-'
*
* @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial'
* @throws DBALException
*/
private function getMariaDbMysqlVersionNumber(string $versionString) : string
{
if ( ! preg_match(
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
$versionString,
$versionParts
)) {
throw DBALException::invalidPlatformVersionSpecified(
$versionString,
'^(?:5\.5\.5-)?(mariadb-)?<major_version>.<minor_version>.<patch_version>'
);
}

return $this->getDatabasePlatform();
return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch'];
}

/**
Expand All @@ -170,6 +210,7 @@ public function getDatabase(\Doctrine\DBAL\Connection $conn)

/**
* {@inheritdoc}
* @return MySqlPlatform
*/
public function getDatabasePlatform()
{
Expand All @@ -178,6 +219,7 @@ public function getDatabasePlatform()

/**
* {@inheritdoc}
* @return MySqlSchemaManager
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
Expand Down
9 changes: 9 additions & 0 deletions lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,18 @@ public function getWrappedResourceHandle()

/**
* {@inheritdoc}
*
* The server version detection includes a special case for MariaDB
* to support '5.5.5-' prefixed versions introduced in Maria 10+
* @link https://jira.mariadb.org/browse/MDEV-4088
*/
public function getServerVersion()
{
$serverInfos = $this->_conn->get_server_info();
if (false !== stripos($serverInfos, 'mariadb')) {
return $serverInfos;
}

$majorVersion = floor($this->_conn->server_version / 10000);
$minorVersion = floor(($this->_conn->server_version - $majorVersion * 10000) / 100);
$patchVersion = floor($this->_conn->server_version - $majorVersion * 10000 - $minorVersion * 100);
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2287,19 +2287,19 @@ public function getDefaultValueDeclarationSQL($field)
$type = $field['type'];

if ($type instanceof Types\PhpIntegerMappingType) {
return " DEFAULT " . $default;
return ' DEFAULT ' . $default;
}

if ($type instanceof Types\PhpDateTimeMappingType && $default === $this->getCurrentTimestampSQL()) {
return " DEFAULT " . $this->getCurrentTimestampSQL();
return ' DEFAULT ' . $this->getCurrentTimestampSQL();
}

if ($type instanceof Types\TimeType && $default === $this->getCurrentTimeSQL()) {
return " DEFAULT " . $this->getCurrentTimeSQL();
return ' DEFAULT ' . $this->getCurrentTimeSQL();
}

if ($type instanceof Types\DateType && $default === $this->getCurrentDateSQL()) {
return " DEFAULT " . $this->getCurrentDateSQL();
return ' DEFAULT ' . $this->getCurrentDateSQL();
}

if ($type instanceof Types\BooleanType) {
Expand Down
Loading