Unverified Commit 94b6980f authored by Sergei Morozov's avatar Sergei Morozov

Merge pull request #3486 from morozov/conn-stmt-void

Converted Connection and Statement methods which returned false in case of a failure into void
parents fcde5f5f a64a4c76
# 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 `Statement::rowCount()` is moved.
`Statement::rowCount()` has been moved to the `ResultStatement` interface where it belongs by definition.
......
......@@ -44,7 +44,7 @@ class ArrayStatement implements IteratorAggregate, ResultStatement
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
unset($this->data);
}
......@@ -72,15 +72,13 @@ class ArrayStatement implements IteratorAggregate, ResultStatement
/**
* {@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;
}
/**
......
......@@ -75,11 +75,12 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
/**
* {@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);
......@@ -90,8 +91,6 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
$this->resultCache->save($this->cacheKey, $data, $this->lifetime);
unset($this->data);
return true;
}
/**
......@@ -105,11 +104,9 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
$this->defaultFetchMode = $fetchMode;
return true;
}
/**
......
......@@ -346,13 +346,12 @@ class Connection implements DriverConnection
/**
* 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'] ?? [];
......@@ -368,12 +367,12 @@ class Connection implements DriverConnection
$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);
}
/**
......@@ -527,10 +526,8 @@ class Connection implements DriverConnection
* Sets the fetch mode.
*
* @param int $fetchMode
*
* @return void
*/
public function setFetchMode($fetchMode)
public function setFetchMode($fetchMode) : void
{
$this->defaultFetchMode = $fetchMode;
}
......
......@@ -123,7 +123,7 @@ class MasterSlaveConnection extends Connection
/**
* {@inheritDoc}
*/
public function connect($connectionName = null)
public function connect($connectionName = null) : void
{
$requestedConnectionChange = ($connectionName !== null);
$connectionName = $connectionName ?: 'slave';
......@@ -136,7 +136,7 @@ class MasterSlaveConnection extends Connection
// 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;
......@@ -153,7 +153,7 @@ class MasterSlaveConnection extends Connection
$this->connections['slave'] = $this->_conn;
}
return false;
return;
}
if ($connectionName === 'master') {
......@@ -167,12 +167,12 @@ class MasterSlaveConnection extends Connection
$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);
}
/**
......
......@@ -89,15 +89,15 @@ class DB2Statement implements IteratorAggregate, Statement
/**
* {@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:
......@@ -122,8 +122,6 @@ class DB2Statement implements IteratorAggregate, Statement
$this->bind($column, $variable, DB2_PARAM_IN, DB2_CHAR);
break;
}
return true;
}
/**
......@@ -144,17 +142,17 @@ class DB2Statement implements IteratorAggregate, Statement
/**
* {@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;
}
/**
......@@ -187,7 +185,7 @@ class DB2Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function execute($params = null)
public function execute($params = null) : void
{
if ($params === null) {
ksort($this->bindParam);
......@@ -222,14 +220,12 @@ class DB2Statement implements IteratorAggregate, Statement
}
$this->result = true;
return $retval;
}
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
$this->defaultFetchMode = $fetchMode;
......@@ -237,11 +233,11 @@ class DB2Statement implements IteratorAggregate, Statement
$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];
}
/**
......
......@@ -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;
......@@ -101,7 +102,7 @@ class MysqliStatement implements IteratorAggregate, Statement
/**
* {@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));
......@@ -111,14 +112,12 @@ class MysqliStatement implements IteratorAggregate, Statement
$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));
......@@ -129,14 +128,12 @@ class MysqliStatement implements IteratorAggregate, Statement
$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)) {
......@@ -199,12 +196,12 @@ class MysqliStatement implements IteratorAggregate, Statement
}
$this->result = true;
return true;
}
/**
* Binds parameters with known types previously bound to the statement
*
* @throws DriverException
*/
private function bindTypedParameters()
{
......@@ -408,12 +405,10 @@ class MysqliStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
$this->_stmt->free_result();
$this->result = false;
return true;
}
/**
......@@ -439,11 +434,9 @@ class MysqliStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
$this->_defaultFetchMode = $fetchMode;
return true;
}
/**
......
......@@ -268,15 +268,15 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
public function bindValue($param, $value, $type = ParameterType::STRING) : void
{
return $this->bindParam($param, $value, $type, null);
$this->bindParam($param, $value, $type, null);
}
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) : void
{
$column = $this->_paramMap[$column];
......@@ -293,13 +293,15 @@ class OCI8Statement implements IteratorAggregate, Statement
$this->boundValues[$column] =& $variable;
return oci_bind_by_name(
if (! oci_bind_by_name(
$this->_sth,
$column,
$variable,
$length ?? -1,
$this->convertParameterType($type)
);
)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
}
/**
......@@ -322,18 +324,16 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
// not having the result means there's nothing to close
if (! $this->result) {
return true;
return;
}
oci_cancel($this->_sth);
$this->result = false;
return true;
}
/**
......@@ -374,7 +374,7 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function execute($params = null)
public function execute($params = null) : void
{
if ($params) {
$hasZeroIndex = array_key_exists(0, $params);
......@@ -386,9 +386,7 @@ class OCI8Statement implements IteratorAggregate, Statement
$param = $key;
}
if (! $this->bindValue($param, $val)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
$this->bindValue($param, $val);
}
}
......@@ -398,18 +396,14 @@ class OCI8Statement implements IteratorAggregate, Statement
}
$this->result = true;
return $ret;
}
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
$this->_defaultFetchMode = $fetchMode;
return true;
}
/**
......
......@@ -14,7 +14,7 @@ class Statement extends PDOStatement
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null)
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null) : void
{
if (($type === ParameterType::LARGE_OBJECT || $type === ParameterType::BINARY)
&& $driverOptions === null
......@@ -22,14 +22,14 @@ class Statement extends PDOStatement
$driverOptions = PDO::SQLSRV_ENCODING_BINARY;
}
return parent::bindParam($column, $variable, $type, $length, $driverOptions);
parent::bindParam($column, $variable, $type, $length, $driverOptions);
}
/**
* {@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);
}
}
......@@ -50,12 +50,12 @@ class PDOStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
$fetchMode = $this->convertFetchMode($fetchMode);
try {
return $this->stmt->setFetchMode($fetchMode, ...$args);
$this->stmt->setFetchMode($fetchMode, ...$args);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......@@ -64,12 +64,12 @@ class PDOStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
public function bindValue($param, $value, $type = ParameterType::STRING) : void
{
$type = $this->convertParamType($type);
try {
return $this->stmt->bindValue($param, $value, $type);
$this->stmt->bindValue($param, $value, $type);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......@@ -78,12 +78,12 @@ class PDOStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null)
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null) : void
{
$type = $this->convertParamType($type);
try {
return $this->stmt->bindParam($column, $variable, $type, ...array_slice(func_get_args(), 3));
$this->stmt->bindParam($column, $variable, $type, ...array_slice(func_get_args(), 3));
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......@@ -92,15 +92,9 @@ class PDOStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
try {
return $this->stmt->closeCursor();
} catch (\PDOException $exception) {
// Exceptions not allowed by the interface.
// In case driver implementations do not adhere to the interface, silence exceptions here.
return true;
}
$this->stmt->closeCursor();
}
/**
......@@ -130,10 +124,10 @@ class PDOStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function execute($params = null)
public function execute($params = null) : void
{
try {
return $this->stmt->execute($params);
$this->stmt->execute($params);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......
......@@ -11,10 +11,8 @@ interface ResultStatement extends Traversable
{
/**
* Closes the cursor, enabling the statement to be executed again.
*
* @return bool TRUE on success or FALSE on failure.
*/
public function closeCursor();
public function closeCursor() : void;
/**
* Returns the number of columns in the result set
......@@ -42,10 +40,8 @@ interface ResultStatement extends Traversable
* @param int $fetchMode Controls how the next row will be returned to the caller.
* The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants.
* @param mixed ...$args Optional mode-specific arguments (see {@link self::fetchAll()}).
*
* @return bool
*/
public function setFetchMode($fetchMode, ...$args);
public function setFetchMode($fetchMode, ...$args) : void;
/**
* Returns the next row of a result set.
......
......@@ -89,7 +89,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*
* @throws SQLAnywhereException
*/
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:
......@@ -116,30 +116,22 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
if (! sasql_stmt_bind_param_ex($this->stmt, $column - 1, $variable, $type, $variable === null)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt);
}
return true;
}
/**
* {@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}
*
* @throws SQLAnywhereException
*/
public function closeCursor()
public function closeCursor() : void
{
if (! sasql_stmt_reset($this->stmt)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt);
}
return true;
sasql_stmt_reset($this->stmt);
}
/**
......@@ -171,7 +163,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*
* @throws SQLAnywhereException
*/
public function execute($params = null)
public function execute($params = null) : void
{
if (is_array($params)) {
$hasZeroIndex = array_key_exists(0, $params);
......@@ -190,8 +182,6 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
}
$this->result = sasql_stmt_result_metadata($this->stmt);
return true;
}
/**
......@@ -309,7 +299,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
$this->defaultFetchMode = $fetchMode;
......@@ -317,11 +307,11 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
$this->defaultFetchClass = $args[0];
}
if (isset($args[1])) {
$this->defaultFetchClassCtorArgs = (array) $args[1];
if (! isset($args[1])) {
return;
}
return true;
$this->defaultFetchClassCtorArgs = (array) $args[1];
}
/**
......
......@@ -147,7 +147,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
public function bindValue($param, $value, $type = ParameterType::STRING) : void
{
if (! is_numeric($param)) {
throw new SQLSrvException(
......@@ -162,7 +162,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) : void
{
if (! is_numeric($column)) {
throw new SQLSrvException('sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.');
......@@ -178,11 +178,11 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
// not having the result means there's nothing to close
if ($this->stmt === null || ! $this->result) {
return true;
return;
}
// emulate it by fetching and discarding rows, similarly to what PDO does in this case
......@@ -193,8 +193,6 @@ class SQLSrvStatement implements IteratorAggregate, Statement
}
$this->result = false;
return true;
}
/**
......@@ -233,7 +231,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function execute($params = null)
public function execute($params = null) : void
{
if ($params) {
$hasZeroIndex = array_key_exists(0, $params);
......@@ -312,7 +310,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
$this->defaultFetchMode = $fetchMode;
......@@ -320,11 +318,11 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$this->defaultFetchClass = $args[0];
}
if (isset($args[1])) {
$this->defaultFetchClassCtorArgs = (array) $args[1];
if (! isset($args[1])) {
return;
}
return true;
$this->defaultFetchClassCtorArgs = (array) $args[1];
}
/**
......
......@@ -26,9 +26,9 @@ interface Statement extends ResultStatement
* @param int $type Explicit data type for the parameter using the {@link \Doctrine\DBAL\ParameterType}
* constants.
*
* @return bool TRUE on success or FALSE on failure.
* @throws DriverException
*/
public function bindValue($param, $value, $type = ParameterType::STRING);
public function bindValue($param, $value, $type = ParameterType::STRING) : void;
/**
* Binds a PHP variable to a corresponding named (not supported by mysqli driver, see comment below) or question
......@@ -53,9 +53,9 @@ interface Statement extends ResultStatement
* @param int|null $length You must specify maxlength when using an OUT bind
* so that PHP allocates enough memory to hold the returned value.
*
* @return bool TRUE on success or FALSE on failure.
* @throws DriverException
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null);
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) : void;
/**
* Fetches the SQLSTATE associated with the last operation on the statement handle.
......@@ -85,7 +85,7 @@ interface Statement extends ResultStatement
* @param mixed[]|null $params An 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.
* @throws DriverException
*/
public function execute($params = null);
public function execute($params = null) : void;
}
......@@ -39,11 +39,16 @@ class Connection extends \Doctrine\DBAL\Connection
/**
* {@inheritdoc}
*/
public function connect()
public function connect() : void
{
$ret = parent::connect();
if ($ret) {
if ($this->isConnected()) {
return;
}
parent::connect();
$params = $this->getParams();
if (isset($params['portability'])) {
if ($this->getDatabasePlatform()->getName() === 'oracle') {
$params['portability'] &= self::PORTABILITY_ORACLE;
......@@ -63,7 +68,10 @@ class Connection extends \Doctrine\DBAL\Connection
$this->portability = $params['portability'];
}
if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) {
if (! isset($params['fetch_case']) || ! ($this->portability & self::PORTABILITY_FIX_CASE)) {
return;
}
if ($this->_conn instanceof PDOConnection) {
// make use of c-level support for case handling
$this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_CASE, $params['fetch_case']);
......@@ -71,10 +79,6 @@ class Connection extends \Doctrine\DBAL\Connection
$this->case = $params['fetch_case'] === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER;
}
}
}
return $ret;
}
/**
* @return int
......
......@@ -45,29 +45,29 @@ class Statement implements IteratorAggregate, DriverStatement
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) : void
{
assert($this->stmt instanceof DriverStatement);
return $this->stmt->bindParam($column, $variable, $type, $length);
$this->stmt->bindParam($column, $variable, $type, $length);
}
/**
* {@inheritdoc}
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
public function bindValue($param, $value, $type = ParameterType::STRING) : void
{
assert($this->stmt instanceof DriverStatement);
return $this->stmt->bindValue($param, $value, $type);
$this->stmt->bindValue($param, $value, $type);
}
/**
* {@inheritdoc}
*/
public function closeCursor()
public function closeCursor() : void
{
return $this->stmt->closeCursor();
$this->stmt->closeCursor();
}
/**
......@@ -101,21 +101,21 @@ class Statement implements IteratorAggregate, DriverStatement
/**
* {@inheritdoc}
*/
public function execute($params = null)
public function execute($params = null) : void
{
assert($this->stmt instanceof DriverStatement);
return $this->stmt->execute($params);
$this->stmt->execute($params);
}
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
$this->defaultFetchMode = $fetchMode;
return $this->stmt->setFetchMode($fetchMode, ...$args);
$this->stmt->setFetchMode($fetchMode, ...$args);
}
/**
......
......@@ -166,18 +166,16 @@ class PoolingShardConnection extends Connection
*
* @param string|int|null $shardId
*
* @return bool
*
* @throws ShardingException
*/
public function connect($shardId = null)
public function connect($shardId = null) : void
{
if ($shardId === null && $this->_conn) {
return false;
return;
}
if ($shardId !== null && $shardId === $this->activeShardId) {
return false;
return;
}
if ($this->getTransactionNestingLevel() > 0) {
......@@ -189,17 +187,17 @@ class PoolingShardConnection extends Connection
if (isset($this->activeConnections[$activeShardId])) {
$this->_conn = $this->activeConnections[$activeShardId];
return false;
return;
}
$this->_conn = $this->activeConnections[$activeShardId] = $this->connectTo($activeShardId);
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);
}
/**
......
......@@ -2,6 +2,7 @@
namespace Doctrine\DBAL;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
......@@ -84,16 +85,18 @@ class Statement implements IteratorAggregate, DriverStatement
* @param mixed $value The value of the parameter.
* @param mixed $type Either a PDO binding type or a DBAL mapping type name or instance.
*
* @return bool TRUE on success, FALSE on failure.
* @throws DBALException
* @throws DriverException
*/
public function bindValue($name, $value, $type = ParameterType::STRING)
public function bindValue($name, $value, $type = ParameterType::STRING) : void
{
$this->params[$name] = $value;
$this->types[$name] = $type;
if ($type !== null) {
if (is_string($type)) {
$type = Type::getType($type);
}
if ($type instanceof Type) {
$value = $type->convertToDatabaseValue($value, $this->platform);
$bindingType = $type->getBindingType();
......@@ -101,10 +104,7 @@ class Statement implements IteratorAggregate, DriverStatement
$bindingType = $type;
}
return $this->stmt->bindValue($name, $value, $bindingType);
}
return $this->stmt->bindValue($name, $value);
$this->stmt->bindValue($name, $value, $bindingType);
}
/**
......@@ -118,26 +118,22 @@ class Statement implements IteratorAggregate, DriverStatement
* @param int|null $length Must be specified when using an OUT bind
* so that PHP allocates enough memory to hold the returned value.
*
* @return bool TRUE on success, FALSE on failure.
* @throws DriverException
*/
public function bindParam($name, &$var, $type = ParameterType::STRING, $length = null)
public function bindParam($name, &$var, $type = ParameterType::STRING, $length = null) : void
{
$this->params[$name] = $var;
$this->types[$name] = $type;
return $this->stmt->bindParam($name, $var, $type, $length);
$this->stmt->bindParam($name, $var, $type, $length);
}
/**
* Executes the statement with the currently bound parameters.
*
* @param mixed[]|null $params
*
* @return bool TRUE on success, FALSE on failure.
* {@inheritDoc}
*
* @throws DBALException
*/
public function execute($params = null)
public function execute($params = null) : void
{
if (is_array($params)) {
$this->params = $params;
......@@ -147,32 +143,28 @@ class Statement implements IteratorAggregate, DriverStatement
$logger->startQuery($this->sql, $this->params, $this->types);
try {
$stmt = $this->stmt->execute($params);
$this->stmt->execute($params);
} catch (Throwable $ex) {
$logger->stopQuery();
throw DBALException::driverExceptionDuringQuery(
$this->conn->getDriver(),
$ex,
$this->sql,
$this->conn->resolveParams($this->params, $this->types)
);
} finally {
$logger->stopQuery();
}
$logger->stopQuery();
$this->params = [];
$this->types = [];
return $stmt;
}
/**
* Closes the cursor, freeing the database resources used by this statement.
*
* @return bool TRUE on success, FALSE on failure.
* {@inheritDoc}
*/
public function closeCursor()
public function closeCursor() : void
{
return $this->stmt->closeCursor();
$this->stmt->closeCursor();
}
/**
......@@ -206,9 +198,9 @@ class Statement implements IteratorAggregate, DriverStatement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, ...$args)
public function setFetchMode($fetchMode, ...$args) : void
{
return $this->stmt->setFetchMode($fetchMode, ...$args);
$this->stmt->setFetchMode($fetchMode, ...$args);
}
/**
......
......@@ -316,7 +316,9 @@ class ConnectionTest extends DbalFunctionalTestCase
$this->connection->getEventManager()
);
self::assertTrue($connection->connect());
$connection->connect();
self::assertTrue($connection->isConnected());
$connection->close();
}
......
......@@ -241,8 +241,11 @@ EOF
public function testCloseCursorOnNonExecutedStatement() : void
{
$this->expectNotToPerformAssertions();
$stmt = $this->connection->prepare('SELECT id FROM stmt_test');
self::assertTrue($stmt->closeCursor());
$stmt->closeCursor();
}
/**
......@@ -250,12 +253,23 @@ EOF
*/
public function testCloseCursorAfterCursorEnd() : void
{
$this->expectNotToPerformAssertions();
$stmt = $this->connection->prepare('SELECT name FROM stmt_test');
$stmt->execute();
$stmt->fetch();
self::assertTrue($stmt->closeCursor());
$stmt->closeCursor();
}
public function testCloseCursorAfterClosingCursor() : void
{
$this->expectNotToPerformAssertions();
$stmt = $this->connection->executeQuery('SELECT name FROM stmt_test');
$stmt->closeCursor();
$stmt->closeCursor();
}
/**
......
......@@ -45,10 +45,9 @@ class StatementTest extends DbalTestCase
$this->wrappedStmt->expects($this->once())
->method('bindParam')
->with($column, $variable, $type, $length)
->will($this->returnValue(true));
->with($column, $variable, $type, $length);
self::assertTrue($this->stmt->bindParam($column, $variable, $type, $length));
$this->stmt->bindParam($column, $variable, $type, $length);
}
public function testBindValue() : void
......@@ -59,19 +58,17 @@ class StatementTest extends DbalTestCase
$this->wrappedStmt->expects($this->once())
->method('bindValue')
->with($param, $value, $type)
->will($this->returnValue(true));
->with($param, $value, $type);
self::assertTrue($this->stmt->bindValue($param, $value, $type));
$this->stmt->bindValue($param, $value, $type);
}
public function testCloseCursor() : void
{
$this->wrappedStmt->expects($this->once())
->method('closeCursor')
->will($this->returnValue(true));
->method('closeCursor');
self::assertTrue($this->stmt->closeCursor());
$this->stmt->closeCursor();
}
public function testColumnCount() : void
......@@ -116,10 +113,9 @@ class StatementTest extends DbalTestCase
$this->wrappedStmt->expects($this->once())
->method('execute')
->with($params)
->will($this->returnValue(true));
->with($params);
self::assertTrue($this->stmt->execute($params));
$this->stmt->execute($params);
}
public function testSetFetchMode() : void
......@@ -137,7 +133,7 @@ class StatementTest extends DbalTestCase
$re->setAccessible(true);
self::assertSame(FetchMode::MIXED, $re->getValue($this->stmt));
self::assertTrue($this->stmt->setFetchMode($fetchMode, $arg1, $arg2));
$this->stmt->setFetchMode($fetchMode, $arg1, $arg2);
self::assertSame($fetchMode, $re->getValue($this->stmt));
}
......
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