From 5322a4d742ef7d3870a4c04ce0369a0ece0a8396 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Jan 2020 00:48:44 -0800 Subject: [PATCH] Dropped handling of one-based numeric arrays of parameters in Statement::execute() --- UPGRADE.md | 4 ++ .../DBAL/Driver/OCI8/OCI8Statement.php | 4 +- .../DBAL/Driver/SQLSrv/SQLSrvStatement.php | 4 +- lib/Doctrine/DBAL/Driver/Statement.php | 2 +- .../DBAL/Driver/OCI8/OCI8StatementTest.php | 66 ------------------- 5 files changed, 7 insertions(+), 73 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index f34f3ddca77..11af4242c55 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 3.0 +## BC BREAK: Dropped handling of one-based numeric arrays of parameters in `Statement::execute()` + +The statement implementations no longer detect whether `$params` is a zero- or one-based array. A zero-based numeric array is expected. + ## BC BREAK: PingableConnection and ServerInfoAwareConnection interfaces now extends Connection All implementations of the `PingableConnection` and `ServerInfoAwareConnection` interfaces have to implement the methods defined in the `Connection` interface as well. diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index 17e464d9c1e..121579915e9 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -351,10 +351,8 @@ public function columnCount() : int public function execute(?array $params = null) : void { if ($params) { - $hasZeroIndex = array_key_exists(0, $params); - foreach ($params as $key => $val) { - if ($hasZeroIndex && is_int($key)) { + if (is_int($key)) { $param = $key + 1; } else { $param = $key; diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index a14067dd177..2dc8486ff5b 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -204,10 +204,8 @@ public function columnCount() : int public function execute(?array $params = null) : void { if ($params) { - $hasZeroIndex = array_key_exists(0, $params); - foreach ($params as $key => $val) { - if ($hasZeroIndex && is_int($key)) { + if (is_int($key)) { $this->bindValue($key + 1, $val); } else { $this->bindValue($key, $val); diff --git a/lib/Doctrine/DBAL/Driver/Statement.php b/lib/Doctrine/DBAL/Driver/Statement.php index 8d2fe2530d0..711e1e453b4 100644 --- a/lib/Doctrine/DBAL/Driver/Statement.php +++ b/lib/Doctrine/DBAL/Driver/Statement.php @@ -68,7 +68,7 @@ public function bindParam($param, &$variable, int $type = ParameterType::STRING, * if any, of their associated parameter markers or pass an array of input-only * parameter values. * - * @param mixed[]|null $params An array of values with as many elements as there are + * @param mixed[]|null $params A numeric array of values with as many elements as there are * bound parameters in the SQL statement being executed. * * @throws DriverException diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php index 846122b40db..b8ff5cca18a 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php @@ -25,72 +25,6 @@ protected function setUp() : void parent::setUp(); } - /** - * This scenario shows that when the first parameter is not null - * it properly sets $hasZeroIndex to 1 and calls bindValue starting at 1. - * - * This also verifies that the statement will check with the connection to - * see what the current execution mode is. - * - * The expected exception is due to oci_execute failing due to no valid connection. - * - * @param mixed[] $params - * - * @dataProvider executeDataProvider - */ - public function testExecute(array $params) : void - { - /** @var OCI8Statement|MockObject $statement */ - $statement = $this->getMockBuilder(OCI8Statement::class) - ->onlyMethods(['bindValue']) - ->disableOriginalConstructor() - ->getMock(); - - foreach ($params as $index => $value) { - $statement->expects($this->at($index)) - ->method('bindValue') - ->with( - $this->equalTo($index + 1), - $this->equalTo($value) - ); - } - - // can't pass to constructor since we don't have a real database handle, - // but execute must check the connection for the executeMode - $conn = $this->createMock(OCI8Connection::class); - $conn->expects($this->once()) - ->method('getExecuteMode') - ->willReturn(OCI_NO_AUTO_COMMIT); - - $connectionReflection = new ReflectionProperty($statement, '_conn'); - $connectionReflection->setAccessible(true); - $connectionReflection->setValue($statement, $conn); - - $handleReflection = new ReflectionProperty($statement, '_sth'); - $handleReflection->setAccessible(true); - $handleReflection->setValue($statement, fopen('php://temp', 'r')); - - $this->expectException(OCI8Exception::class); - $statement->execute($params); - } - - /** - * @return array> - */ - public static function executeDataProvider() : iterable - { - return [ - // $hasZeroIndex = isset($params[0]); == true - [ - [0 => 'test', 1 => null, 2 => 'value'], - ], - // $hasZeroIndex = isset($params[0]); == false - [ - [0 => null, 1 => 'test', 2 => 'value'], - ], - ]; - } - /** * @dataProvider nonTerminatedLiteralProvider */