Unverified Commit a490dec8 authored by Sergei Morozov's avatar Sergei Morozov

Merge pull request #3211 from morozov/issues/3167

Removed support for DB-generated UUIDs
parents 9c36d219 c4d088c8
# Upgrade to 3.0 # Upgrade to 3.0
## BC BREAK: Removed support for DB-generated UUIDs
The support for DB-generated UUIDs was removed as non-portable.
Please generate UUIDs on the application side (e.g. using [ramsey/uuid](https://packagist.org/packages/ramsey/uuid)).
## BC BREAK: Removed MsSQLKeywords class ## BC BREAK: Removed MsSQLKeywords class
The `Doctrine\DBAL\Platforms\MsSQLKeywords` has been removed. The `Doctrine\DBAL\Platforms\MsSQLKeywords` has been removed.
......
...@@ -622,20 +622,6 @@ abstract class AbstractPlatform ...@@ -622,20 +622,6 @@ abstract class AbstractPlatform
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
} }
/**
* Returns the global unique identifier expression.
*
* @deprecated Use application-generated UUIDs instead
*
* @return string
*
* @throws DBALException If not supported on this platform.
*/
public function getGuidExpression()
{
throw DBALException::notSupported(__METHOD__);
}
/** /**
* Returns the SQL snippet to get the average value of a column. * Returns the SQL snippet to get the average value of a column.
* *
......
...@@ -78,16 +78,6 @@ class MySqlPlatform extends AbstractPlatform ...@@ -78,16 +78,6 @@ class MySqlPlatform extends AbstractPlatform
return 'RLIKE'; return 'RLIKE';
} }
/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
return 'UUID()';
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -84,16 +84,6 @@ class OraclePlatform extends AbstractPlatform ...@@ -84,16 +84,6 @@ class OraclePlatform extends AbstractPlatform
return 'INSTR(' . $str . ', ' . $substr . ', ' . $startPos . ')'; return 'INSTR(' . $str . ', ' . $substr . ', ' . $startPos . ')';
} }
/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
return 'SYS_GUID()';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -1021,16 +1021,6 @@ SQL ...@@ -1021,16 +1021,6 @@ SQL
return 'TIME(0) WITHOUT TIME ZONE'; return 'TIME(0) WITHOUT TIME ZONE';
} }
/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
return 'UUID_GENERATE_V4()';
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -667,16 +667,6 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -667,16 +667,6 @@ class SQLAnywherePlatform extends AbstractPlatform
return ''; return '';
} }
/**
* {@inheritdoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
return 'NEWID()';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -1012,16 +1012,6 @@ SQL ...@@ -1012,16 +1012,6 @@ SQL
return 'DROP VIEW ' . $name; return 'DROP VIEW ' . $name;
} }
/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
return 'NEWID()';
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -41,19 +41,6 @@ class SqlitePlatform extends AbstractPlatform ...@@ -41,19 +41,6 @@ class SqlitePlatform extends AbstractPlatform
return 'REGEXP'; return 'REGEXP';
} }
/**
* {@inheritDoc}
*
* @deprecated Use application-generated UUIDs instead
*/
public function getGuidExpression()
{
return "HEX(RANDOMBLOB(4)) || '-' || HEX(RANDOMBLOB(2)) || '-4' || "
. "SUBSTR(HEX(RANDOMBLOB(2)), 2) || '-' || "
. "SUBSTR('89AB', 1 + (ABS(RANDOM()) % 4), 1) || "
. "SUBSTR(HEX(RANDOMBLOB(2)), 2) || '-' || HEX(RANDOMBLOB(6))";
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
<?php
namespace Doctrine\Tests\DBAL\Functional\Ticket;
use Doctrine\Tests\DbalFunctionalTestCase;
use function in_array;
use function preg_match;
/**
* @group DBAL-421
*/
class DBAL421Test extends DbalFunctionalTestCase
{
protected function setUp() : void
{
parent::setUp();
$platform = $this->connection->getDatabasePlatform()->getName();
if (in_array($platform, ['mysql', 'sqlite'])) {
return;
}
$this->markTestSkipped('Currently restricted to MySQL and SQLite.');
}
public function testGuidShouldMatchPattern() : void
{
$guid = $this->connection->query($this->getSelectGuidSql())->fetchColumn();
$pattern = '/[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[8-9A-B][0-9A-F]{3}\-[0-9A-F]{12}/i';
self::assertEquals(1, preg_match($pattern, $guid), 'GUID does not match pattern');
}
/**
* This test does (of course) not proof that all generated GUIDs are
* random, it should however provide some basic confidence.
*/
public function testGuidShouldBeRandom() : void
{
$statement = $this->connection->prepare($this->getSelectGuidSql());
$guids = [];
for ($i = 0; $i < 99; $i++) {
$statement->execute();
$guid = $statement->fetchColumn();
self::assertNotContains($guid, $guids, 'Duplicate GUID detected');
$guids[] = $guid;
}
$statement->closeCursor();
}
private function getSelectGuidSql() : string
{
return 'SELECT ' . $this->connection->getDatabasePlatform()->getGuidExpression();
}
}
...@@ -667,7 +667,6 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase ...@@ -667,7 +667,6 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
self::assertEquals('Y-m-d H:i:s.u', $this->platform->getDateTimeFormatString()); self::assertEquals('Y-m-d H:i:s.u', $this->platform->getDateTimeFormatString());
self::assertEquals('H:i:s.u', $this->platform->getTimeFormatString()); self::assertEquals('H:i:s.u', $this->platform->getTimeFormatString());
self::assertEquals('', $this->platform->getForUpdateSQL()); self::assertEquals('', $this->platform->getForUpdateSQL());
self::assertEquals('NEWID()', $this->platform->getGuidExpression());
self::assertEquals('LOCATE(string_column, substring_column)', $this->platform->getLocateExpression('string_column', 'substring_column')); self::assertEquals('LOCATE(string_column, substring_column)', $this->platform->getLocateExpression('string_column', 'substring_column'));
self::assertEquals('LOCATE(string_column, substring_column, 1)', $this->platform->getLocateExpression('string_column', 'substring_column', 1)); self::assertEquals('LOCATE(string_column, substring_column, 1)', $this->platform->getLocateExpression('string_column', 'substring_column', 1));
self::assertEquals("HASH(column, 'MD5')", $this->platform->getMd5Expression('column')); self::assertEquals("HASH(column, 'MD5')", $this->platform->getMd5Expression('column'));
......
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