Skip to content

Commit

Permalink
Converted Connection and Statement methods which returned false in ca…
Browse files Browse the repository at this point in the history
…se of a failure into void
  • Loading branch information
morozov committed Mar 15, 2019
1 parent 322dc7c commit fec294f
Show file tree
Hide file tree
Showing 21 changed files with 205 additions and 243 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade to 3.0

## BC BREAK `Statement` and `Connection` methods return `void`.

`Connection::connect()`, `Statement::bindParam()`, `::bindValue()`, `::execute()`, `ResultStatement::setFetchMode()` and `::closeCursor()` no longer return a boolean value. They will throw an exception in case of failure.

## BC BREAK Transaction-related `Statement` methods return `void`.

`Statement::beginTransaction()`, `::commit()` and `::rollBack()` no longer return a boolean value. They will throw a `DriverException` in case of failure.
Expand Down
6 changes: 2 additions & 4 deletions lib/Doctrine/DBAL/Cache/ArrayStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(array $data)
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
unset($this->data);
}
Expand All @@ -60,15 +60,13 @@ public function columnCount()
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
if (count($args) > 0) {
throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode()');
}

$this->defaultFetchMode = $fetchMode;

return true;
}

/**
Expand Down
11 changes: 4 additions & 7 deletions lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ public function __construct(ResultStatement $stmt, Cache $resultCache, $cacheKey
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
$this->statement->closeCursor();

if (! $this->emptied || $this->data === null) {
return true;
return;
}

$data = $this->resultCache->fetch($this->cacheKey);
Expand All @@ -92,8 +93,6 @@ public function closeCursor()

$this->resultCache->save($this->cacheKey, $data, $this->lifetime);
unset($this->data);

return true;
}

/**
Expand All @@ -107,11 +106,9 @@ public function columnCount()
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
$this->defaultFetchMode = $fetchMode;

return true;
}

/**
Expand Down
19 changes: 8 additions & 11 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,12 @@ public function getExpressionBuilder()
/**
* Establishes the connection with the database.
*
* @return bool TRUE if the connection was successfully established, FALSE if
* the connection is already open.
* @throws DriverException
*/
public function connect()
public function connect() : void
{
if ($this->isConnected) {
return false;
return;
}

$driverOptions = $this->params['driverOptions'] ?? [];
Expand All @@ -359,12 +358,12 @@ public function connect()
$this->beginTransaction();
}

if ($this->_eventManager->hasListeners(Events::postConnect)) {
$eventArgs = new Event\ConnectionEventArgs($this);
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
if (! $this->_eventManager->hasListeners(Events::postConnect)) {
return;
}

return true;
$eventArgs = new Event\ConnectionEventArgs($this);
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
}

/**
Expand Down Expand Up @@ -518,10 +517,8 @@ public function setAutoCommit(bool $autoCommit) : void
* Sets the fetch mode.
*
* @param int $fetchMode
*
* @return void
*/
public function setFetchMode($fetchMode)
public function setFetchMode($fetchMode) : void
{
$this->defaultFetchMode = $fetchMode;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function isConnectedToMaster()
/**
* {@inheritDoc}
*/
public function connect($connectionName = null)
public function connect($connectionName = null) : void
{
$requestedConnectionChange = ($connectionName !== null);
$connectionName = $connectionName ?: 'slave';
Expand All @@ -136,7 +136,7 @@ public function connect($connectionName = null)
// change request, then abort right here, because we are already done.
// This prevents writes to the slave in case of "keepSlave" option enabled.
if ($this->_conn !== null && ! $requestedConnectionChange) {
return false;
return;
}

$forceMasterAsSlave = false;
Expand All @@ -153,7 +153,7 @@ public function connect($connectionName = null)
$this->connections['slave'] = $this->_conn;
}

return false;
return;
}

if ($connectionName === 'master') {
Expand All @@ -167,12 +167,12 @@ public function connect($connectionName = null)
$this->connections['slave'] = $this->_conn = $this->connectTo($connectionName);
}

if ($this->_eventManager->hasListeners(Events::postConnect)) {
$eventArgs = new ConnectionEventArgs($this);
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
if (! $this->_eventManager->hasListeners(Events::postConnect)) {
return;
}

return true;
$eventArgs = new ConnectionEventArgs($this);
$this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
}

/**
Expand Down
30 changes: 13 additions & 17 deletions lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public function __construct($stmt)
/**
* {@inheritdoc}
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
public function bindValue($param, $value, $type = ParameterType::STRING) : void
{
return $this->bindParam($param, $value, $type);
$this->bindParam($param, $value, $type);
}

/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) : void
{
switch ($type) {
case ParameterType::INTEGER:
Expand All @@ -122,8 +122,6 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l
$this->bind($column, $variable, DB2_PARAM_IN, DB2_CHAR);
break;
}

return true;
}

/**
Expand All @@ -144,17 +142,17 @@ private function bind($position, &$variable, int $parameterType, int $dataType)
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
$this->bindParam = [];

if (! db2_free_result($this->stmt)) {
return false;
if (! $this->result) {
return;
}

$this->result = false;
db2_free_result($this->stmt);

return true;
$this->result = false;
}

/**
Expand Down Expand Up @@ -187,7 +185,7 @@ public function errorInfo()
/**
* {@inheritdoc}
*/
public function execute($params = null)
public function execute($params = null) : void
{
if ($params === null) {
ksort($this->bindParam);
Expand Down Expand Up @@ -222,26 +220,24 @@ public function execute($params = null)
}

$this->result = true;

return $retval;
}

/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
$this->defaultFetchMode = $fetchMode;

if (isset($args[0])) {
$this->defaultFetchClass = $args[0];
}

if (isset($args[1])) {
$this->defaultFetchClassCtorArgs = (array) $args[2];
if (! isset($args[1])) {
return;
}

return true;
$this->defaultFetchClassCtorArgs = (array) $args[2];
}

/**
Expand Down
23 changes: 8 additions & 15 deletions lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Driver\Mysqli;

use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -101,7 +102,7 @@ public function __construct(mysqli $conn, $prepareString)
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) : void
{
assert(is_int($column));

Expand All @@ -111,14 +112,12 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l

$this->_bindedValues[$column] =& $variable;
$this->types[$column - 1] = self::$_paramTypeMap[$type];

return true;
}

/**
* {@inheritdoc}
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
public function bindValue($param, $value, $type = ParameterType::STRING) : void
{
assert(is_int($param));

Expand All @@ -129,14 +128,12 @@ public function bindValue($param, $value, $type = ParameterType::STRING)
$this->_values[$param] = $value;
$this->_bindedValues[$param] =& $this->_values[$param];
$this->types[$param - 1] = self::$_paramTypeMap[$type];

return true;
}

/**
* {@inheritdoc}
*/
public function execute($params = null)
public function execute($params = null) : void
{
if ($params !== null && count($params) > 0) {
if (! $this->bindUntypedValues($params)) {
Expand Down Expand Up @@ -199,12 +196,12 @@ public function execute($params = null)
}

$this->result = true;

return true;
}

/**
* Binds parameters with known types previously bound to the statement
*
* @throws DriverException
*/
private function bindTypedParameters()
{
Expand Down Expand Up @@ -408,12 +405,10 @@ public function errorInfo()
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
$this->_stmt->free_result();
$this->result = false;

return true;
}

/**
Expand All @@ -439,11 +434,9 @@ public function columnCount()
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
$this->_defaultFetchMode = $fetchMode;

return true;
}

/**
Expand Down
Loading

0 comments on commit fec294f

Please sign in to comment.