Skip to content

Commit 5bff8ec

Browse files
committed
Dropped handling of one-based numeric arrays of parameters in Statement::execute()
1 parent 2e54e78 commit 5bff8ec

File tree

5 files changed

+7
-78
lines changed

5 files changed

+7
-78
lines changed

UPGRADE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Upgrade to 3.0
22

3+
## BC BREAK: Dropped handling of one-based numeric arrays of parameters in `Statement::execute()`
4+
5+
The statement implementations no longer detect whether `$params` is a zero- or one-based array. A zero-based numeric array is expected.
6+
37
## BC BREAK: `ServerInfoAwareConnection::requiresQueryForServerVersion()` is removed.
48

59
The `ServerInfoAwareConnection::requiresQueryForServerVersion()` method has been removed as an implementation detail which is the same for almost all supported drivers.

lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,8 @@ public function columnCount() : int
351351
public function execute(?array $params = null) : void
352352
{
353353
if ($params) {
354-
$hasZeroIndex = array_key_exists(0, $params);
355-
356354
foreach ($params as $key => $val) {
357-
if ($hasZeroIndex && is_int($key)) {
355+
if (is_int($key)) {
358356
$param = $key + 1;
359357
} else {
360358
$param = $key;

lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,8 @@ public function columnCount() : int
204204
public function execute(?array $params = null) : void
205205
{
206206
if ($params) {
207-
$hasZeroIndex = array_key_exists(0, $params);
208-
209207
foreach ($params as $key => $val) {
210-
if ($hasZeroIndex && is_int($key)) {
208+
if (is_int($key)) {
211209
$this->bindValue($key + 1, $val);
212210
} else {
213211
$this->bindValue($key, $val);

lib/Doctrine/DBAL/Driver/Statement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function bindParam($param, &$variable, int $type = ParameterType::STRING,
6868
* if any, of their associated parameter markers or pass an array of input-only
6969
* parameter values.
7070
*
71-
* @param mixed[]|null $params An array of values with as many elements as there are
71+
* @param mixed[]|null $params A numeric array of values with as many elements as there are
7272
* bound parameters in the SQL statement being executed.
7373
*
7474
* @throws DriverException

tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44

55
namespace Doctrine\Tests\DBAL\Driver\OCI8;
66

7-
use Doctrine\DBAL\Driver\OCI8\OCI8Connection;
87
use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
98
use Doctrine\DBAL\Driver\OCI8\OCI8Statement;
109
use Doctrine\Tests\DbalTestCase;
11-
use PHPUnit\Framework\MockObject\MockObject;
12-
use ReflectionProperty;
13-
use const OCI_NO_AUTO_COMMIT;
1410
use function extension_loaded;
15-
use function fopen;
1611

1712
class OCI8StatementTest extends DbalTestCase
1813
{
@@ -25,72 +20,6 @@ protected function setUp() : void
2520
parent::setUp();
2621
}
2722

28-
/**
29-
* This scenario shows that when the first parameter is not null
30-
* it properly sets $hasZeroIndex to 1 and calls bindValue starting at 1.
31-
*
32-
* This also verifies that the statement will check with the connection to
33-
* see what the current execution mode is.
34-
*
35-
* The expected exception is due to oci_execute failing due to no valid connection.
36-
*
37-
* @param mixed[] $params
38-
*
39-
* @dataProvider executeDataProvider
40-
*/
41-
public function testExecute(array $params) : void
42-
{
43-
/** @var OCI8Statement|MockObject $statement */
44-
$statement = $this->getMockBuilder(OCI8Statement::class)
45-
->onlyMethods(['bindValue'])
46-
->disableOriginalConstructor()
47-
->getMock();
48-
49-
foreach ($params as $index => $value) {
50-
$statement->expects($this->at($index))
51-
->method('bindValue')
52-
->with(
53-
$this->equalTo($index + 1),
54-
$this->equalTo($value)
55-
);
56-
}
57-
58-
// can't pass to constructor since we don't have a real database handle,
59-
// but execute must check the connection for the executeMode
60-
$conn = $this->createMock(OCI8Connection::class);
61-
$conn->expects($this->once())
62-
->method('getExecuteMode')
63-
->willReturn(OCI_NO_AUTO_COMMIT);
64-
65-
$connectionReflection = new ReflectionProperty($statement, '_conn');
66-
$connectionReflection->setAccessible(true);
67-
$connectionReflection->setValue($statement, $conn);
68-
69-
$handleReflection = new ReflectionProperty($statement, '_sth');
70-
$handleReflection->setAccessible(true);
71-
$handleReflection->setValue($statement, fopen('php://temp', 'r'));
72-
73-
$this->expectException(OCI8Exception::class);
74-
$statement->execute($params);
75-
}
76-
77-
/**
78-
* @return array<int, array<int, mixed>>
79-
*/
80-
public static function executeDataProvider() : iterable
81-
{
82-
return [
83-
// $hasZeroIndex = isset($params[0]); == true
84-
[
85-
[0 => 'test', 1 => null, 2 => 'value'],
86-
],
87-
// $hasZeroIndex = isset($params[0]); == false
88-
[
89-
[0 => null, 1 => 'test', 2 => 'value'],
90-
],
91-
];
92-
}
93-
9423
/**
9524
* @dataProvider nonTerminatedLiteralProvider
9625
*/

0 commit comments

Comments
 (0)