From d7fb61bd874f53b66ff0a0f8daa7ace22e310aaa Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Sun, 1 Nov 2020 23:22:31 +0100 Subject: [PATCH] LockMode::NONE should not set WITH (NOLOCK) This fixes the issue detailed in #4391, with SQL Server and SQL Anywhere setting WITH (NOLOCK) for LockMode::NONE, which effectively means using a READ UNCOMMITTED isolation level at table level, which is not the contract of LockMode::NONE. --- lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php | 3 --- lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php | 3 --- .../DBAL/Platforms/AbstractSQLServerPlatformTestCase.php | 4 ++-- .../Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php | 2 +- .../Tests/DBAL/Platforms/SQLServer2012PlatformTest.php | 4 ++-- tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php | 2 +- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index f7921cbde48..b4f9a8ad57e 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -51,9 +51,6 @@ class SQLAnywherePlatform extends AbstractPlatform public function appendLockHint($fromClause, $lockMode) { switch (true) { - case $lockMode === LockMode::NONE: - return $fromClause . ' WITH (NOLOCK)'; - case $lockMode === LockMode::PESSIMISTIC_READ: return $fromClause . ' WITH (UPDLOCK)'; diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index b41f33bef46..42ec3f16e25 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1573,9 +1573,6 @@ public function getForeignKeyReferentialActionSQL($action) public function appendLockHint($fromClause, $lockMode) { switch (true) { - case $lockMode === LockMode::NONE: - return $fromClause . ' WITH (NOLOCK)'; - case $lockMode === LockMode::PESSIMISTIC_READ: return $fromClause . ' WITH (HOLDLOCK, ROWLOCK)'; diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 7a63f3ffccf..273e109beb9 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -374,14 +374,14 @@ public function testModifyLimitQueryWithOrderByClause(): void } $sql = 'SELECT m0_.NOMBRE AS NOMBRE0, m0_.FECHAINICIO AS FECHAINICIO1, m0_.FECHAFIN AS FECHAFIN2' - . ' FROM MEDICION m0_ WITH (NOLOCK)' + . ' FROM MEDICION m0_' . ' INNER JOIN ESTUDIO e1_ ON m0_.ESTUDIO_ID = e1_.ID' . ' INNER JOIN CLIENTE c2_ ON e1_.CLIENTE_ID = c2_.ID' . ' INNER JOIN USUARIO u3_ ON c2_.ID = u3_.CLIENTE_ID' . ' WHERE u3_.ID = ? ORDER BY m0_.FECHAINICIO DESC'; $alteredSql = 'SELECT TOP 15 m0_.NOMBRE AS NOMBRE0, m0_.FECHAINICIO AS FECHAINICIO1, m0_.FECHAFIN AS FECHAFIN2' - . ' FROM MEDICION m0_ WITH (NOLOCK)' + . ' FROM MEDICION m0_' . ' INNER JOIN ESTUDIO e1_ ON m0_.ESTUDIO_ID = e1_.ID' . ' INNER JOIN CLIENTE c2_ ON e1_.CLIENTE_ID = c2_.ID' . ' INNER JOIN USUARIO u3_ ON c2_.ID = u3_.CLIENTE_ID' diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 5f3bd50e2ac..119b87bc3f9 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -266,7 +266,7 @@ public static function getLockHints(): iterable [null, ''], [false, ''], [true, ''], - [LockMode::NONE, ' WITH (NOLOCK)'], + [LockMode::NONE, ''], [LockMode::OPTIMISTIC, ''], [LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'], [LockMode::PESSIMISTIC_WRITE, ' WITH (XLOCK)'], diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php index 1c21098b678..d4f8220e9df 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php @@ -224,14 +224,14 @@ public function testModifyLimitQueryWithExtraLongQuery(): void public function testModifyLimitQueryWithOrderByClause(): void { $sql = 'SELECT m0_.NOMBRE AS NOMBRE0, m0_.FECHAINICIO AS FECHAINICIO1, m0_.FECHAFIN AS FECHAFIN2' - . ' FROM MEDICION m0_ WITH (NOLOCK)' + . ' FROM MEDICION m0_' . ' INNER JOIN ESTUDIO e1_ ON m0_.ESTUDIO_ID = e1_.ID' . ' INNER JOIN CLIENTE c2_ ON e1_.CLIENTE_ID = c2_.ID' . ' INNER JOIN USUARIO u3_ ON c2_.ID = u3_.CLIENTE_ID' . ' WHERE u3_.ID = ? ORDER BY m0_.FECHAINICIO DESC'; $expected = 'SELECT m0_.NOMBRE AS NOMBRE0, m0_.FECHAINICIO AS FECHAINICIO1, m0_.FECHAFIN AS FECHAFIN2' - . ' FROM MEDICION m0_ WITH (NOLOCK)' + . ' FROM MEDICION m0_' . ' INNER JOIN ESTUDIO e1_ ON m0_.ESTUDIO_ID = e1_.ID' . ' INNER JOIN CLIENTE c2_ ON e1_.CLIENTE_ID = c2_.ID' . ' INNER JOIN USUARIO u3_ ON c2_.ID = u3_.CLIENTE_ID' diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php index 2357c1a796b..08f2e4a5530 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php @@ -39,7 +39,7 @@ public static function getLockHints(): iterable { return [ [null, ''], - [LockMode::NONE, ' WITH (NOLOCK)'], + [LockMode::NONE, ''], [LockMode::OPTIMISTIC, ''], [LockMode::PESSIMISTIC_READ, ' WITH (HOLDLOCK, ROWLOCK)'], [LockMode::PESSIMISTIC_WRITE, ' WITH (UPDLOCK, ROWLOCK)'],