diff --git a/UPGRADE.md b/UPGRADE.md index e63df07c3dc..a2837f855fe 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` trown in case of an error. + ## BC BREAK Changes in driver exceptions 1. The `Doctrine\DBAL\Driver\DriverException::getErrorCode()` method is removed. In order to obtain the driver error code, please use `::getCode()`. diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 11fc857b936..746e463e436 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1065,24 +1065,6 @@ public function getTransactionNestingLevel() return $this->transactionNestingLevel; } - /** - * Fetches the SQLSTATE associated with the last database operation. - * - * @return string|null The last error code. - */ - public function errorCode() - { - return $this->getWrappedConnection()->errorCode(); - } - - /** - * {@inheritDoc} - */ - 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/lib/Doctrine/DBAL/Driver/Connection.php b/lib/Doctrine/DBAL/Driver/Connection.php index acae0b66f9a..8ee150ec4f7 100644 --- a/lib/Doctrine/DBAL/Driver/Connection.php +++ b/lib/Doctrine/DBAL/Driver/Connection.php @@ -67,18 +67,4 @@ public function commit() : void; * @throws DriverException */ public function rollBack() : void; - - /** - * Returns the error code associated with the last operation on the database handle. - * - * @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. - * - * @return mixed[] - */ - public function errorInfo(); } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index 9763a627c14..c5a41d335b3 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -13,8 +13,6 @@ use const DB2_AUTOCOMMIT_ON; 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; use function db2_exec; @@ -165,23 +163,4 @@ public function rollBack() : void throw DB2Exception::fromConnectionError($this->conn); } } - - /** - * {@inheritdoc} - */ - public function errorCode() - { - return db2_conn_error($this->conn); - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - return [ - 0 => db2_conn_errormsg($this->conn), - 1 => $this->errorCode(), - ]; - } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index dfe594d386c..f2633d95d65 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -32,8 +32,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; use function fwrite; @@ -165,25 +163,6 @@ public function columnCount() return db2_num_fields($this->stmt) ?: 0; } - /** - * {@inheritdoc} - */ - public function errorCode() - { - return db2_stmt_error(); - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - return [ - db2_stmt_errormsg(), - db2_stmt_error(), - ]; - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index b377b79c711..02697c96013 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -198,22 +198,6 @@ public function rollBack() : void } } - /** - * {@inheritdoc} - */ - public function errorCode() - { - return $this->conn->errno; - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - return $this->conn->error; - } - /** * Apply the driver options to the connection. * diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 156b2dd5835..bb07e5a9a95 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -388,22 +388,6 @@ public function fetchColumn($columnIndex = 0) return $row[$columnIndex]; } - /** - * {@inheritdoc} - */ - public function errorCode() - { - return $this->_stmt->errno; - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - return $this->_stmt->error; - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index 8a75d27f62e..d32ecd15317 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -199,31 +199,4 @@ public function rollBack() : void $this->executeMode = OCI_COMMIT_ON_SUCCESS; } - - /** - * {@inheritdoc} - */ - public function errorCode() - { - $error = oci_error($this->dbh); - if ($error !== false) { - $error = $error['code']; - } - - return $error; - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - $error = oci_error($this->dbh); - - if ($error === false) { - return []; - } - - return $error; - } } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index 00bf3abf36b..c4dfdddeacd 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -342,33 +342,6 @@ public function columnCount() return oci_num_fields($this->_sth) ?: 0; } - /** - * {@inheritdoc} - */ - public function errorCode() - { - $error = oci_error($this->_sth); - if ($error !== false) { - $error = $error['code']; - } - - return $error; - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - $error = oci_error($this->_sth); - - if ($error === false) { - return []; - } - - return $error; - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Driver/PDOConnection.php b/lib/Doctrine/DBAL/Driver/PDOConnection.php index bc9128e1eb3..d9b40e923c9 100644 --- a/lib/Doctrine/DBAL/Driver/PDOConnection.php +++ b/lib/Doctrine/DBAL/Driver/PDOConnection.php @@ -148,22 +148,6 @@ public function rollBack() : void $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/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index b3b252a41f4..411cf8222c8 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -113,22 +113,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/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php index d98cffcd9a8..7b2161a2e68 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php @@ -14,8 +14,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; @@ -84,22 +82,6 @@ public function commit() : void $this->endTransaction(); } - /** - * {@inheritdoc} - */ - public function errorCode() - { - return sasql_errorcode($this->connection); - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - return sasql_error($this->connection); - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 415be465041..c8afb177f46 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -30,8 +30,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; @@ -144,22 +142,6 @@ public function columnCount() return sasql_stmt_field_count($this->stmt); } - /** - * {@inheritdoc} - */ - public function errorCode() - { - return sasql_stmt_errno($this->stmt); - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - return sasql_stmt_error($this->stmt); - } - /** * {@inheritdoc} * diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index 2e4ac7da767..4470c58cd6d 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -8,12 +8,10 @@ use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\Statement as DriverStatement; -use const SQLSRV_ERR_ERRORS; use function sqlsrv_begin_transaction; 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; @@ -162,25 +160,4 @@ public function rollBack() : void throw SQLSrvException::fromSqlSrvErrors(); } } - - /** - * {@inheritDoc} - */ - public function errorCode() - { - $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); - if ($errors) { - return $errors[0]['code']; - } - - return false; - } - - /** - * {@inheritDoc} - */ - public function errorInfo() - { - return (array) sqlsrv_errors(SQLSRV_ERR_ERRORS); - } } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index cb52aa44720..ad572e81e30 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -11,7 +11,6 @@ use Doctrine\DBAL\ParameterType; use IteratorAggregate; 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; @@ -21,7 +20,6 @@ use function in_array; 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; @@ -207,27 +205,6 @@ public function columnCount() return sqlsrv_num_fields($this->stmt) ?: 0; } - /** - * {@inheritdoc} - */ - public function errorCode() - { - $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); - if ($errors) { - return $errors[0]['code']; - } - - return false; - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - return (array) sqlsrv_errors(SQLSRV_ERR_ERRORS); - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Driver/Statement.php b/lib/Doctrine/DBAL/Driver/Statement.php index 8ad231fea10..dd7895d93d3 100644 --- a/lib/Doctrine/DBAL/Driver/Statement.php +++ b/lib/Doctrine/DBAL/Driver/Statement.php @@ -59,22 +59,6 @@ public function bindValue($param, $value, $type = ParameterType::STRING) : void; */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) : void; - /** - * Fetches the SQLSTATE associated with the last operation on the statement handle. - * - * @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. - * - * @return mixed[] The error info array. - */ - public function errorInfo(); - /** * Executes a prepared statement * diff --git a/lib/Doctrine/DBAL/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index c2ab9534fd7..102c11d9268 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -80,26 +80,6 @@ public function columnCount() return $this->stmt->columnCount(); } - /** - * {@inheritdoc} - */ - public function errorCode() - { - assert($this->stmt instanceof DriverStatement); - - return $this->stmt->errorCode(); - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - assert($this->stmt instanceof DriverStatement); - - return $this->stmt->errorInfo(); - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 7022c809b61..61e60f5e0ed 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -179,24 +179,6 @@ public function columnCount() return $this->stmt->columnCount(); } - /** - * Fetches the SQLSTATE associated with the last operation on the statement. - * - * @return string|int|bool - */ - public function errorCode() - { - return $this->stmt->errorCode(); - } - - /** - * {@inheritDoc} - */ - public function errorInfo() - { - return $this->stmt->errorInfo(); - } - /** * {@inheritdoc} */ diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 428af1038d4..71305aa7c85 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -26,7 +26,6 @@ parameters: - '~^Method Doctrine\\DBAL\\Schema\\(Oracle|PostgreSql|SQLServer)SchemaManager::_getPortableTableDefinition\(\) should return array but returns string\.\z~' - '~^Method Doctrine\\DBAL\\Platforms\\(|SQLAnywhere|Sqlite)Platform::_getTransactionIsolationLevelSQL\(\) should return string but returns int\.\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~' # http://php.net/manual/en/pdo.sqlitecreatefunction.php - '~^Call to an undefined method PDO::sqliteCreateFunction\(\)\.\z~' diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php index c0904d01797..dcca544efbb 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Driver\OCI8\OCI8Exception; use Doctrine\DBAL\Driver\OCI8\OCI8Statement; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; use ReflectionProperty; use const OCI_NO_AUTO_COMMIT; use function extension_loaded; @@ -39,8 +40,9 @@ protected function setUp() : void */ public function testExecute(array $params) { + /** @var OCI8Statement|MockObject $statement */ $statement = $this->getMockBuilder(OCI8Statement::class) - ->setMethods(['bindValue', 'errorInfo']) + ->setMethods(['bindValue']) ->disableOriginalConstructor() ->getMock(); @@ -56,10 +58,7 @@ public function testExecute(array $params) // 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) - ->setMethods(['getExecuteMode']) - ->disableOriginalConstructor() - ->getMock(); + $conn = $this->createMock(OCI8Connection::class); $conn->expects($this->once()) ->method('getExecuteMode') ->willReturn(OCI_NO_AUTO_COMMIT); diff --git a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php index 2477efcd4d3..bd14320921c 100644 --- a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php @@ -85,29 +85,7 @@ public function testColumnCount() self::assertSame($columnCount, $this->stmt->columnCount()); } - public function testErrorCode() - { - $errorCode = '666'; - - $this->wrappedStmt->expects($this->once()) - ->method('errorCode') - ->will($this->returnValue($errorCode)); - - self::assertSame($errorCode, $this->stmt->errorCode()); - } - - public function testErrorInfo() - { - $errorInfo = ['666', 'Evil error.']; - - $this->wrappedStmt->expects($this->once()) - ->method('errorInfo') - ->will($this->returnValue($errorInfo)); - - self::assertSame($errorInfo, $this->stmt->errorInfo()); - } - - public function testExecute() + public function testExecute() : void { $params = [ 'foo',