From 403b27f3220c13dec81cb303300ca561c62cd972 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 3 Nov 2020 10:39:25 -0800 Subject: [PATCH] Remove support for colon prefix in statement parameters --- UPGRADE.md | 4 +++ src/SQLParserUtils.php | 5 --- .../Functional/Driver/OCI8/StatementTest.php | 2 +- tests/SQLParserUtilsTest.php | 34 +++++-------------- 4 files changed, 14 insertions(+), 31 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index b36f9270c69..842394fa2c3 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 3.0 +## BC BREAK: leading in named parameter names not supported + +The usage of the colon prefix when binding named parameters is no longer supported. + ## BC BREAK `Doctrine\DBAL\Abstraction\Result` removed The `Doctrine\DBAL\Abstraction\Result` interface is removed. Use the `Doctrine\DBAL\Result` class instead. diff --git a/src/SQLParserUtils.php b/src/SQLParserUtils.php index 4274a6c38e2..b3a6d5a5a10 100644 --- a/src/SQLParserUtils.php +++ b/src/SQLParserUtils.php @@ -269,11 +269,6 @@ private static function extractParam($paramName, $paramsOrTypes, $isParam, $defa return $paramsOrTypes[$paramName]; } - // Hash keys can be prefixed with a colon for compatibility - if (array_key_exists(':' . $paramName, $paramsOrTypes)) { - return $paramsOrTypes[':' . $paramName]; - } - if ($defaultValue !== null) { return $defaultValue; } diff --git a/tests/Functional/Driver/OCI8/StatementTest.php b/tests/Functional/Driver/OCI8/StatementTest.php index 6278beb756d..1659923030f 100644 --- a/tests/Functional/Driver/OCI8/StatementTest.php +++ b/tests/Functional/Driver/OCI8/StatementTest.php @@ -66,7 +66,7 @@ public static function queryConversionProvider(): iterable ], 'named' => [ 'SELECT :COL COL1 FROM DUAL', - [':COL' => 1], + ['COL' => 1], ['COL1' => 1], ], 'literal-with-placeholder' => [ diff --git a/tests/SQLParserUtilsTest.php b/tests/SQLParserUtilsTest.php index 1afe7572767..62ef990d4c4 100644 --- a/tests/SQLParserUtilsTest.php +++ b/tests/SQLParserUtilsTest.php @@ -474,42 +474,26 @@ public static function dataExpandListParameters(): iterable [1, 2, 'bar'], [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], ], - 'Params/types with colons' => [ + 'Named parameters and partially implicit types' => [ 'SELECT * FROM Foo WHERE foo = :foo OR bar = :bar', - [':foo' => 'foo', ':bar' => 'bar'], - [':foo' => ParameterType::INTEGER], + ['foo' => 'foo', 'bar' => 'bar'], + ['foo' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ? OR bar = ?', ['foo', 'bar'], [ParameterType::INTEGER, ParameterType::STRING], ], - [ + 'Named parameters and explicit types' => [ 'SELECT * FROM Foo WHERE foo = :foo OR bar = :bar', - [':foo' => 'foo', ':bar' => 'bar'], - [':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER], + ['foo' => 'foo', 'bar' => 'bar'], + ['foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ? OR bar = ?', ['foo', 'bar'], [ParameterType::INTEGER, ParameterType::INTEGER], ], - [ - 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar', - [':foo' => [1, 2], ':bar' => 'bar'], - ['foo' => Connection::PARAM_INT_ARRAY], - 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', - [1, 2, 'bar'], - [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], - ], - [ - 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar', - ['foo' => [1, 2], 'bar' => 'bar'], - [':foo' => Connection::PARAM_INT_ARRAY], - 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', - [1, 2, 'bar'], - [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], - ], 'Null valued parameters (DBAL-522)' => [ 'INSERT INTO Foo (foo, bar) values (:foo, :bar)', ['foo' => 1, 'bar' => null], - [':foo' => ParameterType::INTEGER, ':bar' => ParameterType::NULL], + ['foo' => ParameterType::INTEGER, 'bar' => ParameterType::NULL], 'INSERT INTO Foo (foo, bar) values (?, ?)', [1, null], [ParameterType::INTEGER, ParameterType::NULL], @@ -524,8 +508,8 @@ public static function dataExpandListParameters(): iterable ], 'Escaped single quotes SQL- and C-Style (DBAL-1205)' => [ "SELECT * FROM Foo WHERE foo = :foo||''':not_a_param''\\'' OR bar = ''':not_a_param''\\'':bar", - [':foo' => 1, ':bar' => 2], - [':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER], + ['foo' => 1, 'bar' => 2], + ['foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ?||\'\'\':not_a_param\'\'\\\'\' OR bar = \'\'\':not_a_param\'\'\\\'\'?', [1, 2], [ParameterType::INTEGER, ParameterType::INTEGER],