Dropped handling of one-based numeric arrays of parameters in Statement::execute()

parent bfa733d8
# 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 `Statement::project()` has been removed
- The `Statement::project()` method has been removed. Use `::executeQuery()` and fetch the data from the statement using one of the `Statement::fetch*()` methods instead.
......
......@@ -10,7 +10,6 @@ use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatib
use Doctrine\DBAL\ParameterType;
use InvalidArgumentException;
use IteratorAggregate;
use function array_key_exists;
use function assert;
use function count;
use function implode;
......@@ -362,9 +361,8 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe
public function execute($params = null)
{
if ($params !== null) {
$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);
......
......@@ -9,7 +9,6 @@ use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use function array_key_exists;
use function is_int;
use function is_numeric;
use function sqlsrv_execute;
......@@ -207,9 +206,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible
public function execute($params = null)
{
if ($params !== null) {
$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);
......
......@@ -66,7 +66,7 @@ interface Statement extends ResultStatement
* 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.
*
* @return bool TRUE on success or FALSE on failure.
......
......@@ -2,11 +2,9 @@
namespace Doctrine\DBAL\Tests\Driver\OCI8;
use Doctrine\DBAL\Driver\OCI8\OCI8Connection;
use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
use Doctrine\DBAL\Driver\OCI8\OCI8Statement;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use function extension_loaded;
class OCI8StatementTest extends TestCase
......@@ -20,76 +18,6 @@ class OCI8StatementTest extends TestCase
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
{
$statement = $this->getMockBuilder(OCI8Statement::class)
->onlyMethods(['bindValue'])
->disableOriginalConstructor()
->getMock();
$statement->expects(self::at(0))
->method('bindValue')
->with(
self::equalTo(1),
self::equalTo($params[0])
);
$statement->expects(self::at(1))
->method('bindValue')
->with(
self::equalTo(2),
self::equalTo($params[1])
);
$statement->expects(self::at(2))
->method('bindValue')
->with(
self::equalTo(3),
self::equalTo($params[2])
);
// 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(self::once())
->method('getExecuteMode');
$reflProperty = new ReflectionProperty($statement, '_conn');
$reflProperty->setAccessible(true);
$reflProperty->setValue($statement, $conn);
$this->expectException(OCI8Exception::class);
$statement->execute($params);
}
/**
* @return array<int, array<int, mixed>>
*/
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
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment