Skip to content

Commit a48cad1

Browse files
committed
Dropped handling of one-based numeric arrays of parameters in Statement::execute()
1 parent bfa733d commit a48cad1

File tree

5 files changed

+7
-79
lines changed

5 files changed

+7
-79
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 `Statement::project()` has been removed
48

59
- The `Statement::project()` method has been removed. Use `::executeQuery()` and fetch the data from the statement using one of the `Statement::fetch*()` methods instead.

src/Driver/OCI8/OCI8Statement.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Doctrine\DBAL\ParameterType;
1111
use InvalidArgumentException;
1212
use IteratorAggregate;
13-
use function array_key_exists;
1413
use function assert;
1514
use function count;
1615
use function implode;
@@ -362,9 +361,8 @@ public function columnCount()
362361
public function execute($params = null)
363362
{
364363
if ($params !== null) {
365-
$hasZeroIndex = array_key_exists(0, $params);
366364
foreach ($params as $key => $val) {
367-
if ($hasZeroIndex && is_int($key)) {
365+
if (is_int($key)) {
368366
$this->bindValue($key + 1, $val);
369367
} else {
370368
$this->bindValue($key, $val);

src/Driver/SQLSrv/SQLSrvStatement.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
1010
use Doctrine\DBAL\ParameterType;
1111
use IteratorAggregate;
12-
use function array_key_exists;
1312
use function is_int;
1413
use function is_numeric;
1514
use function sqlsrv_execute;
@@ -207,9 +206,8 @@ public function columnCount()
207206
public function execute($params = null)
208207
{
209208
if ($params !== null) {
210-
$hasZeroIndex = array_key_exists(0, $params);
211209
foreach ($params as $key => $val) {
212-
if ($hasZeroIndex && is_int($key)) {
210+
if (is_int($key)) {
213211
$this->bindValue($key + 1, $val);
214212
} else {
215213
$this->bindValue($key, $val);

src/Driver/Statement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l
6666
* if any, of their associated parameter markers or pass an array of input-only
6767
* parameter values.
6868
*
69-
* @param mixed[]|null $params An array of values with as many elements as there are
69+
* @param mixed[]|null $params A numeric array of values with as many elements as there are
7070
* bound parameters in the SQL statement being executed.
7171
*
7272
* @return bool TRUE on success or FALSE on failure.

tests/Driver/OCI8/OCI8StatementTest.php

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
namespace Doctrine\DBAL\Tests\Driver\OCI8;
44

5-
use Doctrine\DBAL\Driver\OCI8\OCI8Connection;
65
use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
76
use Doctrine\DBAL\Driver\OCI8\OCI8Statement;
87
use PHPUnit\Framework\TestCase;
9-
use ReflectionProperty;
108
use function extension_loaded;
119

1210
class OCI8StatementTest extends TestCase
@@ -20,76 +18,6 @@ protected function setUp() : void
2018
parent::setUp();
2119
}
2220

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

0 commit comments

Comments
 (0)