Removed errorCode() and errorInfo() methods from Connection and Statement APIs

parent 808ca39d
# Upgrade to 3.0 # 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 ## 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()`. 1. The `Doctrine\DBAL\Driver\DriverException::getErrorCode()` method is removed. In order to obtain the driver error code, please use `::getCode()`.
......
...@@ -1077,24 +1077,6 @@ class Connection implements DriverConnection ...@@ -1077,24 +1077,6 @@ class Connection implements DriverConnection
return $this->transactionNestingLevel; 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, * Returns the ID of the last inserted row, or the last value from a sequence object,
* depending on the underlying driver. * depending on the underlying driver.
......
...@@ -67,18 +67,4 @@ interface Connection ...@@ -67,18 +67,4 @@ interface Connection
* @throws DriverException * @throws DriverException
*/ */
public function rollBack() : void; 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();
} }
...@@ -13,8 +13,6 @@ use const DB2_AUTOCOMMIT_OFF; ...@@ -13,8 +13,6 @@ use const DB2_AUTOCOMMIT_OFF;
use const DB2_AUTOCOMMIT_ON; use const DB2_AUTOCOMMIT_ON;
use function db2_autocommit; use function db2_autocommit;
use function db2_commit; use function db2_commit;
use function db2_conn_error;
use function db2_conn_errormsg;
use function db2_connect; use function db2_connect;
use function db2_escape_string; use function db2_escape_string;
use function db2_exec; use function db2_exec;
...@@ -165,23 +163,4 @@ class DB2Connection implements Connection, ServerInfoAwareConnection ...@@ -165,23 +163,4 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
throw DB2Exception::fromConnectionError($this->conn); 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(),
];
}
} }
...@@ -32,8 +32,6 @@ use function db2_fetch_object; ...@@ -32,8 +32,6 @@ use function db2_fetch_object;
use function db2_free_result; use function db2_free_result;
use function db2_num_fields; use function db2_num_fields;
use function db2_num_rows; use function db2_num_rows;
use function db2_stmt_error;
use function db2_stmt_errormsg;
use function error_get_last; use function error_get_last;
use function fclose; use function fclose;
use function fwrite; use function fwrite;
...@@ -165,25 +163,6 @@ class DB2Statement implements IteratorAggregate, Statement ...@@ -165,25 +163,6 @@ class DB2Statement implements IteratorAggregate, Statement
return db2_num_fields($this->stmt) ?: 0; 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} * {@inheritdoc}
*/ */
......
...@@ -198,22 +198,6 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar ...@@ -198,22 +198,6 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
} }
} }
/**
* {@inheritdoc}
*/
public function errorCode()
{
return $this->conn->errno;
}
/**
* {@inheritdoc}
*/
public function errorInfo()
{
return $this->conn->error;
}
/** /**
* Apply the driver options to the connection. * Apply the driver options to the connection.
* *
......
...@@ -388,22 +388,6 @@ class MysqliStatement implements IteratorAggregate, Statement ...@@ -388,22 +388,6 @@ class MysqliStatement implements IteratorAggregate, Statement
return $row[$columnIndex]; return $row[$columnIndex];
} }
/**
* {@inheritdoc}
*/
public function errorCode()
{
return $this->_stmt->errno;
}
/**
* {@inheritdoc}
*/
public function errorInfo()
{
return $this->_stmt->error;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -199,31 +199,4 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection ...@@ -199,31 +199,4 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
$this->executeMode = OCI_COMMIT_ON_SUCCESS; $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;
}
} }
...@@ -346,33 +346,6 @@ class OCI8Statement implements IteratorAggregate, Statement ...@@ -346,33 +346,6 @@ class OCI8Statement implements IteratorAggregate, Statement
return oci_num_fields($this->_sth) ?: 0; 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} * {@inheritdoc}
*/ */
......
...@@ -148,22 +148,6 @@ class PDOConnection implements Connection, ServerInfoAwareConnection ...@@ -148,22 +148,6 @@ class PDOConnection implements Connection, ServerInfoAwareConnection
$this->connection->rollBack(); $this->connection->rollBack();
} }
/**
* {@inheritDoc}
*/
public function errorCode()
{
return $this->connection->errorCode();
}
/**
* {@inheritDoc}
*/
public function errorInfo()
{
return $this->connection->errorInfo();
}
public function getWrappedConnection() : PDO public function getWrappedConnection() : PDO
{ {
return $this->connection; return $this->connection;
......
...@@ -113,22 +113,6 @@ class PDOStatement implements IteratorAggregate, Statement ...@@ -113,22 +113,6 @@ class PDOStatement implements IteratorAggregate, Statement
return $this->stmt->columnCount(); return $this->stmt->columnCount();
} }
/**
* {@inheritdoc}
*/
public function errorCode()
{
return $this->stmt->errorCode();
}
/**
* {@inheritdoc}
*/
public function errorInfo()
{
return $this->stmt->errorInfo();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -14,8 +14,6 @@ use function is_string; ...@@ -14,8 +14,6 @@ use function is_string;
use function sasql_affected_rows; use function sasql_affected_rows;
use function sasql_commit; use function sasql_commit;
use function sasql_connect; use function sasql_connect;
use function sasql_error;
use function sasql_errorcode;
use function sasql_escape_string; use function sasql_escape_string;
use function sasql_insert_id; use function sasql_insert_id;
use function sasql_pconnect; use function sasql_pconnect;
...@@ -84,22 +82,6 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection ...@@ -84,22 +82,6 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
$this->endTransaction(); $this->endTransaction();
} }
/**
* {@inheritdoc}
*/
public function errorCode()
{
return sasql_errorcode($this->connection);
}
/**
* {@inheritdoc}
*/
public function errorInfo()
{
return sasql_error($this->connection);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -30,8 +30,6 @@ use function sasql_fetch_row; ...@@ -30,8 +30,6 @@ use function sasql_fetch_row;
use function sasql_prepare; use function sasql_prepare;
use function sasql_stmt_affected_rows; use function sasql_stmt_affected_rows;
use function sasql_stmt_bind_param_ex; 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_execute;
use function sasql_stmt_field_count; use function sasql_stmt_field_count;
use function sasql_stmt_reset; use function sasql_stmt_reset;
...@@ -144,22 +142,6 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -144,22 +142,6 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
return sasql_stmt_field_count($this->stmt); 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} * {@inheritdoc}
* *
......
...@@ -8,12 +8,10 @@ use Doctrine\DBAL\Driver\Connection; ...@@ -8,12 +8,10 @@ use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Driver\Statement as DriverStatement;
use const SQLSRV_ERR_ERRORS;
use function sqlsrv_begin_transaction; use function sqlsrv_begin_transaction;
use function sqlsrv_commit; use function sqlsrv_commit;
use function sqlsrv_configure; use function sqlsrv_configure;
use function sqlsrv_connect; use function sqlsrv_connect;
use function sqlsrv_errors;
use function sqlsrv_query; use function sqlsrv_query;
use function sqlsrv_rollback; use function sqlsrv_rollback;
use function sqlsrv_rows_affected; use function sqlsrv_rows_affected;
...@@ -162,25 +160,4 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection ...@@ -162,25 +160,4 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
throw SQLSrvException::fromSqlSrvErrors(); 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);
}
} }
...@@ -11,7 +11,6 @@ use Doctrine\DBAL\FetchMode; ...@@ -11,7 +11,6 @@ use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use IteratorAggregate; use IteratorAggregate;
use const SQLSRV_ENC_BINARY; use const SQLSRV_ENC_BINARY;
use const SQLSRV_ERR_ERRORS;
use const SQLSRV_FETCH_ASSOC; use const SQLSRV_FETCH_ASSOC;
use const SQLSRV_FETCH_BOTH; use const SQLSRV_FETCH_BOTH;
use const SQLSRV_FETCH_NUMERIC; use const SQLSRV_FETCH_NUMERIC;
...@@ -21,7 +20,6 @@ use function count; ...@@ -21,7 +20,6 @@ use function count;
use function in_array; use function in_array;
use function is_int; use function is_int;
use function is_numeric; use function is_numeric;
use function sqlsrv_errors;
use function sqlsrv_execute; use function sqlsrv_execute;
use function sqlsrv_fetch; use function sqlsrv_fetch;
use function sqlsrv_fetch_array; use function sqlsrv_fetch_array;
...@@ -209,27 +207,6 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -209,27 +207,6 @@ class SQLSrvStatement implements IteratorAggregate, Statement
return sqlsrv_num_fields($this->stmt) ?: 0; 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} * {@inheritdoc}
*/ */
......
...@@ -59,22 +59,6 @@ interface Statement extends ResultStatement ...@@ -59,22 +59,6 @@ interface Statement extends ResultStatement
*/ */
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) : 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 * Executes a prepared statement
* *
......
...@@ -80,26 +80,6 @@ class Statement implements IteratorAggregate, DriverStatement ...@@ -80,26 +80,6 @@ class Statement implements IteratorAggregate, DriverStatement
return $this->stmt->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} * {@inheritdoc}
*/ */
......
...@@ -179,24 +179,6 @@ class Statement implements IteratorAggregate, DriverStatement ...@@ -179,24 +179,6 @@ class Statement implements IteratorAggregate, DriverStatement
return $this->stmt->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} * {@inheritdoc}
*/ */
......
...@@ -26,7 +26,6 @@ parameters: ...@@ -26,7 +26,6 @@ parameters:
- '~^Method Doctrine\\DBAL\\Schema\\(Oracle|PostgreSql|SQLServer)SchemaManager::_getPortableTableDefinition\(\) should return array but returns string\.\z~' - '~^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\\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\\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 # https://bugs.php.net/bug.php?id=78126
- '~^Call to an undefined method PDO::sqliteCreateFunction\(\)\.\z~' - '~^Call to an undefined method PDO::sqliteCreateFunction\(\)\.\z~'
......
...@@ -8,6 +8,7 @@ use Doctrine\DBAL\Driver\OCI8\OCI8Connection; ...@@ -8,6 +8,7 @@ use Doctrine\DBAL\Driver\OCI8\OCI8Connection;
use Doctrine\DBAL\Driver\OCI8\OCI8Exception; use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
use Doctrine\DBAL\Driver\OCI8\OCI8Statement; use Doctrine\DBAL\Driver\OCI8\OCI8Statement;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionProperty; use ReflectionProperty;
use const OCI_NO_AUTO_COMMIT; use const OCI_NO_AUTO_COMMIT;
use function extension_loaded; use function extension_loaded;
...@@ -39,8 +40,9 @@ class OCI8StatementTest extends DbalTestCase ...@@ -39,8 +40,9 @@ class OCI8StatementTest extends DbalTestCase
*/ */
public function testExecute(array $params) : void public function testExecute(array $params) : void
{ {
/** @var OCI8Statement|MockObject $statement */
$statement = $this->getMockBuilder(OCI8Statement::class) $statement = $this->getMockBuilder(OCI8Statement::class)
->onlyMethods(['bindValue', 'errorInfo']) ->onlyMethods(['bindValue'])
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
...@@ -54,17 +56,9 @@ class OCI8StatementTest extends DbalTestCase ...@@ -54,17 +56,9 @@ class OCI8StatementTest extends DbalTestCase
->willReturn(true); ->willReturn(true);
} }
// 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, // can't pass to constructor since we don't have a real database handle,
// but execute must check the connection for the executeMode // but execute must check the connection for the executeMode
$conn = $this->getMockBuilder(OCI8Connection::class) $conn = $this->createMock(OCI8Connection::class);
->onlyMethods(['getExecuteMode'])
->disableOriginalConstructor()
->getMock();
$conn->expects($this->once()) $conn->expects($this->once())
->method('getExecuteMode') ->method('getExecuteMode')
->willReturn(OCI_NO_AUTO_COMMIT); ->willReturn(OCI_NO_AUTO_COMMIT);
......
...@@ -84,28 +84,6 @@ class StatementTest extends DbalTestCase ...@@ -84,28 +84,6 @@ class StatementTest extends DbalTestCase
self::assertSame($columnCount, $this->stmt->columnCount()); self::assertSame($columnCount, $this->stmt->columnCount());
} }
public function testErrorCode() : void
{
$errorCode = '666';
$this->wrappedStmt->expects($this->once())
->method('errorCode')
->will($this->returnValue($errorCode));
self::assertSame($errorCode, $this->stmt->errorCode());
}
public function testErrorInfo() : void
{
$errorInfo = ['666', 'Evil error.'];
$this->wrappedStmt->expects($this->once())
->method('errorInfo')
->will($this->returnValue($errorInfo));
self::assertSame($errorInfo, $this->stmt->errorInfo());
}
public function testExecute() : void public function testExecute() : void
{ {
$params = [ $params = [
......
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