Unverified Commit 4ddc496d authored by belgattitude's avatar belgattitude Committed by Luís Cobucci

Fixes from @lcobucci review

parent d4c2be87
...@@ -39,6 +39,10 @@ use Doctrine\DBAL\VersionAwarePlatformDriver; ...@@ -39,6 +39,10 @@ use Doctrine\DBAL\VersionAwarePlatformDriver;
*/ */
abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
{ {
private const MYSQL_MARIADB_VERSION_REGEXP = '/^(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/';
private const MYSQL_ORACLE_VERSION_REGEXP = '/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/';
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
...@@ -130,18 +134,16 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -130,18 +134,16 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
* @return AbstractPlatform|MariaDb102Platform|MySQL57Platform|MySqlPlatform * @return AbstractPlatform|MariaDb102Platform|MySQL57Platform|MySqlPlatform
* @throws DBALException * @throws DBALException
*/ */
public function createDatabasePlatformForVersion($version) : AbstractPlatform public function createDatabasePlatformForVersion($version)
{ {
if (false !== stripos($version, 'mariadb')) { if (false !== stripos($version, 'mariadb')
$versionNumber = $this->getMariaDbMysqlVersionNumber($version); && version_compare($this->getMariaDbMysqlVersionNumber($version), '10.2.7', '>=')) {
if (version_compare($versionNumber, '10.2.7', '>=')) { return new MariaDb102Platform();
return new MariaDb102Platform(); }
}
} else { if (false === stripos($version, 'mariadb')
$versionNumber = $this->getOracleMysqlVersionNumber($version); && version_compare($this->getOracleMysqlVersionNumber($version), '5.7.9', '>=')) {
if (version_compare($versionNumber, '5.7.9', '>=')) { return new MySQL57Platform();
return new MySQL57Platform();
}
} }
return $this->getDatabasePlatform(); return $this->getDatabasePlatform();
...@@ -156,7 +158,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -156,7 +158,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
*/ */
private function getOracleMysqlVersionNumber(string $versionString) : string private function getOracleMysqlVersionNumber(string $versionString) : string
{ {
if (!preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $versionString, $versionParts)) { if (!preg_match(self::MYSQL_ORACLE_VERSION_REGEXP, $versionString, $versionParts)) {
throw DBALException::invalidPlatformVersionSpecified( throw DBALException::invalidPlatformVersionSpecified(
$versionString, $versionString,
'<major_version>.<minor_version>.<patch_version>' '<major_version>.<minor_version>.<patch_version>'
...@@ -184,7 +186,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, ...@@ -184,7 +186,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
{ {
$version = str_replace('5.5.5-', '', $versionString); $version = str_replace('5.5.5-', '', $versionString);
if (!preg_match('/^(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/', strtolower($version), $versionParts)) { if (!preg_match(self::MYSQL_MARIADB_VERSION_REGEXP, strtolower($version), $versionParts)) {
throw DBALException::invalidPlatformVersionSpecified( throw DBALException::invalidPlatformVersionSpecified(
$version, $version,
'(mariadb-)?<major_version>.<minor_version>.<patch_version>' '(mariadb-)?<major_version>.<minor_version>.<patch_version>'
......
...@@ -227,24 +227,26 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -227,24 +227,26 @@ class MySqlSchemaManager extends AbstractSchemaManager
* @param null|string $columnDefault default value as stored in information_schema for MariaDB >= 10.2.7 * @param null|string $columnDefault default value as stored in information_schema for MariaDB >= 10.2.7
*/ */
private function getMariaDb1027ColumnDefault(MariaDb102Platform $platform, ?string $columnDefault) : ?string { private function getMariaDb1027ColumnDefault(MariaDb102Platform $platform, ?string $columnDefault) : ?string {
if ($columnDefault === 'NULL' || $columnDefault === null) { if ($columnDefault === 'NULL' || $columnDefault === null) {
$defaultValue = null; return null;
} elseif (strpos($columnDefault, "'") === 0) { }
$defaultValue = stripslashes( if (strpos($columnDefault, "'") === 0) {
return stripslashes(
str_replace("''", "'", str_replace("''", "'",
preg_replace('/^\'(.*)\'$/', '$1', $columnDefault) preg_replace('/^\'(.*)\'$/', '$1', $columnDefault)
) )
); );
} elseif ($columnDefault === 'current_timestamp()') {
$defaultValue = $platform->getCurrentTimestampSQL();
} elseif ($columnDefault === 'curdate()') {
$defaultValue = $platform->getCurrentDateSQL();
} elseif ($columnDefault === 'curtime()') {
$defaultValue = $platform->getCurrentTimeSQL();
} else {
$defaultValue = $columnDefault;
} }
return $defaultValue; switch($columnDefault) {
case 'current_timestamp()':
return $platform->getCurrentTimestampSQL();
case 'curdate()':
return $platform->getCurrentDateSQL();
case 'curtime()':
return $platform->getCurrentTimeSQL();
}
return $columnDefault;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment