From 8f331e81e237790311697b4511388521b19e0e97 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 5 Apr 2019 14:45:12 -0700 Subject: [PATCH 1/3] Removed errorCode() and errorInfo() methods from Connection and Statement APIs --- UPGRADE.md | 4 +++ phpstan.neon.dist | 1 - src/Connection.php | 22 ------------ src/Driver/Connection.php | 18 ---------- src/Driver/IBMDB2/DB2Connection.php | 24 ------------- src/Driver/IBMDB2/DB2Statement.php | 24 ------------- src/Driver/Mysqli/MysqliConnection.php | 20 ----------- src/Driver/Mysqli/MysqliStatement.php | 18 ---------- src/Driver/OCI8/OCI8Connection.php | 35 ++----------------- src/Driver/OCI8/OCI8Statement.php | 33 +---------------- src/Driver/PDOConnection.php | 16 --------- src/Driver/PDOStatement.php | 16 --------- .../SQLAnywhere/SQLAnywhereConnection.php | 22 ------------ .../SQLAnywhere/SQLAnywhereStatement.php | 22 ------------ src/Driver/SQLSrv/SQLSrvConnection.php | 27 -------------- src/Driver/SQLSrv/SQLSrvStatement.php | 27 -------------- src/Driver/Statement.php | 20 ----------- src/Portability/Statement.php | 24 ------------- src/Statement.php | 22 ------------ tests/Driver/OCI8/OCI8StatementTest.php | 12 ++----- tests/Portability/StatementTest.php | 22 ------------ 21 files changed, 9 insertions(+), 420 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 8717e37dd0c..55824bdb046 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 3.0 +## BC BREAK `::errorCode()` and `::errorInfo()` removed from `Connection` and `Statement` APIs + +The error information is available in `DriverException` thrown in case of an error. + ## BC BREAK: Dropped support for `FetchMode::CUSTOM_OBJECT` and `::STANDARD_OBJECT` Instead of fetching an object, fetch an array and map it to an object of the desired class. diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 056d90e56df..35fa53a5910 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -27,7 +27,6 @@ parameters: - '~^Method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint::onEvent\(\) should return string\|null but returns false\.\z~' - '~^Method Doctrine\\DBAL\\Schema\\(Oracle|PostgreSql|SQLServer)SchemaManager::_getPortableTableDefinition\(\) should return array but returns string\.\z~' - '~^Method Doctrine\\DBAL\\Driver\\OCI8\\OCI8Connection::lastInsertId\(\) should return string but returns (int|false)\.\z~' - - '~^Method Doctrine\\DBAL\\Driver\\SQLSrv\\SQLSrvConnection::errorCode\(\) should return string\|null but returns false\.\z~' # https://bugs.php.net/bug.php?id=78126 - '~^Call to an undefined method PDO::sqliteCreateFunction\(\)\.\z~' diff --git a/src/Connection.php b/src/Connection.php index 01bc249005a..26706d25802 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -1320,28 +1320,6 @@ public function getTransactionNestingLevel() return $this->transactionNestingLevel; } - /** - * Fetches the SQLSTATE associated with the last database operation. - * - * @deprecated The error information is available via exceptions. - * - * @return string|null The last error code. - */ - public function errorCode() - { - return $this->getWrappedConnection()->errorCode(); - } - - /** - * {@inheritDoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - return $this->getWrappedConnection()->errorInfo(); - } - /** * Returns the ID of the last inserted row, or the last value from a sequence object, * depending on the underlying driver. diff --git a/src/Driver/Connection.php b/src/Driver/Connection.php index d8e68b81490..7817f60adad 100644 --- a/src/Driver/Connection.php +++ b/src/Driver/Connection.php @@ -71,22 +71,4 @@ public function commit(); * @return bool TRUE on success or FALSE on failure. */ public function rollBack(); - - /** - * Returns the error code associated with the last operation on the database handle. - * - * @deprecated The error information is available via exceptions. - * - * @return string|null The error code, or null if no operation has been run on the database handle. - */ - public function errorCode(); - - /** - * Returns extended error information associated with the last operation on the database handle. - * - * @deprecated The error information is available via exceptions. - * - * @return mixed[] - */ - public function errorInfo(); } diff --git a/src/Driver/IBMDB2/DB2Connection.php b/src/Driver/IBMDB2/DB2Connection.php index e8905f11a38..bfea7420566 100644 --- a/src/Driver/IBMDB2/DB2Connection.php +++ b/src/Driver/IBMDB2/DB2Connection.php @@ -10,7 +10,6 @@ use function assert; use function db2_autocommit; use function db2_commit; -use function db2_conn_error; use function db2_conn_errormsg; use function db2_connect; use function db2_escape_string; @@ -166,27 +165,4 @@ public function rollBack() return $result; } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorCode() - { - return db2_conn_error($this->conn); - } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - return [ - 0 => db2_conn_errormsg($this->conn), - 1 => $this->errorCode(), - ]; - } } diff --git a/src/Driver/IBMDB2/DB2Statement.php b/src/Driver/IBMDB2/DB2Statement.php index 0f42dac26b6..d485f8ed576 100644 --- a/src/Driver/IBMDB2/DB2Statement.php +++ b/src/Driver/IBMDB2/DB2Statement.php @@ -16,7 +16,6 @@ use function db2_free_result; use function db2_num_fields; use function db2_num_rows; -use function db2_stmt_error; use function db2_stmt_errormsg; use function error_get_last; use function fclose; @@ -154,29 +153,6 @@ public function columnCount() return 0; } - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorCode() - { - return db2_stmt_error(); - } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - return [ - db2_stmt_errormsg(), - db2_stmt_error(), - ]; - } - /** * {@inheritdoc} */ diff --git a/src/Driver/Mysqli/MysqliConnection.php b/src/Driver/Mysqli/MysqliConnection.php index ba1c7fbbfe9..93274207eec 100644 --- a/src/Driver/Mysqli/MysqliConnection.php +++ b/src/Driver/Mysqli/MysqliConnection.php @@ -193,26 +193,6 @@ public function rollBack() return $this->conn->rollback(); } - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorCode() - { - return $this->conn->errno; - } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - return $this->conn->error; - } - /** * Apply the driver options to the connection. * diff --git a/src/Driver/Mysqli/MysqliStatement.php b/src/Driver/Mysqli/MysqliStatement.php index ac9f03abbf8..f9e71042af0 100644 --- a/src/Driver/Mysqli/MysqliStatement.php +++ b/src/Driver/Mysqli/MysqliStatement.php @@ -463,24 +463,6 @@ public function fetchAllAssociative() : array return FetchUtils::fetchAllAssociative($this); } - /** - * {@inheritdoc} - */ - public function errorCode() - { - return $this->_stmt->errno; - } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - return $this->_stmt->error; - } - /** * {@inheritdoc} */ diff --git a/src/Driver/OCI8/OCI8Connection.php b/src/Driver/OCI8/OCI8Connection.php index 378094383e5..efdb3b4d9a8 100644 --- a/src/Driver/OCI8/OCI8Connection.php +++ b/src/Driver/OCI8/OCI8Connection.php @@ -181,7 +181,7 @@ public function beginTransaction() public function commit() { if (! oci_commit($this->dbh)) { - throw OCI8Exception::fromErrorInfo($this->errorInfo()); + throw OCI8Exception::fromErrorInfo(oci_error($this->dbh)); } $this->executeMode = OCI_COMMIT_ON_SUCCESS; @@ -195,42 +195,11 @@ public function commit() public function rollBack() { if (! oci_rollback($this->dbh)) { - throw OCI8Exception::fromErrorInfo($this->errorInfo()); + throw OCI8Exception::fromErrorInfo(oci_error($this->dbh)); } $this->executeMode = OCI_COMMIT_ON_SUCCESS; return true; } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorCode() - { - $error = oci_error($this->dbh); - if ($error !== false) { - $error = $error['code']; - } - - return $error; - } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - $error = oci_error($this->dbh); - - if ($error === false) { - return []; - } - - return $error; - } } diff --git a/src/Driver/OCI8/OCI8Statement.php b/src/Driver/OCI8/OCI8Statement.php index 229e348f45c..9e29b49ad16 100644 --- a/src/Driver/OCI8/OCI8Statement.php +++ b/src/Driver/OCI8/OCI8Statement.php @@ -356,37 +356,6 @@ public function columnCount() return 0; } - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorCode() - { - $error = oci_error($this->_sth); - if ($error !== false) { - $error = $error['code']; - } - - return $error; - } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - $error = oci_error($this->_sth); - - if ($error === false) { - return []; - } - - return $error; - } - /** * {@inheritdoc} */ @@ -405,7 +374,7 @@ public function execute($params = null) $ret = @oci_execute($this->_sth, $this->_conn->getExecuteMode()); if (! $ret) { - throw OCI8Exception::fromErrorInfo($this->errorInfo()); + throw OCI8Exception::fromErrorInfo(oci_error($this->_sth)); } $this->result = true; diff --git a/src/Driver/PDOConnection.php b/src/Driver/PDOConnection.php index 7cceff36ef2..77938099311 100644 --- a/src/Driver/PDOConnection.php +++ b/src/Driver/PDOConnection.php @@ -138,22 +138,6 @@ public function rollBack() return $this->connection->rollBack(); } - /** - * {@inheritDoc} - */ - public function errorCode() - { - return $this->connection->errorCode(); - } - - /** - * {@inheritDoc} - */ - public function errorInfo() - { - return $this->connection->errorInfo(); - } - public function getWrappedConnection() : PDO { return $this->connection; diff --git a/src/Driver/PDOStatement.php b/src/Driver/PDOStatement.php index be6c41a3e12..6e176caa628 100644 --- a/src/Driver/PDOStatement.php +++ b/src/Driver/PDOStatement.php @@ -115,22 +115,6 @@ public function columnCount() return $this->stmt->columnCount(); } - /** - * {@inheritdoc} - */ - public function errorCode() - { - return $this->stmt->errorCode(); - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - return $this->stmt->errorInfo(); - } - /** * {@inheritdoc} */ diff --git a/src/Driver/SQLAnywhere/SQLAnywhereConnection.php b/src/Driver/SQLAnywhere/SQLAnywhereConnection.php index 285d7b84ded..d07711658e9 100644 --- a/src/Driver/SQLAnywhere/SQLAnywhereConnection.php +++ b/src/Driver/SQLAnywhere/SQLAnywhereConnection.php @@ -15,8 +15,6 @@ use function sasql_affected_rows; use function sasql_commit; use function sasql_connect; -use function sasql_error; -use function sasql_errorcode; use function sasql_escape_string; use function sasql_insert_id; use function sasql_pconnect; @@ -89,26 +87,6 @@ public function commit() return true; } - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorCode() - { - return sasql_errorcode($this->connection); - } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - return sasql_error($this->connection); - } - public function exec(string $statement) : int { if (sasql_real_query($this->connection, $statement) === false) { diff --git a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php index e5c1928610a..4c9d86fa77d 100644 --- a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -20,8 +20,6 @@ use function sasql_prepare; use function sasql_stmt_affected_rows; use function sasql_stmt_bind_param_ex; -use function sasql_stmt_errno; -use function sasql_stmt_error; use function sasql_stmt_execute; use function sasql_stmt_field_count; use function sasql_stmt_reset; @@ -138,26 +136,6 @@ public function columnCount() return sasql_stmt_field_count($this->stmt); } - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorCode() - { - return sasql_stmt_errno($this->stmt); - } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - return sasql_stmt_error($this->stmt); - } - /** * {@inheritdoc} * diff --git a/src/Driver/SQLSrv/SQLSrvConnection.php b/src/Driver/SQLSrv/SQLSrvConnection.php index 79158cf6822..a97f26961ff 100644 --- a/src/Driver/SQLSrv/SQLSrvConnection.php +++ b/src/Driver/SQLSrv/SQLSrvConnection.php @@ -14,13 +14,11 @@ use function sqlsrv_commit; use function sqlsrv_configure; use function sqlsrv_connect; -use function sqlsrv_errors; use function sqlsrv_query; use function sqlsrv_rollback; use function sqlsrv_rows_affected; use function sqlsrv_server_info; use function str_replace; -use const SQLSRV_ERR_ERRORS; /** * SQL Server implementation for the Connection interface. @@ -173,29 +171,4 @@ public function rollBack() return true; } - - /** - * {@inheritDoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorCode() - { - $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); - if ($errors !== null) { - return $errors[0]['code']; - } - - return false; - } - - /** - * {@inheritDoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - return (array) sqlsrv_errors(SQLSRV_ERR_ERRORS); - } } diff --git a/src/Driver/SQLSrv/SQLSrvStatement.php b/src/Driver/SQLSrv/SQLSrvStatement.php index d13a48b52d0..afa6d923731 100644 --- a/src/Driver/SQLSrv/SQLSrvStatement.php +++ b/src/Driver/SQLSrv/SQLSrvStatement.php @@ -12,7 +12,6 @@ use function array_key_exists; use function is_int; use function is_numeric; -use function sqlsrv_errors; use function sqlsrv_execute; use function sqlsrv_fetch; use function sqlsrv_fetch_array; @@ -26,7 +25,6 @@ use function SQLSRV_SQLTYPE_VARBINARY; use function stripos; use const SQLSRV_ENC_BINARY; -use const SQLSRV_ERR_ERRORS; use const SQLSRV_FETCH_ASSOC; use const SQLSRV_FETCH_BOTH; use const SQLSRV_FETCH_NUMERIC; @@ -203,31 +201,6 @@ public function columnCount() return 0; } - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorCode() - { - $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); - if ($errors !== null) { - return $errors[0]['code']; - } - - return false; - } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - return (array) sqlsrv_errors(SQLSRV_ERR_ERRORS); - } - /** * {@inheritdoc} */ diff --git a/src/Driver/Statement.php b/src/Driver/Statement.php index e6f0135fcae..6599d822a65 100644 --- a/src/Driver/Statement.php +++ b/src/Driver/Statement.php @@ -57,26 +57,6 @@ public function bindValue($param, $value, $type = ParameterType::STRING); */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null); - /** - * Fetches the SQLSTATE associated with the last operation on the statement handle. - * - * @deprecated The error information is available via exceptions. - * - * @see Doctrine_Adapter_Interface::errorCode() - * - * @return string|int|bool The error code string. - */ - public function errorCode(); - - /** - * Fetches extended error information associated with the last operation on the statement handle. - * - * @deprecated The error information is available via exceptions. - * - * @return mixed[] The error info array. - */ - public function errorInfo(); - /** * Executes a prepared statement * diff --git a/src/Portability/Statement.php b/src/Portability/Statement.php index 3465e8077c6..1d1a85887c3 100644 --- a/src/Portability/Statement.php +++ b/src/Portability/Statement.php @@ -79,30 +79,6 @@ public function columnCount() return $this->stmt->columnCount(); } - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorCode() - { - assert($this->stmt instanceof DriverStatement); - - return $this->stmt->errorCode(); - } - - /** - * {@inheritdoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - assert($this->stmt instanceof DriverStatement); - - return $this->stmt->errorInfo(); - } - /** * {@inheritdoc} */ diff --git a/src/Statement.php b/src/Statement.php index 37d91027c72..def50288964 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -196,28 +196,6 @@ public function columnCount() return $this->stmt->columnCount(); } - /** - * Fetches the SQLSTATE associated with the last operation on the statement. - * - * @deprecated The error information is available via exceptions. - * - * @return string|int|bool - */ - public function errorCode() - { - return $this->stmt->errorCode(); - } - - /** - * {@inheritDoc} - * - * @deprecated The error information is available via exceptions. - */ - public function errorInfo() - { - return $this->stmt->errorInfo(); - } - /** * {@inheritdoc} * diff --git a/tests/Driver/OCI8/OCI8StatementTest.php b/tests/Driver/OCI8/OCI8StatementTest.php index 6a4ff3db823..068be3c1a05 100644 --- a/tests/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Driver/OCI8/OCI8StatementTest.php @@ -36,7 +36,7 @@ protected function setUp() : void public function testExecute(array $params) : void { $statement = $this->getMockBuilder(OCI8Statement::class) - ->onlyMethods(['bindValue', 'errorInfo']) + ->onlyMethods(['bindValue']) ->disableOriginalConstructor() ->getMock(); @@ -59,17 +59,9 @@ public function testExecute(array $params) : void self::equalTo($params[2]) ); - // the return value is irrelevant to the test - // but it has to be compatible with the method signature - $statement->method('errorInfo') - ->willReturn(false); - // 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->getMockBuilder(OCI8Connection::class) - ->onlyMethods(['getExecuteMode']) - ->disableOriginalConstructor() - ->getMock(); + $conn = $this->createMock(OCI8Connection::class); $conn->expects(self::once()) ->method('getExecuteMode'); diff --git a/tests/Portability/StatementTest.php b/tests/Portability/StatementTest.php index 91ceabc406f..49362e21ee7 100644 --- a/tests/Portability/StatementTest.php +++ b/tests/Portability/StatementTest.php @@ -80,28 +80,6 @@ public function testColumnCount() : void self::assertSame($columnCount, $this->stmt->columnCount()); } - public function testErrorCode() : void - { - $errorCode = '666'; - - $this->wrappedStmt->expects(self::once()) - ->method('errorCode') - ->will(self::returnValue($errorCode)); - - self::assertSame($errorCode, $this->stmt->errorCode()); - } - - public function testErrorInfo() : void - { - $errorInfo = ['666', 'Evil error.']; - - $this->wrappedStmt->expects(self::once()) - ->method('errorInfo') - ->will(self::returnValue($errorInfo)); - - self::assertSame($errorInfo, $this->stmt->errorInfo()); - } - public function testExecute() : void { $params = [ From bfa733d8844312412b9327dc135b771842003988 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 15 Jan 2020 20:48:45 -0800 Subject: [PATCH 2/3] Removed Connection::project() The methods has more limitations and caveats than provides real use: 1. It fetches all data in memory which is often inefficient (see #2718). 2. It fetches rows in memory one by one instead of using `fetchAll()`. 4. It doesn't allow to specify the statement fetch mode since it's instantiated internally. 5. It can be easily replaced with: ```php foreach ($conn->executeQuery($query, $params, $types) as $value) { yield $function($value); } ``` --- UPGRADE.md | 4 ++++ src/Connection.php | 28 ---------------------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 55824bdb046..513fa074e85 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 3.0 +## 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. + ## BC BREAK `::errorCode()` and `::errorInfo()` removed from `Connection` and `Statement` APIs The error information is available in `DriverException` thrown in case of an error. diff --git a/src/Connection.php b/src/Connection.php index 26706d25802..9b8a4b62c6f 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -1187,34 +1187,6 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc return $stmt; } - /** - * Executes an, optionally parametrized, SQL query and returns the result, - * applying a given projection/transformation function on each row of the result. - * - * @deprecated - * - * @param string $query The SQL query to execute. - * @param mixed[] $params The parameters, if any. - * @param Closure $function The transformation function that is applied on each row. - * The function receives a single parameter, an array, that - * represents a row of the result set. - * - * @return mixed[] The projected result of the query. - */ - public function project($query, array $params, Closure $function) - { - $result = []; - $stmt = $this->executeQuery($query, $params); - - while ($row = $stmt->fetch()) { - $result[] = $function($row); - } - - $stmt->closeCursor(); - - return $result; - } - public function query(string $sql) : ResultStatement { $connection = $this->getWrappedConnection(); From a48cad1e5f6b9a49a102d91ff4af3ee7e6ab090c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Jan 2020 00:48:44 -0800 Subject: [PATCH 3/3] Dropped handling of one-based numeric arrays of parameters in Statement::execute() --- UPGRADE.md | 4 ++ src/Driver/OCI8/OCI8Statement.php | 4 +- src/Driver/SQLSrv/SQLSrvStatement.php | 4 +- src/Driver/Statement.php | 2 +- tests/Driver/OCI8/OCI8StatementTest.php | 72 ------------------------- 5 files changed, 7 insertions(+), 79 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 513fa074e85..4a81d1a32b7 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 `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. diff --git a/src/Driver/OCI8/OCI8Statement.php b/src/Driver/OCI8/OCI8Statement.php index 9e29b49ad16..2383dd307ed 100644 --- a/src/Driver/OCI8/OCI8Statement.php +++ b/src/Driver/OCI8/OCI8Statement.php @@ -10,7 +10,6 @@ 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 @@ public function columnCount() 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); diff --git a/src/Driver/SQLSrv/SQLSrvStatement.php b/src/Driver/SQLSrv/SQLSrvStatement.php index afa6d923731..00a69bae3fe 100644 --- a/src/Driver/SQLSrv/SQLSrvStatement.php +++ b/src/Driver/SQLSrv/SQLSrvStatement.php @@ -9,7 +9,6 @@ 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 @@ public function columnCount() 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); diff --git a/src/Driver/Statement.php b/src/Driver/Statement.php index 6599d822a65..4fb7865e28f 100644 --- a/src/Driver/Statement.php +++ b/src/Driver/Statement.php @@ -66,7 +66,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l * 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. diff --git a/tests/Driver/OCI8/OCI8StatementTest.php b/tests/Driver/OCI8/OCI8StatementTest.php index 068be3c1a05..1de85da0b09 100644 --- a/tests/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Driver/OCI8/OCI8StatementTest.php @@ -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 @@ 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 - { - $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> - */ - 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 */