[DBAL-2958] Replaced extension of \PDOStatement with a composition to avoid...

[DBAL-2958] Replaced extension of \PDOStatement with a composition to avoid having to replicate the \PDOStatement interface in ResultStatement
parent 11106683
......@@ -7,7 +7,6 @@ use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\FetchMode;
use InvalidArgumentException;
use IteratorAggregate;
use PDO;
use function array_merge;
use function array_values;
use function count;
......@@ -59,9 +58,9 @@ class ArrayStatement implements IteratorAggregate, ResultStatement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
public function setFetchMode($fetchMode, ...$args)
{
if ($arg2 !== null || $arg3 !== null) {
if (count($args) > 0) {
throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode()');
}
......@@ -83,7 +82,7 @@ class ArrayStatement implements IteratorAggregate, ResultStatement
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
if (! isset($this->data[$this->num])) {
return false;
......@@ -114,10 +113,10 @@ class ArrayStatement implements IteratorAggregate, ResultStatement
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
$rows = [];
while ($row = $this->fetch($fetchMode)) {
while ($row = $this->fetch($fetchMode, ...$args)) {
$rows[] = $row;
}
......
......@@ -9,7 +9,6 @@ use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\FetchMode;
use InvalidArgumentException;
use IteratorAggregate;
use PDO;
use function array_merge;
use function array_values;
use function assert;
......@@ -105,7 +104,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
public function setFetchMode($fetchMode, ...$args)
{
$this->defaultFetchMode = $fetchMode;
......@@ -125,7 +124,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
if ($this->data === null) {
$this->data = [];
......@@ -165,9 +164,9 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
$data = $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs);
$data = $this->statement->fetchAll($fetchMode, ...$args);
if ($fetchMode === FetchMode::COLUMN) {
foreach ($data as $key => $value) {
......
......@@ -7,7 +7,6 @@ use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use PDO;
use ReflectionClass;
use ReflectionObject;
use ReflectionProperty;
......@@ -19,6 +18,7 @@ use const DB2_LONG;
use const DB2_PARAM_FILE;
use const DB2_PARAM_IN;
use function array_change_key_case;
use function count;
use function db2_bind_param;
use function db2_execute;
use function db2_fetch_array;
......@@ -32,8 +32,6 @@ use function db2_stmt_error;
use function db2_stmt_errormsg;
use function error_get_last;
use function fclose;
use function func_get_args;
use function func_num_args;
use function fwrite;
use function gettype;
use function is_object;
......@@ -229,11 +227,17 @@ class DB2Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
public function setFetchMode($fetchMode, ...$args)
{
$this->defaultFetchMode = $fetchMode;
$this->defaultFetchClass = $arg2 ?: $this->defaultFetchClass;
$this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs;
if (isset($args[0])) {
$this->defaultFetchClass = $args[0];
}
if (isset($args[1])) {
$this->defaultFetchClassCtorArgs = (array) $args[1];
}
return true;
}
......@@ -249,7 +253,7 @@ class DB2Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
......@@ -272,10 +276,9 @@ class DB2Statement implements IteratorAggregate, Statement
$className = $this->defaultFetchClass;
$ctorArgs = $this->defaultFetchClassCtorArgs;
if (func_num_args() >= 2) {
$args = func_get_args();
$className = $args[1];
$ctorArgs = $args[2] ?? [];
if (count($args) > 0) {
$className = $args[0];
$ctorArgs = $args[1] ?? [];
}
$result = db2_fetch_object($this->stmt);
......@@ -300,13 +303,13 @@ class DB2Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
$rows = [];
switch ($fetchMode) {
case FetchMode::CUSTOM_OBJECT:
while (($row = $this->fetch(...func_get_args())) !== false) {
while (($row = $this->fetch($fetchMode, ...$args)) !== false) {
$rows[] = $row;
}
break;
......
......@@ -10,7 +10,6 @@ use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use mysqli;
use mysqli_stmt;
use PDO;
use function array_combine;
use function array_fill;
use function assert;
......@@ -303,7 +302,7 @@ class MysqliStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
......@@ -353,7 +352,7 @@ class MysqliStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
......@@ -436,7 +435,7 @@ class MysqliStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
public function setFetchMode($fetchMode, ...$args)
{
$this->_defaultFetchMode = $fetchMode;
......
......@@ -8,7 +8,6 @@ use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use InvalidArgumentException;
use IteratorAggregate;
use PDO;
use const OCI_ASSOC;
use const OCI_B_BIN;
use const OCI_B_BLOB;
......@@ -407,7 +406,7 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
public function setFetchMode($fetchMode, ...$args)
{
$this->_defaultFetchMode = $fetchMode;
......@@ -425,7 +424,7 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
......@@ -456,7 +455,7 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
......
......@@ -25,7 +25,6 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
{
try {
parent::__construct($dsn, (string) $user, (string) $password, (array) $options);
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (\PDOException $exception) {
throw new PDOException($exception);
......@@ -58,7 +57,9 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
public function prepare($prepareString, $driverOptions = [])
{
try {
return parent::prepare($prepareString, $driverOptions);
return $this->createStatement(
parent::prepare($prepareString, $driverOptions)
);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......@@ -75,7 +76,7 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
$stmt = parent::query(...$args);
assert($stmt instanceof \PDOStatement);
return $stmt;
return $this->createStatement($stmt);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......@@ -112,4 +113,12 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
{
return false;
}
/**
* Creates a wrapped statement
*/
private function createStatement(\PDOStatement $stmt) : PDOStatement
{
return new PDOStatement($stmt);
}
}
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use InvalidArgumentException;
use IteratorAggregate;
use PDO;
use function array_slice;
use function assert;
......@@ -15,7 +16,7 @@ use function is_array;
* The PDO implementation of the Statement interface.
* Used by all PDO-based drivers.
*/
class PDOStatement extends \PDOStatement implements Statement
class PDOStatement implements IteratorAggregate, Statement
{
private const PARAM_TYPE_MAP = [
ParameterType::NULL => PDO::PARAM_NULL,
......@@ -35,34 +36,23 @@ class PDOStatement extends \PDOStatement implements Statement
FetchMode::CUSTOM_OBJECT => PDO::FETCH_CLASS,
];
/**
* Protected constructor.
*/
protected function __construct()
/** @var \PDOStatement */
private $stmt;
public function __construct(\PDOStatement $stmt)
{
$this->stmt = $stmt;
}
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
public function setFetchMode($fetchMode, ...$args)
{
$fetchMode = $this->convertFetchMode($fetchMode);
// This thin wrapper is necessary to shield against the weird signature
// of PDOStatement::setFetchMode(): even if the second and third
// parameters are optional, PHP will not let us remove it from this
// declaration.
try {
if ($arg2 === null && $arg3 === null) {
return parent::setFetchMode($fetchMode);
}
if ($arg3 === null) {
return parent::setFetchMode($fetchMode, $arg2);
}
return parent::setFetchMode($fetchMode, $arg2, $arg3);
return $this->stmt->setFetchMode($fetchMode, ...$args);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......@@ -76,7 +66,7 @@ class PDOStatement extends \PDOStatement implements Statement
$type = $this->convertParamType($type);
try {
return parent::bindValue($param, $value, $type);
return $this->stmt->bindValue($param, $value, $type);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......@@ -90,7 +80,7 @@ class PDOStatement extends \PDOStatement implements Statement
$type = $this->convertParamType($type);
try {
return parent::bindParam($column, $variable, $type, ...array_slice(func_get_args(), 3));
return $this->stmt->bindParam($column, $variable, $type, ...array_slice(func_get_args(), 3));
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......@@ -102,7 +92,7 @@ class PDOStatement extends \PDOStatement implements Statement
public function closeCursor()
{
try {
return parent::closeCursor();
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.
......@@ -110,31 +100,52 @@ class PDOStatement extends \PDOStatement implements Statement
}
}
public function columnCount()
{
return $this->stmt->columnCount();
}
public function errorCode()
{
return $this->stmt->errorCode();
}
public function errorInfo()
{
return $this->stmt->errorInfo();
}
/**
* {@inheritdoc}
*/
public function execute($params = null)
{
try {
return parent::execute($params);
return $this->stmt->execute($params);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
}
public function rowCount()
{
return $this->stmt->rowCount();
}
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
$args = func_get_args();
if (isset($args[0])) {
$args[0] = $this->convertFetchMode($args[0]);
try {
if ($fetchMode === null) {
return $this->stmt->fetch();
}
try {
return parent::fetch(...$args);
return $this->stmt->fetch(
$this->convertFetchMode($fetchMode),
...$args
);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......@@ -143,32 +154,24 @@ class PDOStatement extends \PDOStatement implements Statement
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
$args = func_get_args();
if (isset($args[0])) {
$args[0] = $this->convertFetchMode($args[0]);
}
if ($fetchMode === null && $fetchArgument === null && $ctorArgs === null) {
$args = [];
} elseif ($fetchArgument === null && $ctorArgs === null) {
$args = [$fetchMode];
} elseif ($ctorArgs === null) {
$args = [$fetchMode, $fetchArgument];
try {
if ($fetchMode === null) {
$data = $this->stmt->fetchAll();
} else {
$args = [$fetchMode, $fetchArgument, $ctorArgs];
$data = $this->stmt->fetchAll(
$this->convertFetchMode($fetchMode),
...$args
);
}
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
try {
$data = parent::fetchAll(...$args);
assert(is_array($data));
return $data;
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
}
/**
......@@ -177,7 +180,7 @@ class PDOStatement extends \PDOStatement implements Statement
public function fetchColumn($columnIndex = 0)
{
try {
return parent::fetchColumn($columnIndex);
return $this->stmt->fetchColumn($columnIndex);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......@@ -210,4 +213,12 @@ class PDOStatement extends \PDOStatement implements Statement
return self::FETCH_MODE_MAP[$fetchMode];
}
/**
* {@inheritdoc}
*/
public function getIterator()
{
yield from $this->stmt;
}
}
......@@ -2,7 +2,6 @@
namespace Doctrine\DBAL\Driver;
use PDO;
use Traversable;
/**
......@@ -29,13 +28,13 @@ interface ResultStatement extends Traversable
/**
* Sets the fetch mode to use while iterating this statement.
*
* @param int $fetchMode The fetch mode must be one of the {@link \Doctrine\DBAL\FetchMode} constants.
* @param mixed $arg2
* @param mixed $arg3
* @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, $arg2 = null, $arg3 = null);
public function setFetchMode($fetchMode, ...$args);
/**
* Returns the next row of a result set.
......@@ -43,26 +42,12 @@ interface ResultStatement extends Traversable
* @param int|null $fetchMode Controls how the next row will be returned to the caller.
* The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants,
* defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}.
* @param int $cursorOrientation For a ResultStatement object representing a scrollable cursor,
* this value determines which row will be returned to the caller.
* This value must be one of the \PDO::FETCH_ORI_* constants,
* defaulting to \PDO::FETCH_ORI_NEXT. To request a scrollable
* cursor for your ResultStatement object, you must set the \PDO::ATTR_CURSOR
* attribute to \PDO::CURSOR_SCROLL when you prepare the SQL statement with
* \PDO::prepare().
* @param int $cursorOffset For a ResultStatement object representing a scrollable cursor for which the
* cursorOrientation parameter is set to \PDO::FETCH_ORI_ABS, this value
* specifies the absolute number of the row in the result set that shall be
* fetched.
* For a ResultStatement object representing a scrollable cursor for which the
* cursorOrientation parameter is set to \PDO::FETCH_ORI_REL, this value
* specifies the row to fetch relative to the cursor position before
* ResultStatement::fetch() was called.
* @param mixed ...$args Optional mode-specific arguments (see {@link self::fetchAll()}).
*
* @return mixed The return value of this method on success depends on the fetch mode. In all cases, FALSE is
* returned on failure.
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0);
public function fetch($fetchMode = null, ...$args);
/**
* Returns an array containing all of the result set rows.
......@@ -70,21 +55,16 @@ interface ResultStatement extends Traversable
* @param int|null $fetchMode Controls how the next row will be returned to the caller.
* The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants,
* defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}.
* @param int|null $fetchArgument This argument has a different meaning depending on the value of the $fetchMode parameter:
* * {@link \Doctrine\DBAL\FetchMode::COLUMN}:
* Returns the indicated 0-indexed column.
* * {@link \Doctrine\DBAL\FetchMode::CUSTOM_OBJECT}:
* Returns instances of the specified class, mapping the columns of each row
* to named properties in the class.
* * \PDO::FETCH_FUNC: Returns the results of calling the specified function, using each row's
* columns as parameters in the call.
* @param mixed[]|null $ctorArgs Controls how the next row will be returned to the caller.
* The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants,
* defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}.
* @param mixed ...$args Optional mode-specific arguments. Supported modes:
* * {@link \Doctrine\DBAL\FetchMode::COLUMN}
* 1. The 0-indexed column to be returned.
* * {@link \Doctrine\DBAL\FetchMode::CUSTOM_OBJECT}
* 1. The class name of the object to be created,
* 2. Array of constructor arguments
*
* @return mixed[]
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null);
public function fetchAll($fetchMode = null, ...$args);
/**
* Returns a single column from the next row of a result set or FALSE if there are no more rows.
......
......@@ -7,14 +7,12 @@ use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use PDO;
use ReflectionClass;
use ReflectionObject;
use stdClass;
use const SASQL_BOTH;
use function array_key_exists;
use function func_get_args;
use function func_num_args;
use function count;
use function gettype;
use function is_array;
use function is_int;
......@@ -199,7 +197,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*
* @throws SQLAnywhereException
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
if (! is_resource($this->result)) {
return false;
......@@ -221,10 +219,9 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
$className = $this->defaultFetchClass;
$ctorArgs = $this->defaultFetchClassCtorArgs;
if (func_num_args() >= 2) {
$args = func_get_args();
$className = $args[1];
$ctorArgs = $args[2] ?? [];
if (count($args) > 0) {
$className = $args[0];
$ctorArgs = $args[1] ?? [];
}
$result = sasql_fetch_object($this->result);
......@@ -249,13 +246,13 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
$rows = [];
switch ($fetchMode) {
case FetchMode::CUSTOM_OBJECT:
while (($row = $this->fetch(...func_get_args())) !== false) {
while (($row = $this->fetch($fetchMode, ...$args)) !== false) {
$rows[] = $row;
}
break;
......@@ -308,11 +305,19 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
public function setFetchMode($fetchMode, ...$args)
{
$this->defaultFetchMode = $fetchMode;
$this->defaultFetchClass = $arg2 ?: $this->defaultFetchClass;
$this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs;
if (isset($args[0])) {
$this->defaultFetchClass = $args[0];
}
if (isset($args[1])) {
$this->defaultFetchClassCtorArgs = (array) $args[1];
}
return true;
}
/**
......
......@@ -7,7 +7,6 @@ use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use PDO;
use const SQLSRV_ENC_BINARY;
use const SQLSRV_ERR_ERRORS;
use const SQLSRV_FETCH_ASSOC;
......@@ -16,7 +15,6 @@ use const SQLSRV_FETCH_NUMERIC;
use const SQLSRV_PARAM_IN;
use function array_key_exists;
use function count;
use function func_get_args;
use function in_array;
use function is_int;
use function is_numeric;
......@@ -313,11 +311,17 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
public function setFetchMode($fetchMode, ...$args)
{
$this->defaultFetchMode = $fetchMode;
$this->defaultFetchClass = $arg2 ?: $this->defaultFetchClass;
$this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs;
if (isset($args[0])) {
$this->defaultFetchClass = $args[0];
}
if (isset($args[1])) {
$this->defaultFetchClassCtorArgs = (array) $args[1];
}
return true;
}
......@@ -335,7 +339,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*
* @throws SQLSrvException
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
......@@ -343,7 +347,6 @@ class SQLSrvStatement implements IteratorAggregate, Statement
return false;
}
$args = func_get_args();
$fetchMode = $fetchMode ?: $this->defaultFetchMode;
if ($fetchMode === FetchMode::COLUMN) {
......@@ -358,9 +361,9 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$className = $this->defaultFetchClass;
$ctorArgs = $this->defaultFetchClassCtorArgs;
if (count($args) >= 2) {
$className = $args[1];
$ctorArgs = $args[2] ?? [];
if (count($args) > 0) {
$className = $args[0];
$ctorArgs = $args[1] ?? [];
}
return sqlsrv_fetch_object($this->stmt, $className, $ctorArgs) ?: false;
......@@ -372,13 +375,13 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
$rows = [];
switch ($fetchMode) {
case FetchMode::CUSTOM_OBJECT:
while (($row = $this->fetch(...func_get_args())) !== false) {
while (($row = $this->fetch($fetchMode, ...$args)) !== false) {
$rows[] = $row;
}
break;
......
......@@ -8,7 +8,6 @@ use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use PDO;
use function array_change_key_case;
use function assert;
use function is_string;
......@@ -112,11 +111,11 @@ class Statement implements IteratorAggregate, DriverStatement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, $arg1 = null, $arg2 = null)
public function setFetchMode($fetchMode, ...$args)
{
$this->defaultFetchMode = $fetchMode;
return $this->stmt->setFetchMode($fetchMode, $arg1, $arg2);
return $this->stmt->setFetchMode($fetchMode, ...$args);
}
/**
......@@ -130,11 +129,11 @@ class Statement implements IteratorAggregate, DriverStatement
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
$fetchMode = $fetchMode ?: $this->defaultFetchMode;
$row = $this->stmt->fetch($fetchMode);
$row = $this->stmt->fetch($fetchMode, ...$args);
$iterateRow = $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM);
$fixCase = $this->case !== null
......@@ -149,15 +148,11 @@ class Statement implements IteratorAggregate, DriverStatement
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
$fetchMode = $fetchMode ?: $this->defaultFetchMode;
if ($fetchArgument) {
$rows = $this->stmt->fetchAll($fetchMode, $fetchArgument);
} else {
$rows = $this->stmt->fetchAll($fetchMode);
}
$rows = $this->stmt->fetchAll($fetchMode, ...$args);
$iterateRow = $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM);
$fixCase = $this->case !== null
......
......@@ -6,7 +6,6 @@ use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use IteratorAggregate;
use PDO;
use Throwable;
use function is_array;
use function is_string;
......@@ -213,17 +212,9 @@ class Statement implements IteratorAggregate, DriverStatement
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
public function setFetchMode($fetchMode, ...$args)
{
if ($arg2 === null) {
return $this->stmt->setFetchMode($fetchMode);
}
if ($arg3 === null) {
return $this->stmt->setFetchMode($fetchMode, $arg2);
}
return $this->stmt->setFetchMode($fetchMode, $arg2, $arg3);
return $this->stmt->setFetchMode($fetchMode, ...$args);
}
/**
......@@ -239,21 +230,17 @@ class Statement implements IteratorAggregate, DriverStatement
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
return $this->stmt->fetch($fetchMode);
return $this->stmt->fetch($fetchMode, ...$args);
}
/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
if ($fetchArgument) {
return $this->stmt->fetchAll($fetchMode, $fetchArgument);
}
return $this->stmt->fetchAll($fetchMode);
return $this->stmt->fetchAll($fetchMode, ...$args);
}
/**
......
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