Replace the concept of the statement fetch modes with an explicit API

parent 67944fce
# Upgrade to 3.0 # Upgrade to 3.0
## Removed `FetchMode` and the corresponding methods
1. The `FetchMode` class and the `setFetchMode()` method of the `Connection` and `Statement` interfaces are removed.
2. The `Statement::fetch()` method is replaced with `fetchNumeric()`, `fetchAssociative()` and `fetchOne()`.
3. The `Statement::fetchAll()` method is replaced with `fetchAllNumeric()`, `fetchAllAssociative()` and `fechColumn()`.
4. The `Statement::fetchColumn()` method is replaced with `fetchOne()`.
5. The `Connection::fetchArray()` and `fetchAssoc()` methods are replaced with `fetchNumeric()` and `fetchAssociative()` respectively.
6. The `StatementIterator` class is removed. The usage of a `Statement` object as `Traversable` is no longer possible. Use `iterateNumeric()`, `iterateAssociative()` and `iterateColumn()` instead.
7. Fetching data in mixed mode (former `FetchMode::MIXED`) is no longer possible.
## BC BREAK: Dropped handling of one-based numeric arrays of parameters in `Statement::execute()` ## BC BREAK: Dropped handling of one-based numeric arrays of parameters in `Statement::execute()`
The statement implementations no longer detect whether `$params` is a zero- or one-based array. A zero-based numeric array is expected. The statement implementations no longer detect whether `$params` is a zero- or one-based array. A zero-based numeric array is expected.
......
...@@ -42,7 +42,7 @@ object is closed: ...@@ -42,7 +42,7 @@ object is closed:
<?php <?php
$stmt = $conn->executeCacheQuery($query, $params, $types, new QueryCacheProfile(0, "some key")); $stmt = $conn->executeCacheQuery($query, $params, $types, new QueryCacheProfile(0, "some key"));
$data = $stmt->fetchAll(); $data = $stmt->fetchAllAssociative();
$stmt->closeCursor(); // at this point the result is cached $stmt->closeCursor(); // at this point the result is cached
.. warning:: .. warning::
......
...@@ -41,7 +41,7 @@ the query until there are no more rows: ...@@ -41,7 +41,7 @@ the query until there are no more rows:
<?php <?php
while ($row = $stmt->fetch()) { while (($row = $stmt->fetchAssociative()) !== false) {
echo $row['headline']; echo $row['headline'];
} }
...@@ -308,7 +308,7 @@ Prepare a given SQL statement and return the ...@@ -308,7 +308,7 @@ Prepare a given SQL statement and return the
<?php <?php
$statement = $conn->prepare('SELECT * FROM user'); $statement = $conn->prepare('SELECT * FROM user');
$statement->execute(); $statement->execute();
$users = $statement->fetchAll(); $users = $statement->fetchAllAssociative();
/* /*
array( array(
...@@ -346,7 +346,7 @@ parameters to the execute method, then returning the statement: ...@@ -346,7 +346,7 @@ parameters to the execute method, then returning the statement:
<?php <?php
$statement = $conn->executeQuery('SELECT * FROM user WHERE username = ?', array('jwage')); $statement = $conn->executeQuery('SELECT * FROM user WHERE username = ?', array('jwage'));
$user = $statement->fetch(); $user = $statement->fetchAssociative();
/* /*
array( array(
...@@ -360,15 +360,15 @@ to perform necessary type conversions between actual input ...@@ -360,15 +360,15 @@ to perform necessary type conversions between actual input
parameters and expected database values. See the parameters and expected database values. See the
:ref:`Types <mappingMatrix>` section for more information. :ref:`Types <mappingMatrix>` section for more information.
fetchAll() fetchAllAssociative()
~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
Execute the query and fetch all results into an array: Execute the query and fetch all results into an array:
.. code-block:: php .. code-block:: php
<?php <?php
$users = $conn->fetchAll('SELECT * FROM user'); $users = $conn->fetchAllAssociative('SELECT * FROM user');
/* /*
array( array(
...@@ -379,15 +379,15 @@ Execute the query and fetch all results into an array: ...@@ -379,15 +379,15 @@ Execute the query and fetch all results into an array:
) )
*/ */
fetchArray() fetchNumeric()
~~~~~~~~~~~~ ~~~~~~~~~~~~~~
Numeric index retrieval of first result row of the given query: Numeric index retrieval of first result row of the given query:
.. code-block:: php .. code-block:: php
<?php <?php
$user = $conn->fetchArray('SELECT * FROM user WHERE username = ?', array('jwage')); $user = $conn->fetchNumeric('SELECT * FROM user WHERE username = ?', array('jwage'));
/* /*
array( array(
...@@ -396,26 +396,26 @@ Numeric index retrieval of first result row of the given query: ...@@ -396,26 +396,26 @@ Numeric index retrieval of first result row of the given query:
) )
*/ */
fetchColumn() fetchOne()
~~~~~~~~~~~~~ ~~~~~~~~~~
Retrieve only the given column of the first result row. Retrieve only the value of the first column of the first result row.
.. code-block:: php .. code-block:: php
<?php <?php
$username = $conn->fetchColumn('SELECT username FROM user WHERE id = ?', array(1), 0); $username = $conn->fetchOne('SELECT username FROM user WHERE id = ?', array(1), 0);
echo $username; // jwage echo $username; // jwage
fetchAssoc() fetchAssociative()
~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
Retrieve assoc row of the first result row. Retrieve associative array of the first result row.
.. code-block:: php .. code-block:: php
<?php <?php
$user = $conn->fetchAssoc('SELECT * FROM user WHERE username = ?', array('jwage')); $user = $conn->fetchAssociative('SELECT * FROM user WHERE username = ?', array('jwage'));
/* /*
array( array(
'username' => 'jwage', 'username' => 'jwage',
......
...@@ -2,19 +2,13 @@ ...@@ -2,19 +2,13 @@
namespace Doctrine\DBAL\Cache; namespace Doctrine\DBAL\Cache;
use ArrayIterator;
use Doctrine\DBAL\Driver\FetchUtils; use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use InvalidArgumentException;
use IteratorAggregate;
use function array_merge;
use function array_values; use function array_values;
use function count; use function count;
use function reset; use function reset;
class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompatibleResultStatement class ArrayStatement implements ResultStatement
{ {
/** @var mixed[] */ /** @var mixed[] */
private $data; private $data;
...@@ -25,9 +19,6 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa ...@@ -25,9 +19,6 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa
/** @var int */ /** @var int */
private $num = 0; private $num = 0;
/** @var int */
private $defaultFetchMode = FetchMode::MIXED;
/** /**
* @param mixed[] $data * @param mixed[] $data
*/ */
...@@ -59,97 +50,12 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa ...@@ -59,97 +50,12 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa
return $this->columnCount; return $this->columnCount;
} }
/**
* {@inheritdoc}
*
* @deprecated Use one of the fetch- or iterate-related methods.
*/
public function setFetchMode($fetchMode)
{
$this->defaultFetchMode = $fetchMode;
return true;
}
/**
* {@inheritdoc}
*
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
*/
public function getIterator()
{
$data = $this->fetchAll();
return new ArrayIterator($data);
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*/
public function fetch($fetchMode = null)
{
if (! isset($this->data[$this->num])) {
return false;
}
$row = $this->data[$this->num++];
$fetchMode = $fetchMode ?? $this->defaultFetchMode;
if ($fetchMode === FetchMode::ASSOCIATIVE) {
return $row;
}
if ($fetchMode === FetchMode::NUMERIC) {
return array_values($row);
}
if ($fetchMode === FetchMode::MIXED) {
return array_merge($row, array_values($row));
}
if ($fetchMode === FetchMode::COLUMN) {
return reset($row);
}
throw new InvalidArgumentException('Invalid fetch-style given for fetching result.');
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
*/
public function fetchAll($fetchMode = null)
{
$rows = [];
while ($row = $this->fetch($fetchMode)) {
$rows[] = $row;
}
return $rows;
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchOne() instead.
*/
public function fetchColumn()
{
$row = $this->fetch(FetchMode::NUMERIC);
// TODO: verify that return false is the correct behavior
return $row[0] ?? false;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetchNumeric() public function fetchNumeric()
{ {
$row = $this->doFetch(); $row = $this->fetch();
if ($row === false) { if ($row === false) {
return false; return false;
...@@ -163,7 +69,7 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa ...@@ -163,7 +69,7 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa
*/ */
public function fetchAssociative() public function fetchAssociative()
{ {
return $this->doFetch(); return $this->fetch();
} }
/** /**
...@@ -171,7 +77,7 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa ...@@ -171,7 +77,7 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa
*/ */
public function fetchOne() public function fetchOne()
{ {
$row = $this->doFetch(); $row = $this->fetch();
if ($row === false) { if ($row === false) {
return false; return false;
...@@ -196,10 +102,18 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa ...@@ -196,10 +102,18 @@ class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompa
return FetchUtils::fetchAllAssociative($this); return FetchUtils::fetchAllAssociative($this);
} }
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
{
return FetchUtils::fetchColumn($this);
}
/** /**
* @return mixed|false * @return mixed|false
*/ */
private function doFetch() private function fetch()
{ {
if (! isset($this->data[$this->num])) { if (! isset($this->data[$this->num])) {
return false; return false;
......
...@@ -2,20 +2,12 @@ ...@@ -2,20 +2,12 @@
namespace Doctrine\DBAL\Cache; namespace Doctrine\DBAL\Cache;
use ArrayIterator;
use Doctrine\Common\Cache\Cache; use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\FetchUtils; use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement; use function array_map;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use InvalidArgumentException;
use IteratorAggregate;
use function array_merge;
use function array_values; use function array_values;
use function assert;
use function reset;
/** /**
* Cache statement for SQL results. * Cache statement for SQL results.
...@@ -30,7 +22,7 @@ use function reset; ...@@ -30,7 +22,7 @@ use function reset;
* Also you have to realize that the cache will load the whole result into memory at once to ensure 2. * Also you have to realize that the cache will load the whole result into memory at once to ensure 2.
* This means that the memory usage for cached results might increase by using this feature. * This means that the memory usage for cached results might increase by using this feature.
*/ */
class ResultCacheStatement implements IteratorAggregate, ResultStatement, ForwardCompatibleResultStatement class ResultCacheStatement implements ResultStatement
{ {
/** @var Cache */ /** @var Cache */
private $resultCache; private $resultCache;
...@@ -54,12 +46,9 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar ...@@ -54,12 +46,9 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar
*/ */
private $emptied = false; private $emptied = false;
/** @var mixed[] */ /** @var array<int,array<string,mixed>> */
private $data; private $data;
/** @var int */
private $defaultFetchMode = FetchMode::MIXED;
/** /**
* @param string $cacheKey * @param string $cacheKey
* @param string $realKey * @param string $realKey
...@@ -105,112 +94,12 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar ...@@ -105,112 +94,12 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar
return $this->statement->columnCount(); return $this->statement->columnCount();
} }
/**
* {@inheritdoc}
*
* @deprecated Use one of the fetch- or iterate-related methods.
*/
public function setFetchMode($fetchMode)
{
$this->defaultFetchMode = $fetchMode;
return true;
}
/**
* {@inheritdoc}
*
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
*/
public function getIterator()
{
$data = $this->fetchAll();
return new ArrayIterator($data);
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*/
public function fetch($fetchMode = null)
{
if ($this->data === null) {
$this->data = [];
}
$row = $this->statement->fetch(FetchMode::ASSOCIATIVE);
if ($row !== false) {
$this->data[] = $row;
$fetchMode = $fetchMode ?? $this->defaultFetchMode;
if ($fetchMode === FetchMode::ASSOCIATIVE) {
return $row;
}
if ($fetchMode === FetchMode::NUMERIC) {
return array_values($row);
}
if ($fetchMode === FetchMode::MIXED) {
return array_merge($row, array_values($row));
}
if ($fetchMode === FetchMode::COLUMN) {
return reset($row);
}
throw new InvalidArgumentException('Invalid fetch-style given for caching result.');
}
$this->emptied = true;
return false;
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
*/
public function fetchAll($fetchMode = null)
{
$data = $this->statement->fetchAll($fetchMode);
if ($fetchMode === FetchMode::COLUMN) {
foreach ($data as $key => $value) {
$data[$key] = [$value];
}
}
$this->data = $data;
$this->emptied = true;
return $this->data;
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchOne() instead.
*/
public function fetchColumn()
{
$row = $this->fetch(FetchMode::NUMERIC);
// TODO: verify that return false is the correct behavior
return $row[0] ?? false;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetchNumeric() public function fetchNumeric()
{ {
$row = $this->doFetch(); $row = $this->fetch();
if ($row === false) { if ($row === false) {
return false; return false;
...@@ -224,7 +113,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar ...@@ -224,7 +113,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar
*/ */
public function fetchAssociative() public function fetchAssociative()
{ {
return $this->doFetch(); return $this->fetch();
} }
/** /**
...@@ -240,13 +129,11 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar ...@@ -240,13 +129,11 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar
*/ */
public function fetchAllNumeric() : array public function fetchAllNumeric() : array
{ {
if ($this->statement instanceof ForwardCompatibleResultStatement) { $this->store(
$data = $this->statement->fetchAllAssociative(); $this->statement->fetchAllAssociative()
} else { );
$data = $this->statement->fetchAll(FetchMode::ASSOCIATIVE);
}
return $this->store($data); return array_map('array_values', $this->data);
} }
/** /**
...@@ -254,31 +141,19 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar ...@@ -254,31 +141,19 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar
*/ */
public function fetchAllAssociative() : array public function fetchAllAssociative() : array
{ {
if ($this->statement instanceof ForwardCompatibleResultStatement) { $this->store(
$data = $this->statement->fetchAllAssociative(); $this->statement->fetchAllAssociative()
} else { );
$data = $this->statement->fetchAll(FetchMode::ASSOCIATIVE);
}
return $this->store($data); return $this->data;
} }
/** /**
* Returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement * {@inheritdoc}
* executed by the corresponding object.
*
* If the last SQL statement executed by the associated Statement object was a SELECT statement,
* some databases may return the number of rows returned by that statement. However,
* this behaviour is not guaranteed for all databases and should not be
* relied on for portable applications.
*
* @return int The number of rows.
*/ */
public function rowCount() : int public function fetchColumn() : array
{ {
assert($this->statement instanceof Statement); return FetchUtils::fetchColumn($this);
return $this->statement->rowCount();
} }
/** /**
...@@ -286,17 +161,13 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar ...@@ -286,17 +161,13 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar
* *
* @throws DriverException * @throws DriverException
*/ */
private function doFetch() private function fetch()
{ {
if ($this->data === null) { if ($this->data === null) {
$this->data = []; $this->data = [];
} }
if ($this->statement instanceof ForwardCompatibleResultStatement) { $row = $this->statement->fetchAssociative();
$row = $this->statement->fetchAssociative();
} else {
$row = $this->statement->fetch(FetchMode::ASSOCIATIVE);
}
if ($row !== false) { if ($row !== false) {
$this->data[] = $row; $this->data[] = $row;
...@@ -310,19 +181,11 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar ...@@ -310,19 +181,11 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Forwar
} }
/** /**
* @param array<int,array<mixed>> $data * @param array<int,array<string,mixed>> $data
*
* @return array<int,array<mixed>>
*/ */
private function store(array $data) : array private function store(array $data) : void
{ {
foreach ($data as $key => $value) {
$data[$key] = [$value];
}
$this->data = $data; $this->data = $data;
$this->emptied = true; $this->emptied = true;
return $this->data;
} }
} }
This diff is collapsed.
...@@ -352,8 +352,6 @@ class MasterSlaveConnection extends Connection ...@@ -352,8 +352,6 @@ class MasterSlaveConnection extends Connection
$statement = $this->_conn->query($sql); $statement = $this->_conn->query($sql);
$statement->setFetchMode($this->defaultFetchMode);
if ($logger !== null) { if ($logger !== null) {
$logger->stopQuery(); $logger->stopQuery();
} }
......
...@@ -196,7 +196,7 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA ...@@ -196,7 +196,7 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA
{ {
$params = $conn->getParams(); $params = $conn->getParams();
return $params['dbname'] ?? $conn->query('SELECT DATABASE()')->fetchColumn(); return $params['dbname'] ?? $conn->query('SELECT DATABASE()')->fetchOne();
} }
/** /**
......
...@@ -108,7 +108,7 @@ abstract class AbstractPostgreSQLDriver implements ExceptionConverterDriver, Ver ...@@ -108,7 +108,7 @@ abstract class AbstractPostgreSQLDriver implements ExceptionConverterDriver, Ver
{ {
$params = $conn->getParams(); $params = $conn->getParams();
return $params['dbname'] ?? $conn->query('SELECT CURRENT_DATABASE()')->fetchColumn(); return $params['dbname'] ?? $conn->query('SELECT CURRENT_DATABASE()')->fetchOne();
} }
/** /**
......
...@@ -105,7 +105,7 @@ abstract class AbstractSQLAnywhereDriver implements ExceptionConverterDriver, Ve ...@@ -105,7 +105,7 @@ abstract class AbstractSQLAnywhereDriver implements ExceptionConverterDriver, Ve
{ {
$params = $conn->getParams(); $params = $conn->getParams();
return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchColumn(); return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchOne();
} }
/** /**
......
...@@ -19,7 +19,7 @@ abstract class AbstractSQLServerDriver implements Driver ...@@ -19,7 +19,7 @@ abstract class AbstractSQLServerDriver implements Driver
{ {
$params = $conn->getParams(); $params = $conn->getParams();
return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchColumn(); return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchOne();
} }
/** /**
......
...@@ -4,8 +4,6 @@ declare(strict_types=1); ...@@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement;
/** /**
* @internal * @internal
*/ */
...@@ -58,4 +56,20 @@ final class FetchUtils ...@@ -58,4 +56,20 @@ final class FetchUtils
return $rows; return $rows;
} }
/**
* @return array<int,mixed>
*
* @throws DriverException
*/
public static function fetchColumn(ResultStatement $stmt) : array
{
$rows = [];
while (($row = $stmt->fetchOne()) !== false) {
$rows[] = $row;
}
return $rows;
}
} }
...@@ -2,17 +2,14 @@ ...@@ -2,17 +2,14 @@
namespace Doctrine\DBAL\Driver\IBMDB2; namespace Doctrine\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use function assert; use function assert;
use function db2_bind_param; use function db2_bind_param;
use function db2_execute; use function db2_execute;
use function db2_fetch_array; use function db2_fetch_array;
use function db2_fetch_assoc; use function db2_fetch_assoc;
use function db2_fetch_both;
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;
...@@ -32,7 +29,7 @@ use const DB2_LONG; ...@@ -32,7 +29,7 @@ use const DB2_LONG;
use const DB2_PARAM_FILE; use const DB2_PARAM_FILE;
use const DB2_PARAM_IN; use const DB2_PARAM_IN;
class DB2Statement implements IteratorAggregate, Statement class DB2Statement implements Statement
{ {
/** @var resource */ /** @var resource */
private $stmt; private $stmt;
...@@ -48,9 +45,6 @@ class DB2Statement implements IteratorAggregate, Statement ...@@ -48,9 +45,6 @@ class DB2Statement implements IteratorAggregate, Statement
*/ */
private $lobs = []; private $lobs = [];
/** @var int */
private $defaultFetchMode = FetchMode::MIXED;
/** /**
* Indicates whether the statement is in the state when fetching results is possible * Indicates whether the statement is in the state when fetching results is possible
* *
...@@ -196,99 +190,61 @@ class DB2Statement implements IteratorAggregate, Statement ...@@ -196,99 +190,61 @@ class DB2Statement implements IteratorAggregate, Statement
} }
/** /**
* {@inheritdoc} * {@inheritDoc}
*
* @deprecated Use one of the fetch- or iterate-related methods.
*/ */
public function setFetchMode($fetchMode) public function fetchNumeric()
{ {
$this->defaultFetchMode = $fetchMode; if (! $this->result) {
return false;
return true; }
}
/** return db2_fetch_array($this->stmt);
* {@inheritdoc}
*
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
*/
public function getIterator()
{
return new StatementIterator($this);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*/ */
public function fetch($fetchMode = null) public function fetchAssociative()
{ {
// do not try fetching from the statement if it's not expected to contain result // do not try fetching from the statement if it's not expected to contain the result
// in order to prevent exceptional situation // in order to prevent exceptional situation
if (! $this->result) { if (! $this->result) {
return false; return false;
} }
$fetchMode = $fetchMode ?? $this->defaultFetchMode; return db2_fetch_assoc($this->stmt);
switch ($fetchMode) {
case FetchMode::COLUMN:
return $this->fetchColumn();
case FetchMode::MIXED:
return db2_fetch_both($this->stmt);
case FetchMode::ASSOCIATIVE:
return db2_fetch_assoc($this->stmt);
case FetchMode::NUMERIC:
return db2_fetch_array($this->stmt);
default:
throw new DB2Exception('Given Fetch-Style ' . $fetchMode . ' is not supported.');
}
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
*/ */
public function fetchAll($fetchMode = null) public function fetchOne()
{ {
$rows = []; return FetchUtils::fetchOne($this);
switch ($fetchMode) {
case FetchMode::COLUMN:
while (($row = $this->fetchColumn()) !== false) {
$rows[] = $row;
}
break;
default:
while (($row = $this->fetch($fetchMode)) !== false) {
$rows[] = $row;
}
}
return $rows;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated Use fetchOne() instead.
*/ */
public function fetchColumn() public function fetchAllNumeric() : array
{ {
$row = $this->fetch(FetchMode::NUMERIC); return FetchUtils::fetchAllNumeric($this);
}
if ($row === false) { /**
return false; * {@inheritdoc}
} */
public function fetchAllAssociative() : array
{
return FetchUtils::fetchAllAssociative($this);
}
return $row[0] ?? null; /**
* {@inheritdoc}
*/
public function fetchColumn() : array
{
return FetchUtils::fetchColumn($this);
} }
public function rowCount() : int public function rowCount() : int
......
...@@ -4,12 +4,8 @@ namespace Doctrine\DBAL\Driver\Mysqli; ...@@ -4,12 +4,8 @@ namespace Doctrine\DBAL\Driver\Mysqli;
use Doctrine\DBAL\Driver\FetchUtils; use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use mysqli; use mysqli;
use mysqli_stmt; use mysqli_stmt;
use function array_combine; use function array_combine;
...@@ -25,7 +21,7 @@ use function is_resource; ...@@ -25,7 +21,7 @@ use function is_resource;
use function sprintf; use function sprintf;
use function str_repeat; use function str_repeat;
class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatibleResultStatement class MysqliStatement implements Statement
{ {
/** @var string[] */ /** @var string[] */
protected static $_paramTypeMap = [ protected static $_paramTypeMap = [
...@@ -62,9 +58,6 @@ class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatible ...@@ -62,9 +58,6 @@ class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatible
*/ */
protected $_values = []; protected $_values = [];
/** @var int */
protected $_defaultFetchMode = FetchMode::MIXED;
/** /**
* Indicates whether the statement is in the state when fetching results is possible * Indicates whether the statement is in the state when fetching results is possible
* *
...@@ -308,97 +301,6 @@ class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatible ...@@ -308,97 +301,6 @@ class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatible
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*/
public function fetch($fetchMode = null)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
if (! $this->result) {
return false;
}
$fetchMode = $fetchMode ?? $this->_defaultFetchMode;
if ($fetchMode === FetchMode::COLUMN) {
return $this->fetchColumn();
}
$values = $this->_fetch();
if ($values === null) {
return false;
}
if ($values === false) {
throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
}
if ($fetchMode === FetchMode::NUMERIC) {
return $values;
}
assert(is_array($this->_columnNames));
$assoc = array_combine($this->_columnNames, $values);
assert(is_array($assoc));
switch ($fetchMode) {
case FetchMode::ASSOCIATIVE:
return $assoc;
case FetchMode::MIXED:
return $assoc + $values;
default:
throw new MysqliException(sprintf("Unknown fetch type '%s'", $fetchMode));
}
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
*/
public function fetchAll($fetchMode = null)
{
$fetchMode = $fetchMode ?? $this->_defaultFetchMode;
$rows = [];
if ($fetchMode === FetchMode::COLUMN) {
while (($row = $this->fetchColumn()) !== false) {
$rows[] = $row;
}
} else {
while (($row = $this->fetch($fetchMode)) !== false) {
$rows[] = $row;
}
}
return $rows;
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchOne() instead.
*/
public function fetchColumn()
{
$row = $this->fetch(FetchMode::NUMERIC);
if ($row === false) {
return false;
}
return $row[0] ?? null;
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/ */
public function fetchNumeric() public function fetchNumeric()
{ {
...@@ -463,6 +365,14 @@ class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatible ...@@ -463,6 +365,14 @@ class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatible
return FetchUtils::fetchAllAssociative($this); return FetchUtils::fetchAllAssociative($this);
} }
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
{
return FetchUtils::fetchColumn($this);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -490,26 +400,4 @@ class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatible ...@@ -490,26 +400,4 @@ class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatible
{ {
return $this->_stmt->field_count; return $this->_stmt->field_count;
} }
/**
* {@inheritdoc}
*
* @deprecated Use one of the fetch- or iterate-related methods.
*/
public function setFetchMode($fetchMode)
{
$this->_defaultFetchMode = $fetchMode;
return true;
}
/**
* {@inheritdoc}
*
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
*/
public function getIterator()
{
return new StatementIterator($this);
}
} }
...@@ -144,9 +144,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection ...@@ -144,9 +144,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
return false; return false;
} }
$sql = 'SELECT ' . $name . '.CURRVAL FROM DUAL'; $result = $this->query('SELECT ' . $name . '.CURRVAL FROM DUAL')->fetchOne();
$stmt = $this->query($sql);
$result = $stmt->fetchColumn();
if ($result === false) { if ($result === false) {
throw new OCI8Exception('lastInsertId failed: Query was executed but no result was returned.'); throw new OCI8Exception('lastInsertId failed: Query was executed but no result was returned.');
......
...@@ -4,12 +4,7 @@ namespace Doctrine\DBAL\Driver\OCI8; ...@@ -4,12 +4,7 @@ namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\FetchUtils; use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use InvalidArgumentException;
use IteratorAggregate;
use function assert; use function assert;
use function count; use function count;
use function implode; use function implode;
...@@ -32,7 +27,6 @@ use function substr; ...@@ -32,7 +27,6 @@ use function substr;
use const OCI_ASSOC; use const OCI_ASSOC;
use const OCI_B_BIN; use const OCI_B_BIN;
use const OCI_B_BLOB; use const OCI_B_BLOB;
use const OCI_BOTH;
use const OCI_D_LOB; use const OCI_D_LOB;
use const OCI_FETCHSTATEMENT_BY_COLUMN; use const OCI_FETCHSTATEMENT_BY_COLUMN;
use const OCI_FETCHSTATEMENT_BY_ROW; use const OCI_FETCHSTATEMENT_BY_ROW;
...@@ -46,7 +40,7 @@ use const SQLT_CHR; ...@@ -46,7 +40,7 @@ use const SQLT_CHR;
/** /**
* The OCI8 implementation of the Statement interface. * The OCI8 implementation of the Statement interface.
*/ */
class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleResultStatement class OCI8Statement implements Statement
{ {
/** @var resource */ /** @var resource */
protected $_dbh; protected $_dbh;
...@@ -64,17 +58,6 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe ...@@ -64,17 +58,6 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe
*/ */
protected static $_PARAM = ':param'; protected static $_PARAM = ':param';
/** @var int[] */
protected static $fetchModeMap = [
FetchMode::MIXED => OCI_BOTH,
FetchMode::ASSOCIATIVE => OCI_ASSOC,
FetchMode::NUMERIC => OCI_NUM,
FetchMode::COLUMN => OCI_NUM,
];
/** @var int */
protected $_defaultFetchMode = FetchMode::MIXED;
/** @var string[] */ /** @var string[] */
protected $_paramMap = []; protected $_paramMap = [];
...@@ -380,127 +363,6 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe ...@@ -380,127 +363,6 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe
return $ret; return $ret;
} }
/**
* {@inheritdoc}
*
* @deprecated Use one of the fetch- or iterate-related methods.
*/
public function setFetchMode($fetchMode)
{
$this->_defaultFetchMode = $fetchMode;
return true;
}
/**
* {@inheritdoc}
*
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
*/
public function getIterator()
{
return new StatementIterator($this);
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*/
public function fetch($fetchMode = null)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
if (! $this->result) {
return false;
}
$fetchMode = $fetchMode ?? $this->_defaultFetchMode;
if ($fetchMode === FetchMode::COLUMN) {
return $this->fetchColumn();
}
if (! isset(self::$fetchModeMap[$fetchMode])) {
throw new InvalidArgumentException('Invalid fetch style: ' . $fetchMode);
}
return oci_fetch_array(
$this->_sth,
self::$fetchModeMap[$fetchMode] | OCI_RETURN_NULLS | OCI_RETURN_LOBS
);
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
*/
public function fetchAll($fetchMode = null)
{
$fetchMode = $fetchMode ?? $this->_defaultFetchMode;
$result = [];
if (! isset(self::$fetchModeMap[$fetchMode])) {
throw new InvalidArgumentException('Invalid fetch style: ' . $fetchMode);
}
if (self::$fetchModeMap[$fetchMode] === OCI_BOTH) {
while ($row = $this->fetch($fetchMode)) {
$result[] = $row;
}
} else {
$fetchStructure = OCI_FETCHSTATEMENT_BY_ROW;
if ($fetchMode === FetchMode::COLUMN) {
$fetchStructure = OCI_FETCHSTATEMENT_BY_COLUMN;
}
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
if (! $this->result) {
return [];
}
oci_fetch_all(
$this->_sth,
$result,
0,
-1,
self::$fetchModeMap[$fetchMode] | OCI_RETURN_NULLS | $fetchStructure | OCI_RETURN_LOBS
);
if ($fetchMode === FetchMode::COLUMN) {
$result = $result[0];
}
}
return $result;
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchOne() instead.
*/
public function fetchColumn()
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
if (! $this->result) {
return false;
}
$row = oci_fetch_array($this->_sth, OCI_NUM | OCI_RETURN_NULLS | OCI_RETURN_LOBS);
if ($row === false) {
return false;
}
return $row[0] ?? null;
}
public function rowCount() : int public function rowCount() : int
{ {
$count = oci_num_rows($this->_sth); $count = oci_num_rows($this->_sth);
...@@ -517,7 +379,7 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe ...@@ -517,7 +379,7 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe
*/ */
public function fetchNumeric() public function fetchNumeric()
{ {
return $this->doFetch(OCI_NUM); return $this->fetch(OCI_NUM);
} }
/** /**
...@@ -525,7 +387,7 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe ...@@ -525,7 +387,7 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe
*/ */
public function fetchAssociative() public function fetchAssociative()
{ {
return $this->doFetch(OCI_ASSOC); return $this->fetch(OCI_ASSOC);
} }
/** /**
...@@ -541,7 +403,7 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe ...@@ -541,7 +403,7 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe
*/ */
public function fetchAllNumeric() : array public function fetchAllNumeric() : array
{ {
return $this->doFetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_ROW); return $this->fetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_ROW);
} }
/** /**
...@@ -549,13 +411,21 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe ...@@ -549,13 +411,21 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe
*/ */
public function fetchAllAssociative() : array public function fetchAllAssociative() : array
{ {
return $this->doFetchAll(OCI_ASSOC, OCI_FETCHSTATEMENT_BY_ROW); return $this->fetchAll(OCI_ASSOC, OCI_FETCHSTATEMENT_BY_ROW);
}
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
{
return $this->fetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_COLUMN)[0];
} }
/** /**
* @return mixed|false * @return mixed|false
*/ */
private function doFetch(int $mode) private function fetch(int $mode)
{ {
// do not try fetching from the statement if it's not expected to contain the result // do not try fetching from the statement if it's not expected to contain the result
// in order to prevent exceptional situation // in order to prevent exceptional situation
...@@ -572,7 +442,7 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe ...@@ -572,7 +442,7 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe
/** /**
* @return array<mixed> * @return array<mixed>
*/ */
private function doFetchAll(int $mode, int $fetchStructure) : array private function fetchAll(int $mode, int $fetchStructure) : array
{ {
// do not try fetching from the statement if it's not expected to contain the result // do not try fetching from the statement if it's not expected to contain the result
// in order to prevent exceptional situation // in order to prevent exceptional situation
......
...@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv; ...@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv;
use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\PDOStatement; use Doctrine\DBAL\Driver\PDOStatement;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use function strpos; use function strpos;
use function substr; use function substr;
...@@ -26,11 +25,7 @@ class Connection extends PDOConnection ...@@ -26,11 +25,7 @@ class Connection extends PDOConnection
$stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?'); $stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
$stmt->execute([$name]); $stmt->execute([$name]);
if ($stmt instanceof ForwardCompatibleResultStatement) { return $stmt->fetchOne();
return $stmt->fetchOne();
}
return $stmt->fetchColumn();
} }
/** /**
......
...@@ -2,11 +2,8 @@ ...@@ -2,11 +2,8 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use InvalidArgumentException; use InvalidArgumentException;
use IteratorAggregate;
use PDO; use PDO;
use function array_slice; use function array_slice;
use function assert; use function assert;
...@@ -17,7 +14,7 @@ use function is_array; ...@@ -17,7 +14,7 @@ use function is_array;
* The PDO implementation of the Statement interface. * The PDO implementation of the Statement interface.
* Used by all PDO-based drivers. * Used by all PDO-based drivers.
*/ */
class PDOStatement implements IteratorAggregate, Statement, ForwardCompatibleResultStatement class PDOStatement implements Statement
{ {
private const PARAM_TYPE_MAP = [ private const PARAM_TYPE_MAP = [
ParameterType::NULL => PDO::PARAM_NULL, ParameterType::NULL => PDO::PARAM_NULL,
...@@ -28,13 +25,6 @@ class PDOStatement implements IteratorAggregate, Statement, ForwardCompatibleRes ...@@ -28,13 +25,6 @@ class PDOStatement implements IteratorAggregate, Statement, ForwardCompatibleRes
ParameterType::BOOLEAN => PDO::PARAM_BOOL, ParameterType::BOOLEAN => PDO::PARAM_BOOL,
]; ];
private const FETCH_MODE_MAP = [
FetchMode::ASSOCIATIVE => PDO::FETCH_ASSOC,
FetchMode::NUMERIC => PDO::FETCH_NUM,
FetchMode::MIXED => PDO::FETCH_BOTH,
FetchMode::COLUMN => PDO::FETCH_COLUMN,
];
/** @var \PDOStatement */ /** @var \PDOStatement */
private $stmt; private $stmt;
...@@ -43,22 +33,6 @@ class PDOStatement implements IteratorAggregate, Statement, ForwardCompatibleRes ...@@ -43,22 +33,6 @@ class PDOStatement implements IteratorAggregate, Statement, ForwardCompatibleRes
$this->stmt = $stmt; $this->stmt = $stmt;
} }
/**
* {@inheritdoc}
*
* @deprecated Use one of the fetch- or iterate-related methods.
*/
public function setFetchMode($fetchMode)
{
$fetchMode = $this->convertFetchMode($fetchMode);
try {
return $this->stmt->setFetchMode($fetchMode);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -132,64 +106,6 @@ class PDOStatement implements IteratorAggregate, Statement, ForwardCompatibleRes ...@@ -132,64 +106,6 @@ class PDOStatement implements IteratorAggregate, Statement, ForwardCompatibleRes
return $this->stmt->rowCount(); return $this->stmt->rowCount();
} }
/**
* {@inheritdoc}
*
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*/
public function fetch($fetchMode = null)
{
try {
if ($fetchMode === null) {
return $this->stmt->fetch();
}
return $this->stmt->fetch(
$this->convertFetchMode($fetchMode)
);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
*/
public function fetchAll($fetchMode = null)
{
try {
if ($fetchMode === null) {
$data = $this->stmt->fetchAll();
} else {
$data = $this->stmt->fetchAll(
$this->convertFetchMode($fetchMode)
);
}
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
assert(is_array($data));
return $data;
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchOne() instead.
*/
public function fetchColumn()
{
try {
return $this->stmt->fetchColumn();
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -231,38 +147,56 @@ class PDOStatement implements IteratorAggregate, Statement, ForwardCompatibleRes ...@@ -231,38 +147,56 @@ class PDOStatement implements IteratorAggregate, Statement, ForwardCompatibleRes
} }
/** /**
* Converts DBAL parameter type to PDO parameter type * {@inheritdoc}
*/
public function fetchColumn() : array
{
return $this->fetchAll(PDO::FETCH_COLUMN);
}
/**
* @return mixed|false
* *
* @param int $type Parameter type * @throws PDOException
*/ */
private function convertParamType(int $type) : int private function fetch(int $mode)
{ {
if (! isset(self::PARAM_TYPE_MAP[$type])) { try {
throw new InvalidArgumentException('Invalid parameter type: ' . $type); return $this->stmt->fetch($mode);
} catch (\PDOException $exception) {
throw new PDOException($exception);
} }
return self::PARAM_TYPE_MAP[$type];
} }
/** /**
* Converts DBAL fetch mode to PDO fetch mode * @return array<int,mixed>
* *
* @param int $fetchMode Fetch mode * @throws PDOException
*/ */
private function convertFetchMode(int $fetchMode) : int private function fetchAll(int $mode) : array
{ {
if (! isset(self::FETCH_MODE_MAP[$fetchMode])) { try {
throw new InvalidArgumentException('Invalid fetch mode: ' . $fetchMode); $data = $this->stmt->fetchAll($mode);
} catch (\PDOException $exception) {
throw new PDOException($exception);
} }
return self::FETCH_MODE_MAP[$fetchMode]; assert(is_array($data));
return $data;
} }
/** /**
* {@inheritdoc} * Converts DBAL parameter type to PDO parameter type
*
* @param int $type Parameter type
*/ */
public function getIterator() private function convertParamType(int $type) : int
{ {
yield from $this->stmt; if (! isset(self::PARAM_TYPE_MAP[$type])) {
throw new InvalidArgumentException('Invalid parameter type: ' . $type);
}
return self::PARAM_TYPE_MAP[$type];
} }
} }
<?php <?php
namespace Doctrine\DBAL\Driver; declare(strict_types=1);
use Traversable; namespace Doctrine\DBAL\Driver;
/** /**
* Interface for the reading part of a prepare statement only. * Interface for the reading part of a prepare statement only.
*/ */
interface ResultStatement extends Traversable interface ResultStatement
{ {
/** /**
* Closes the cursor, enabling the statement to be executed again. * Closes the cursor, enabling the statement to be executed again.
...@@ -20,56 +20,62 @@ interface ResultStatement extends Traversable ...@@ -20,56 +20,62 @@ interface ResultStatement extends Traversable
* Returns the number of columns in the result set * Returns the number of columns in the result set
* *
* @return int The number of columns in the result set represented * @return int The number of columns in the result set represented
* by the PDOStatement object. If there is no result set, * by the statement. If there is no result set,
* this method should return 0. * this method should return 0.
*/ */
public function columnCount(); public function columnCount();
/** /**
* Sets the fetch mode to use while iterating this statement. * Returns the next row of a result set as a numeric array or FALSE if there are no more rows.
*
* @deprecated Use one of the fetch- or iterate-related methods.
* *
* @param int $fetchMode Controls how the next row will be returned to the caller. * @return array<int,mixed>|false
* The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants.
* *
* @return bool * @throws DriverException
*/ */
public function setFetchMode($fetchMode); public function fetchNumeric();
/** /**
* Returns the next row of a result set. * Returns the next row of a result set as an associative array or FALSE if there are no more rows.
* *
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead. * @return array<string,mixed>|false
* *
* @param int|null $fetchMode Controls how the next row will be returned to the caller. * @throws DriverException
* The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants, */
* defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}. public function fetchAssociative();
/**
* Returns the first value of the next row of a result set or FALSE if there are no more rows.
* *
* @return mixed The return value of this method on success depends on the fetch mode. In all cases, FALSE is * @return mixed|false
* returned on failure. *
* @throws DriverException
*/ */
public function fetch($fetchMode = null); public function fetchOne();
/** /**
* Returns an array containing all of the result set rows. * Returns an array containing all of the result set rows represented as numeric arrays.
*
* @return array<int,array<int,mixed>>
* *
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead. * @throws DriverException
*/
public function fetchAllNumeric() : array;
/**
* Returns an array containing all of the result set rows represented as associative arrays.
* *
* @param int|null $fetchMode Controls how the next row will be returned to the caller. * @return array<int,array<string,mixed>>
* The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants,
* defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}.
* *
* @return mixed[] * @throws DriverException
*/ */
public function fetchAll($fetchMode = null); public function fetchAllAssociative() : array;
/** /**
* Returns a single column from the next row of a result set or FALSE if there are no more rows. * Returns an array containing the values of the first column of the result set.
* *
* @deprecated Use fetchOne() instead. * @return array<int,mixed>
* *
* @return mixed|false A single column in the next row of a result set, or FALSE if there are no more rows. * @throws DriverException
*/ */
public function fetchColumn(); public function fetchColumn() : array;
} }
...@@ -5,7 +5,6 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere; ...@@ -5,7 +5,6 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere;
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 Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use function assert; use function assert;
use function is_float; use function is_float;
...@@ -101,14 +100,7 @@ class SQLAnywhereConnection implements ServerInfoAwareConnection ...@@ -101,14 +100,7 @@ class SQLAnywhereConnection implements ServerInfoAwareConnection
*/ */
public function getServerVersion() public function getServerVersion()
{ {
$stmt = $this->query("SELECT PROPERTY('ProductVersion')"); $version = $this->query("SELECT PROPERTY('ProductVersion')")->fetchOne();
if ($stmt instanceof ForwardCompatibleResultStatement) {
$version = $stmt->fetchOne();
} else {
$version = $stmt->fetchColumn();
}
assert(is_string($version)); assert(is_string($version));
return $version; return $version;
...@@ -123,13 +115,7 @@ class SQLAnywhereConnection implements ServerInfoAwareConnection ...@@ -123,13 +115,7 @@ class SQLAnywhereConnection implements ServerInfoAwareConnection
return sasql_insert_id($this->connection); return sasql_insert_id($this->connection);
} }
$stmt = $this->query('SELECT ' . $name . '.CURRVAL'); return $this->query('SELECT ' . $name . '.CURRVAL')->fetchOne();
if ($stmt instanceof ForwardCompatibleResultStatement) {
return $stmt->fetchOne();
}
return $stmt->fetchColumn();
} }
public function prepare(string $sql) : DriverStatement public function prepare(string $sql) : DriverStatement
......
...@@ -5,16 +5,11 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere; ...@@ -5,16 +5,11 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere;
use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\FetchUtils; use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use function array_key_exists; use function array_key_exists;
use function assert; use function assert;
use function is_int; use function is_int;
use function is_resource; use function is_resource;
use function sasql_fetch_array;
use function sasql_fetch_assoc; use function sasql_fetch_assoc;
use function sasql_fetch_row; use function sasql_fetch_row;
use function sasql_prepare; use function sasql_prepare;
...@@ -24,19 +19,15 @@ use function sasql_stmt_execute; ...@@ -24,19 +19,15 @@ 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;
use function sasql_stmt_result_metadata; use function sasql_stmt_result_metadata;
use const SASQL_BOTH;
/** /**
* SAP SQL Anywhere implementation of the Statement interface. * SAP SQL Anywhere implementation of the Statement interface.
*/ */
class SQLAnywhereStatement implements IteratorAggregate, Statement, ForwardCompatibleResultStatement class SQLAnywhereStatement implements Statement
{ {
/** @var resource The connection resource. */ /** @var resource The connection resource. */
private $conn; private $conn;
/** @var int Default fetch mode to use. */
private $defaultFetchMode = FetchMode::MIXED;
/** @var resource|null The result set resource to fetch. */ /** @var resource|null The result set resource to fetch. */
private $result; private $result;
...@@ -167,91 +158,8 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement, ForwardCompa ...@@ -167,91 +158,8 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement, ForwardCompa
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*
* @throws SQLAnywhereException * @throws SQLAnywhereException
*/ */
public function fetch($fetchMode = null)
{
if (! is_resource($this->result)) {
return false;
}
$fetchMode = $fetchMode ?? $this->defaultFetchMode;
switch ($fetchMode) {
case FetchMode::COLUMN:
return $this->fetchColumn();
case FetchMode::ASSOCIATIVE:
return sasql_fetch_assoc($this->result);
case FetchMode::MIXED:
return sasql_fetch_array($this->result, SASQL_BOTH);
case FetchMode::NUMERIC:
return sasql_fetch_row($this->result);
default:
throw new SQLAnywhereException('Fetch mode is not supported: ' . $fetchMode);
}
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
*/
public function fetchAll($fetchMode = null)
{
$rows = [];
switch ($fetchMode) {
case FetchMode::COLUMN:
while (($row = $this->fetchColumn()) !== false) {
$rows[] = $row;
}
break;
default:
while (($row = $this->fetch($fetchMode)) !== false) {
$rows[] = $row;
}
}
return $rows;
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchOne() instead.
*/
public function fetchColumn()
{
$row = $this->fetch(FetchMode::NUMERIC);
if ($row === false) {
return false;
}
return $row[0] ?? null;
}
/**
* {@inheritdoc}
*
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
*/
public function getIterator()
{
return new StatementIterator($this);
}
/**
* {@inheritDoc}
*/
public function fetchNumeric() public function fetchNumeric()
{ {
if (! is_resource($this->result)) { if (! is_resource($this->result)) {
...@@ -303,20 +211,18 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement, ForwardCompa ...@@ -303,20 +211,18 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement, ForwardCompa
return FetchUtils::fetchAllAssociative($this); return FetchUtils::fetchAllAssociative($this);
} }
public function rowCount() : int
{
return sasql_stmt_affected_rows($this->stmt);
}
/** /**
* {@inheritdoc} * @return array<int,mixed>
* *
* @deprecated Use one of the fetch- or iterate-related methods. * @throws DriverException
*/ */
public function setFetchMode($fetchMode) public function fetchColumn() : array
{ {
$this->defaultFetchMode = $fetchMode; return FetchUtils::fetchColumn($this);
}
return true; public function rowCount() : int
{
return sasql_stmt_affected_rows($this->stmt);
} }
} }
...@@ -5,7 +5,6 @@ namespace Doctrine\DBAL\Driver\SQLSrv; ...@@ -5,7 +5,6 @@ namespace Doctrine\DBAL\Driver\SQLSrv;
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 Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use function is_float; use function is_float;
use function is_int; use function is_int;
...@@ -129,11 +128,7 @@ class SQLSrvConnection implements ServerInfoAwareConnection ...@@ -129,11 +128,7 @@ class SQLSrvConnection implements ServerInfoAwareConnection
$stmt = $this->query('SELECT @@IDENTITY'); $stmt = $this->query('SELECT @@IDENTITY');
} }
if ($stmt instanceof ForwardCompatibleResultStatement) { return $stmt->fetchOne();
return $stmt->fetchOne();
}
return $stmt->fetchColumn();
} }
/** /**
......
...@@ -4,11 +4,7 @@ namespace Doctrine\DBAL\Driver\SQLSrv; ...@@ -4,11 +4,7 @@ namespace Doctrine\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Driver\FetchUtils; use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use function is_int; use function is_int;
use function is_numeric; use function is_numeric;
use function sqlsrv_execute; use function sqlsrv_execute;
...@@ -25,14 +21,13 @@ use function SQLSRV_SQLTYPE_VARBINARY; ...@@ -25,14 +21,13 @@ use function SQLSRV_SQLTYPE_VARBINARY;
use function stripos; use function stripos;
use const SQLSRV_ENC_BINARY; use const SQLSRV_ENC_BINARY;
use const SQLSRV_FETCH_ASSOC; use const SQLSRV_FETCH_ASSOC;
use const SQLSRV_FETCH_BOTH;
use const SQLSRV_FETCH_NUMERIC; use const SQLSRV_FETCH_NUMERIC;
use const SQLSRV_PARAM_IN; use const SQLSRV_PARAM_IN;
/** /**
* SQL Server Statement. * SQL Server Statement.
*/ */
class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatibleResultStatement final class SQLSrvStatement implements Statement
{ {
/** /**
* The SQLSRV Resource. * The SQLSRV Resource.
...@@ -69,24 +64,6 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible ...@@ -69,24 +64,6 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible
*/ */
private $types = []; private $types = [];
/**
* Translations.
*
* @var int[]
*/
private static $fetchMap = [
FetchMode::MIXED => SQLSRV_FETCH_BOTH,
FetchMode::ASSOCIATIVE => SQLSRV_FETCH_ASSOC,
FetchMode::NUMERIC => SQLSRV_FETCH_NUMERIC,
];
/**
* The fetch style.
*
* @var int
*/
private $defaultFetchMode = FetchMode::MIXED;
/** /**
* The last insert ID. * The last insert ID.
* *
...@@ -279,104 +256,12 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible ...@@ -279,104 +256,12 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible
return $stmt; return $stmt;
} }
/**
* {@inheritdoc}
*
* @deprecated Use one of the fetch- or iterate-related methods.
*/
public function setFetchMode($fetchMode)
{
$this->defaultFetchMode = $fetchMode;
return true;
}
/**
* {@inheritdoc}
*
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
*/
public function getIterator()
{
return new StatementIterator($this);
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*
* @throws SQLSrvException
*/
public function fetch($fetchMode = null)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
if ($this->stmt === null || ! $this->result) {
return false;
}
$fetchMode = $fetchMode ?? $this->defaultFetchMode;
if ($fetchMode === FetchMode::COLUMN) {
return $this->fetchColumn();
}
if (isset(self::$fetchMap[$fetchMode])) {
return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchMode]) ?? false;
}
throw new SQLSrvException('Fetch mode is not supported!');
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
*/
public function fetchAll($fetchMode = null)
{
$rows = [];
switch ($fetchMode) {
case FetchMode::COLUMN:
while (($row = $this->fetchColumn()) !== false) {
$rows[] = $row;
}
break;
default:
while (($row = $this->fetch($fetchMode)) !== false) {
$rows[] = $row;
}
}
return $rows;
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchOne() instead.
*/
public function fetchColumn()
{
$row = $this->fetch(FetchMode::NUMERIC);
if ($row === false) {
return false;
}
return $row[0] ?? null;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetchNumeric() public function fetchNumeric()
{ {
return $this->doFetch(SQLSRV_FETCH_NUMERIC); return $this->fetch(SQLSRV_FETCH_NUMERIC);
} }
/** /**
...@@ -384,7 +269,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible ...@@ -384,7 +269,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible
*/ */
public function fetchAssociative() public function fetchAssociative()
{ {
return $this->doFetch(SQLSRV_FETCH_ASSOC); return $this->fetch(SQLSRV_FETCH_ASSOC);
} }
/** /**
...@@ -411,6 +296,14 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible ...@@ -411,6 +296,14 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible
return FetchUtils::fetchAllAssociative($this); return FetchUtils::fetchAllAssociative($this);
} }
/**
* {@inheritdoc}
*/
public function fetchColumn() : array
{
return FetchUtils::fetchColumn($this);
}
public function rowCount() : int public function rowCount() : int
{ {
if ($this->stmt === null) { if ($this->stmt === null) {
...@@ -429,7 +322,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible ...@@ -429,7 +322,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible
/** /**
* @return mixed|false * @return mixed|false
*/ */
private function doFetch(int $fetchType) private function fetch(int $fetchType)
{ {
// do not try fetching from the statement if it's not expected to contain the result // do not try fetching from the statement if it's not expected to contain the result
// in order to prevent exceptional situation // in order to prevent exceptional situation
......
<?php
namespace Doctrine\DBAL\Driver;
use IteratorAggregate;
/**
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn().
*/
class StatementIterator implements IteratorAggregate
{
/** @var ResultStatement */
private $statement;
public function __construct(ResultStatement $statement)
{
$this->statement = $statement;
}
/**
* {@inheritdoc}
*/
public function getIterator()
{
while (($result = $this->statement->fetch()) !== false) {
yield $result;
}
}
}
<?php
namespace Doctrine\DBAL;
/**
* Contains statement fetch modes.
*
* @deprecated Use one of the fetch- or iterate-related methods on the Statement.
*/
final class FetchMode
{
/**
* Specifies that the fetch method shall return each row as an array indexed
* by column name as returned in the corresponding result set. If the result
* set contains multiple columns with the same name, the statement returns
* only a single value per column name.
*
* @see \PDO::FETCH_ASSOC
*/
public const ASSOCIATIVE = 2;
/**
* Specifies that the fetch method shall return each row as an array indexed
* by column number as returned in the corresponding result set, starting at
* column 0.
*
* @see \PDO::FETCH_NUM
*/
public const NUMERIC = 3;
/**
* Specifies that the fetch method shall return each row as an array indexed
* by both column name and number as returned in the corresponding result set,
* starting at column 0.
*
* @see \PDO::FETCH_BOTH
*/
public const MIXED = 4;
/**
* Specifies that the fetch method shall return only a single requested
* column from the next row in the result set.
*
* @see \PDO::FETCH_COLUMN
*/
public const COLUMN = 7;
/**
* This class cannot be instantiated.
*/
private function __construct()
{
}
}
...@@ -4,56 +4,13 @@ declare(strict_types=1); ...@@ -4,56 +4,13 @@ declare(strict_types=1);
namespace Doctrine\DBAL\ForwardCompatibility\Driver; namespace Doctrine\DBAL\ForwardCompatibility\Driver;
use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\ResultStatement as BaseResultStatement; use Doctrine\DBAL\Driver\ResultStatement as BaseResultStatement;
/** /**
* Forward compatibility extension for the ResultStatement interface. * Forward compatibility extension for the ResultStatement interface.
*
* @deprecated
*/ */
interface ResultStatement extends BaseResultStatement interface ResultStatement extends BaseResultStatement
{ {
/**
* Returns the next row of a result set as a numeric array or FALSE if there are no more rows.
*
* @return array<int,mixed>|false
*
* @throws DriverException
*/
public function fetchNumeric();
/**
* Returns the next row of a result set as an associative array or FALSE if there are no more rows.
*
* @return array<string,mixed>|false
*
* @throws DriverException
*/
public function fetchAssociative();
/**
* Returns the first value of the next row of a result set or FALSE if there are no more rows.
*
* @return mixed|false
*
* @throws DriverException
*/
public function fetchOne();
/**
* Returns an array containing all of the result set rows represented as numeric arrays.
*
* @return array<int,array<int,mixed>>
*
* @throws DriverException
*/
public function fetchAllNumeric() : array;
/**
* Returns an array containing all of the result set rows represented as associative arrays.
*
* @return array<int,array<string,mixed>>
*
* @throws DriverException
*/
public function fetchAllAssociative() : array;
} }
...@@ -4,39 +4,13 @@ declare(strict_types=1); ...@@ -4,39 +4,13 @@ declare(strict_types=1);
namespace Doctrine\DBAL\ForwardCompatibility; namespace Doctrine\DBAL\ForwardCompatibility;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as BaseResultStatement; use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as BaseResultStatement;
use Traversable;
/** /**
* Forward compatibility extension for the DBAL ResultStatement interface. * Forward compatibility extension for the DBAL ResultStatement interface.
*
* @deprecated
*/ */
interface ResultStatement extends BaseResultStatement interface ResultStatement extends BaseResultStatement
{ {
/**
* Returns an iterator over the result set rows represented as numeric arrays.
*
* @return Traversable<int,array<int,mixed>>
*
* @throws DBALException
*/
public function iterateNumeric() : Traversable;
/**
* Returns an iterator over the result set rows represented as associative arrays.
*
* @return Traversable<int,array<string,mixed>>
*
* @throws DBALException
*/
public function iterateAssociative() : Traversable;
/**
* Returns an iterator over the values of the first column of the result set.
*
* @return Traversable<int,mixed>
*
* @throws DBALException
*/
public function iterateColumn() : Traversable;
} }
...@@ -98,28 +98,20 @@ class Connection extends \Doctrine\DBAL\Connection ...@@ -98,28 +98,20 @@ class Connection extends \Doctrine\DBAL\Connection
*/ */
public function executeQuery(string $query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) : ResultStatement public function executeQuery(string $query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) : ResultStatement
{ {
$stmt = new Statement(parent::executeQuery($query, $params, $types, $qcp), $this); return new Statement(parent::executeQuery($query, $params, $types, $qcp), $this);
$stmt->setFetchMode($this->defaultFetchMode);
return $stmt;
} }
public function prepare(string $sql) : DriverStatement public function prepare(string $sql) : DriverStatement
{ {
$stmt = new Statement(parent::prepare($sql), $this); return new Statement(parent::prepare($sql), $this);
$stmt->setFetchMode($this->defaultFetchMode);
return $stmt;
} }
public function query(string $sql) : ResultStatement public function query(string $sql) : ResultStatement
{ {
$connection = $this->getWrappedConnection(); return new Statement(
$this->getWrappedConnection()
$stmt = $connection->query($sql); ->query($sql),
$stmt = new Statement($stmt, $this); $this
$stmt->setFetchMode($this->defaultFetchMode); );
return $stmt;
} }
} }
...@@ -4,11 +4,7 @@ namespace Doctrine\DBAL\Portability; ...@@ -4,11 +4,7 @@ namespace Doctrine\DBAL\Portability;
use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use function array_change_key_case; use function array_change_key_case;
use function assert; use function assert;
use function is_string; use function is_string;
...@@ -17,7 +13,7 @@ use function rtrim; ...@@ -17,7 +13,7 @@ use function rtrim;
/** /**
* Portability wrapper for a Statement. * Portability wrapper for a Statement.
*/ */
class Statement implements IteratorAggregate, DriverStatement, ForwardCompatibleResultStatement class Statement implements DriverStatement
{ {
/** @var int */ /** @var int */
private $portability; private $portability;
...@@ -28,9 +24,6 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -28,9 +24,6 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
/** @var int */ /** @var int */
private $case; private $case;
/** @var int */
private $defaultFetchMode = FetchMode::MIXED;
/** /**
* Wraps <tt>Statement</tt> and applies portability measures. * Wraps <tt>Statement</tt> and applies portability measures.
* *
...@@ -89,79 +82,15 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -89,79 +82,15 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
return $this->stmt->execute($params); return $this->stmt->execute($params);
} }
/**
* {@inheritdoc}
*
* @deprecated Use one of the fetch- or iterate-related methods.
*/
public function setFetchMode($fetchMode)
{
$this->defaultFetchMode = $fetchMode;
return $this->stmt->setFetchMode($fetchMode);
}
/**
* {@inheritdoc}
*
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
*/
public function getIterator()
{
return new StatementIterator($this);
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*/
public function fetch($fetchMode = null)
{
$fetchMode = $fetchMode ?? $this->defaultFetchMode;
$row = $this->stmt->fetch($fetchMode);
$iterateRow = ($this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM)) !== 0;
$fixCase = $this->case !== null
&& ($fetchMode === FetchMode::ASSOCIATIVE || $fetchMode === FetchMode::MIXED)
&& ($this->portability & Connection::PORTABILITY_FIX_CASE) !== 0;
$row = $this->fixRow($row, $iterateRow, $fixCase);
return $row;
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
*/
public function fetchAll($fetchMode = null)
{
$fetchMode = $fetchMode ?? $this->defaultFetchMode;
$rows = $this->stmt->fetchAll($fetchMode);
$fixCase = $this->case !== null
&& ($fetchMode === FetchMode::ASSOCIATIVE || $fetchMode === FetchMode::MIXED)
&& ($this->portability & Connection::PORTABILITY_FIX_CASE) !== 0;
return $this->fixResultSet($rows, $fixCase, $fetchMode !== FetchMode::COLUMN);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetchNumeric() public function fetchNumeric()
{ {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { return $this->fixResult(
$row = $this->stmt->fetchNumeric(); $this->stmt->fetchAssociative(),
} else { false
$row = $this->stmt->fetch(FetchMode::NUMERIC); );
}
return $this->fixResult($row, false);
} }
/** /**
...@@ -169,13 +98,10 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -169,13 +98,10 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
*/ */
public function fetchAssociative() public function fetchAssociative()
{ {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { return $this->fixResult(
$row = $this->stmt->fetchAssociative(); $this->stmt->fetchAssociative(),
} else { true
$row = $this->stmt->fetch(FetchMode::ASSOCIATIVE); );
}
return $this->fixResult($row, true);
} }
/** /**
...@@ -183,11 +109,7 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -183,11 +109,7 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
*/ */
public function fetchOne() public function fetchOne()
{ {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { $value = $this->stmt->fetchOne();
$value = $this->stmt->fetchOne();
} else {
$value = $this->stmt->fetch(FetchMode::COLUMN);
}
if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) !== 0 && $value === '') { if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) !== 0 && $value === '') {
$value = null; $value = null;
...@@ -203,13 +125,11 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -203,13 +125,11 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
*/ */
public function fetchAllNumeric() : array public function fetchAllNumeric() : array
{ {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { return $this->fixResultSet(
$data = $this->stmt->fetchAllNumeric(); $this->stmt->fetchAllNumeric(),
} else { false,
$data = $this->stmt->fetchAll(FetchMode::NUMERIC); true
} );
return $this->fixResultSet($data, false, true);
} }
/** /**
...@@ -217,13 +137,23 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -217,13 +137,23 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
*/ */
public function fetchAllAssociative() : array public function fetchAllAssociative() : array
{ {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { return $this->fixResultSet(
$data = $this->stmt->fetchAllAssociative(); $this->stmt->fetchAllAssociative(),
} else { true,
$data = $this->stmt->fetchAll(FetchMode::ASSOCIATIVE); true
} );
}
return $this->fixResultSet($data, true, true); /**
* {@inheritdoc}
*/
public function fetchColumn() : array
{
return $this->fixResultSet(
$this->stmt->fetchColumn(),
true,
false
);
} }
/** /**
...@@ -302,24 +232,6 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -302,24 +232,6 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
return $row; return $row;
} }
/**
* {@inheritdoc}
*
* @deprecated Use fetchOne() instead.
*/
public function fetchColumn()
{
$value = $this->stmt->fetchColumn();
if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) !== 0 && $value === '') {
$value = null;
} elseif (($this->portability & Connection::PORTABILITY_RTRIM) !== 0 && is_string($value)) {
$value = rtrim($value);
}
return $value;
}
public function rowCount() : int public function rowCount() : int
{ {
assert($this->stmt instanceof DriverStatement); assert($this->stmt instanceof DriverStatement);
......
<?php
declare(strict_types=1);
namespace Doctrine\DBAL;
use Doctrine\DBAL\Driver\ResultStatement as DriverResultStatement;
use Traversable;
/**
* DBAL-level ResultStatement interface.
*/
interface ResultStatement extends DriverResultStatement
{
/**
* Returns an iterator over the result set rows represented as numeric arrays.
*
* @return Traversable<int,array<int,mixed>>
*
* @throws DBALException
*/
public function iterateNumeric() : Traversable;
/**
* Returns an iterator over the result set rows represented as associative arrays.
*
* @return Traversable<int,array<string,mixed>>
*
* @throws DBALException
*/
public function iterateAssociative() : Traversable;
/**
* Returns an iterator over the values of the first column of the result set.
*
* @return Traversable<int,mixed>
*
* @throws DBALException
*/
public function iterateColumn() : Traversable;
}
...@@ -640,7 +640,7 @@ abstract class AbstractSchemaManager ...@@ -640,7 +640,7 @@ abstract class AbstractSchemaManager
/** /**
* Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition. * Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition.
* *
* @param mixed[][] $namespaces The list of namespace names in the native DBMS data definition. * @param array<int, array<string, mixed>> $namespaces The list of namespace names in the native DBMS data definition.
* *
* @return string[] * @return string[]
*/ */
...@@ -668,7 +668,7 @@ abstract class AbstractSchemaManager ...@@ -668,7 +668,7 @@ abstract class AbstractSchemaManager
/** /**
* Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition. * Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition.
* *
* @param mixed[] $namespace The native DBMS namespace definition. * @param array<string, mixed> $namespace The native DBMS namespace definition.
* *
* @return mixed * @return mixed
*/ */
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Doctrine\DBAL\Schema; namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\Types;
...@@ -41,9 +40,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -41,9 +40,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
*/ */
public function getSchemaNames() public function getSchemaNames()
{ {
$statement = $this->_conn->executeQuery("SELECT nspname FROM pg_namespace WHERE nspname !~ '^pg_.*' AND nspname != 'information_schema'"); return $this->_conn->fetchColumn("SELECT nspname FROM pg_namespace WHERE nspname !~ '^pg_.*' AND nspname != 'information_schema'");
return $statement->fetchAll(FetchMode::COLUMN);
} }
/** /**
...@@ -56,7 +53,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -56,7 +53,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
public function getSchemaSearchPaths() public function getSchemaSearchPaths()
{ {
$params = $this->_conn->getParams(); $params = $this->_conn->getParams();
$schema = explode(',', $this->_conn->fetchColumn('SHOW search_path')); $schema = explode(',', $this->_conn->fetchOne('SHOW search_path'));
if (isset($params['user'])) { if (isset($params['user'])) {
$schema = str_replace('"$user"', $params['user'], $schema); $schema = str_replace('"$user"', $params['user'], $schema);
...@@ -311,7 +308,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -311,7 +308,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
if (! isset($sequence['increment_by'], $sequence['min_value'])) { if (! isset($sequence['increment_by'], $sequence['min_value'])) {
/** @var string[] $data */ /** @var string[] $data */
$data = $this->_conn->fetchAssoc('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName)); $data = $this->_conn->fetchAssociative('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
$sequence += $data; $sequence += $data;
} }
...@@ -532,7 +529,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -532,7 +529,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
assert($platform instanceof PostgreSQL94Platform); assert($platform instanceof PostgreSQL94Platform);
$sql = $platform->getListTableMetadataSQL($tableName); $sql = $platform->getListTableMetadataSQL($tableName);
$tableOptions = $this->_conn->fetchAssoc($sql); $tableOptions = $this->_conn->fetchAssociative($sql);
if ($tableOptions !== false) { if ($tableOptions !== false) {
$table->addOption('comment', $tableOptions['table_comment']); $table->addOption('comment', $tableOptions['table_comment']);
......
...@@ -514,7 +514,7 @@ CREATE\sTABLE # Match "CREATE TABLE" ...@@ -514,7 +514,7 @@ CREATE\sTABLE # Match "CREATE TABLE"
private function getCreateTableSQL(string $table) : string private function getCreateTableSQL(string $table) : string
{ {
$sql = $this->_conn->fetchColumn( $sql = $this->_conn->fetchOne(
<<<'SQL' <<<'SQL'
SELECT sql SELECT sql
FROM ( FROM (
......
...@@ -4,10 +4,8 @@ namespace Doctrine\DBAL; ...@@ -4,10 +4,8 @@ namespace Doctrine\DBAL;
use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\ForwardCompatibility\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use IteratorAggregate;
use Throwable; use Throwable;
use Traversable; use Traversable;
use function is_string; use function is_string;
...@@ -16,7 +14,7 @@ use function is_string; ...@@ -16,7 +14,7 @@ use function is_string;
* A thin wrapper around a Doctrine\DBAL\Driver\Statement that adds support * A thin wrapper around a Doctrine\DBAL\Driver\Statement that adds support
* for logging, DBAL mapping types, etc. * for logging, DBAL mapping types, etc.
*/ */
class Statement implements IteratorAggregate, DriverStatement, ForwardCompatibleResultStatement class Statement implements DriverStatement, ResultStatement
{ {
/** /**
* The SQL statement. * The SQL statement.
...@@ -199,53 +197,15 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -199,53 +197,15 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
* @deprecated Use one of the fetch- or iterate-related methods. * @throws DBALException
*/
public function setFetchMode($fetchMode)
{
return $this->stmt->setFetchMode($fetchMode);
}
/**
* Required by interface IteratorAggregate.
*
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
*
* {@inheritdoc}
*/
public function getIterator()
{
return $this->stmt;
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*/
public function fetch($fetchMode = null)
{
return $this->stmt->fetch($fetchMode);
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
*/
public function fetchAll($fetchMode = null)
{
return $this->stmt->fetchAll($fetchMode);
}
/**
* {@inheritDoc}
*
* @deprecated Use fetchOne() instead.
*/ */
public function fetchColumn() public function fetchNumeric()
{ {
return $this->stmt->fetchColumn(); try {
return $this->stmt->fetchNumeric();
} catch (DriverException $e) {
throw DBALException::driverException($this->conn->getDriver(), $e);
}
} }
/** /**
...@@ -253,14 +213,10 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -253,14 +213,10 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
* *
* @throws DBALException * @throws DBALException
*/ */
public function fetchNumeric() public function fetchAssociative()
{ {
try { try {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { return $this->stmt->fetchAssociative();
return $this->stmt->fetchNumeric();
}
return $this->stmt->fetch(FetchMode::NUMERIC);
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->conn->getDriver(), $e); throw DBALException::driverException($this->conn->getDriver(), $e);
} }
...@@ -268,35 +224,25 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -268,35 +224,25 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @throws DBALException
*/ */
public function fetchAssociative() public function fetchOne()
{ {
try { try {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { return $this->stmt->fetchOne();
return $this->stmt->fetchAssociative();
}
return $this->stmt->fetch(FetchMode::ASSOCIATIVE);
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->conn->getDriver(), $e); throw DBALException::driverException($this->conn->getDriver(), $e);
} }
} }
/** /**
* {@inheritDoc} * {@inheritdoc}
* *
* @throws DBALException * @throws DBALException
*/ */
public function fetchOne() public function fetchAllNumeric() : array
{ {
try { try {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { return $this->stmt->fetchAllNumeric();
return $this->stmt->fetchOne();
}
return $this->stmt->fetch(FetchMode::COLUMN);
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->conn->getDriver(), $e); throw DBALException::driverException($this->conn->getDriver(), $e);
} }
...@@ -307,14 +253,10 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -307,14 +253,10 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
* *
* @throws DBALException * @throws DBALException
*/ */
public function fetchAllNumeric() : array public function fetchAllAssociative() : array
{ {
try { try {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { return $this->stmt->fetchAllAssociative();
return $this->stmt->fetchAllNumeric();
}
return $this->stmt->fetchAll(FetchMode::NUMERIC);
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->conn->getDriver(), $e); throw DBALException::driverException($this->conn->getDriver(), $e);
} }
...@@ -325,14 +267,10 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -325,14 +267,10 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
* *
* @throws DBALException * @throws DBALException
*/ */
public function fetchAllAssociative() : array public function fetchColumn() : array
{ {
try { try {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { return $this->stmt->fetchColumn();
return $this->stmt->fetchAllAssociative();
}
return $this->stmt->fetchAll(FetchMode::ASSOCIATIVE);
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->conn->getDriver(), $e); throw DBALException::driverException($this->conn->getDriver(), $e);
} }
...@@ -348,14 +286,8 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -348,14 +286,8 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
public function iterateNumeric() : Traversable public function iterateNumeric() : Traversable
{ {
try { try {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { while (($row = $this->stmt->fetchNumeric()) !== false) {
while (($row = $this->stmt->fetchNumeric()) !== false) { yield $row;
yield $row;
}
} else {
while (($row = $this->stmt->fetch(FetchMode::NUMERIC)) !== false) {
yield $row;
}
} }
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->conn->getDriver(), $e); throw DBALException::driverException($this->conn->getDriver(), $e);
...@@ -372,14 +304,8 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -372,14 +304,8 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
public function iterateAssociative() : Traversable public function iterateAssociative() : Traversable
{ {
try { try {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { while (($row = $this->stmt->fetchAssociative()) !== false) {
while (($row = $this->stmt->fetchAssociative()) !== false) { yield $row;
yield $row;
}
} else {
while (($row = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) !== false) {
yield $row;
}
} }
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->conn->getDriver(), $e); throw DBALException::driverException($this->conn->getDriver(), $e);
...@@ -396,14 +322,8 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -396,14 +322,8 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
public function iterateColumn() : Traversable public function iterateColumn() : Traversable
{ {
try { try {
if ($this->stmt instanceof ForwardCompatibleResultStatement) { while (($value = $this->stmt->fetchOne()) !== false) {
while (($value = $this->stmt->fetchOne()) !== false) { yield $value;
yield $value;
}
} else {
while (($value = $this->stmt->fetch(FetchMode::COLUMN)) !== false) {
yield $value;
}
} }
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->conn->getDriver(), $e); throw DBALException::driverException($this->conn->getDriver(), $e);
......
...@@ -17,7 +17,6 @@ use Doctrine\DBAL\Driver\Statement; ...@@ -17,7 +17,6 @@ use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
...@@ -548,7 +547,7 @@ class ConnectionTest extends TestCase ...@@ -548,7 +547,7 @@ class ConnectionTest extends TestCase
); );
} }
public function testFetchAssoc() : void public function testFetchAssociative() : void
{ {
$statement = 'SELECT * FROM foo WHERE bar = ?'; $statement = 'SELECT * FROM foo WHERE bar = ?';
$params = [666]; $params = [666];
...@@ -566,8 +565,7 @@ class ConnectionTest extends TestCase ...@@ -566,8 +565,7 @@ class ConnectionTest extends TestCase
$driverStatementMock = $this->createMock(Statement::class); $driverStatementMock = $this->createMock(Statement::class);
$driverStatementMock->expects(self::once()) $driverStatementMock->expects(self::once())
->method('fetch') ->method('fetchAssociative')
->with(FetchMode::ASSOCIATIVE)
->will(self::returnValue($result)); ->will(self::returnValue($result));
$conn = $this->getMockBuilder(Connection::class) $conn = $this->getMockBuilder(Connection::class)
...@@ -580,10 +578,10 @@ class ConnectionTest extends TestCase ...@@ -580,10 +578,10 @@ class ConnectionTest extends TestCase
->with($statement, $params, $types) ->with($statement, $params, $types)
->will(self::returnValue($driverStatementMock)); ->will(self::returnValue($driverStatementMock));
self::assertSame($result, $conn->fetchAssoc($statement, $params, $types)); self::assertSame($result, $conn->fetchAssociative($statement, $params, $types));
} }
public function testFetchArray() : void public function testFetchNumeric() : void
{ {
$statement = 'SELECT * FROM foo WHERE bar = ?'; $statement = 'SELECT * FROM foo WHERE bar = ?';
$params = [666]; $params = [666];
...@@ -601,8 +599,7 @@ class ConnectionTest extends TestCase ...@@ -601,8 +599,7 @@ class ConnectionTest extends TestCase
$driverStatementMock = $this->createMock(Statement::class); $driverStatementMock = $this->createMock(Statement::class);
$driverStatementMock->expects(self::once()) $driverStatementMock->expects(self::once())
->method('fetch') ->method('fetchNumeric')
->with(FetchMode::NUMERIC)
->will(self::returnValue($result)); ->will(self::returnValue($result));
$conn = $this->getMockBuilder(Connection::class) $conn = $this->getMockBuilder(Connection::class)
...@@ -615,10 +612,10 @@ class ConnectionTest extends TestCase ...@@ -615,10 +612,10 @@ class ConnectionTest extends TestCase
->with($statement, $params, $types) ->with($statement, $params, $types)
->will(self::returnValue($driverStatementMock)); ->will(self::returnValue($driverStatementMock));
self::assertSame($result, $conn->fetchArray($statement, $params, $types)); self::assertSame($result, $conn->fetchNumeric($statement, $params, $types));
} }
public function testFetchColumn() : void public function testFetchOne() : void
{ {
$statement = 'SELECT * FROM foo WHERE bar = ?'; $statement = 'SELECT * FROM foo WHERE bar = ?';
$params = [666]; $params = [666];
...@@ -636,7 +633,7 @@ class ConnectionTest extends TestCase ...@@ -636,7 +633,7 @@ class ConnectionTest extends TestCase
$driverStatementMock = $this->createMock(Statement::class); $driverStatementMock = $this->createMock(Statement::class);
$driverStatementMock->expects(self::once()) $driverStatementMock->expects(self::once())
->method('fetchColumn') ->method('fetchOne')
->will(self::returnValue($result)); ->will(self::returnValue($result));
$conn = $this->getMockBuilder(Connection::class) $conn = $this->getMockBuilder(Connection::class)
...@@ -649,10 +646,10 @@ class ConnectionTest extends TestCase ...@@ -649,10 +646,10 @@ class ConnectionTest extends TestCase
->with($statement, $params, $types) ->with($statement, $params, $types)
->will(self::returnValue($driverStatementMock)); ->will(self::returnValue($driverStatementMock));
self::assertSame($result, $conn->fetchColumn($statement, $params, $types)); self::assertSame($result, $conn->fetchOne($statement, $params, $types));
} }
public function testFetchAll() : void public function testFetchAllAssociative() : void
{ {
$statement = 'SELECT * FROM foo WHERE bar = ?'; $statement = 'SELECT * FROM foo WHERE bar = ?';
$params = [666]; $params = [666];
...@@ -670,7 +667,7 @@ class ConnectionTest extends TestCase ...@@ -670,7 +667,7 @@ class ConnectionTest extends TestCase
$driverStatementMock = $this->createMock(Statement::class); $driverStatementMock = $this->createMock(Statement::class);
$driverStatementMock->expects(self::once()) $driverStatementMock->expects(self::once())
->method('fetchAll') ->method('fetchAllAssociative')
->will(self::returnValue($result)); ->will(self::returnValue($result));
$conn = $this->getMockBuilder(Connection::class) $conn = $this->getMockBuilder(Connection::class)
...@@ -683,7 +680,7 @@ class ConnectionTest extends TestCase ...@@ -683,7 +680,7 @@ class ConnectionTest extends TestCase
->with($statement, $params, $types) ->with($statement, $params, $types)
->will(self::returnValue($driverStatementMock)); ->will(self::returnValue($driverStatementMock));
self::assertSame($result, $conn->fetchAll($statement, $params, $types)); self::assertSame($result, $conn->fetchAllAssociative($statement, $params, $types));
} }
public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() : void public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() : void
......
...@@ -29,7 +29,7 @@ class AbstractMySQLDriverTest extends AbstractDriverTest ...@@ -29,7 +29,7 @@ class AbstractMySQLDriverTest extends AbstractDriverTest
$statement = $this->createMock(ResultStatement::class); $statement = $this->createMock(ResultStatement::class);
$statement->expects(self::once()) $statement->expects(self::once())
->method('fetchColumn') ->method('fetchOne')
->will(self::returnValue($database)); ->will(self::returnValue($database));
$connection = $this->getConnectionMock(); $connection = $this->getConnectionMock();
......
...@@ -27,7 +27,7 @@ class AbstractPostgreSQLDriverTest extends AbstractDriverTest ...@@ -27,7 +27,7 @@ class AbstractPostgreSQLDriverTest extends AbstractDriverTest
$statement = $this->createMock(ResultStatement::class); $statement = $this->createMock(ResultStatement::class);
$statement->expects(self::once()) $statement->expects(self::once())
->method('fetchColumn') ->method('fetchOne')
->will(self::returnValue($database)); ->will(self::returnValue($database));
$connection = $this->getConnectionMock(); $connection = $this->getConnectionMock();
......
<?php
namespace Doctrine\DBAL\Tests\Driver;
use Doctrine\DBAL\Driver\IBMDB2\DB2Statement;
use Doctrine\DBAL\Driver\Mysqli\MysqliStatement;
use Doctrine\DBAL\Driver\OCI8\OCI8Statement;
use Doctrine\DBAL\Driver\SQLAnywhere\SQLAnywhereStatement;
use Doctrine\DBAL\Driver\SQLSrv\SQLSrvStatement;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\Portability\Statement as PortabilityStatement;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Traversable;
use function extension_loaded;
class StatementIteratorTest extends TestCase
{
/**
* @dataProvider statementProvider()
*/
public function testGettingIteratorDoesNotCallFetch(string $class) : void
{
$stmt = $this->createPartialMock($class, ['fetch', 'fetchAll', 'fetchColumn']);
$stmt->expects(self::never())->method('fetch');
$stmt->expects(self::never())->method('fetchAll');
$stmt->expects(self::never())->method('fetchColumn');
$stmt->getIterator();
}
public function testIteratorIterationCallsFetchOncePerStep() : void
{
$stmt = $this->createMock(Statement::class);
$calls = 0;
$this->configureStatement($stmt, $calls);
$stmtIterator = new StatementIterator($stmt);
$this->assertIterationCallsFetchOncePerStep($stmtIterator, $calls);
}
/**
* @dataProvider statementProvider()
*/
public function testStatementIterationCallsFetchOncePerStep(string $class) : void
{
$stmt = $this->createPartialMock($class, ['fetch']);
$calls = 0;
$this->configureStatement($stmt, $calls);
$this->assertIterationCallsFetchOncePerStep($stmt, $calls);
}
private function configureStatement(MockObject $stmt, int &$calls) : void
{
$values = ['foo', '', 'bar', '0', 'baz', 0, 'qux', null, 'quz', false, 'impossible'];
$calls = 0;
$stmt->expects(self::exactly(10))
->method('fetch')
->willReturnCallback(static function () use ($values, &$calls) {
$value = $values[$calls];
$calls++;
return $value;
});
}
/**
* @param Traversable<int, mixed> $iterator
*/
private function assertIterationCallsFetchOncePerStep(Traversable $iterator, int &$calls) : void
{
foreach ($iterator as $i => $_) {
self::assertEquals($i + 1, $calls);
}
}
/**
* @return string[][]
*/
public static function statementProvider() : iterable
{
if (extension_loaded('ibm_db2')) {
yield [DB2Statement::class];
}
yield [MysqliStatement::class];
if (extension_loaded('oci8')) {
yield [OCI8Statement::class];
}
yield [PortabilityStatement::class];
yield [SQLAnywhereStatement::class];
if (! extension_loaded('sqlsrv')) {
return;
}
yield [SQLSrvStatement::class];
}
}
...@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Tests\Functional; ...@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Tests\Functional;
use Doctrine\DBAL\Driver\OCI8\Driver as OCI8Driver; use Doctrine\DBAL\Driver\OCI8\Driver as OCI8Driver;
use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver; use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase; use Doctrine\DBAL\Tests\FunctionalTestCase;
...@@ -158,7 +157,7 @@ class BlobTest extends FunctionalTestCase ...@@ -158,7 +157,7 @@ class BlobTest extends FunctionalTestCase
private function assertBlobContains(string $text) : void private function assertBlobContains(string $text) : void
{ {
$rows = $this->connection->query('SELECT blobfield FROM blob_table')->fetchAll(FetchMode::COLUMN); $rows = $this->connection->query('SELECT blobfield FROM blob_table')->fetchColumn();
self::assertCount(1, $rows); self::assertCount(1, $rows);
......
<?php
namespace Doctrine\DBAL\Tests\Functional\Connection\BackwardCompatibility;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Connection as BaseConnection;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use function func_get_args;
/**
* Wraps statements in a non-forward-compatible wrapper.
*/
class Connection extends BaseConnection
{
/**
* {@inheritdoc}
*/
public function executeQuery(string $query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) : ResultStatement
{
return new Statement(parent::executeQuery($query, $params, $types, $qcp));
}
public function prepare(string $sql) : DriverStatement
{
return new Statement(parent::prepare($sql));
}
public function query(string $sql) : ResultStatement
{
return new Statement(parent::query(...func_get_args()));
}
}
<?php
namespace Doctrine\DBAL\Tests\Functional\Connection\BackwardCompatibility;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Tests\Functional\Connection\FetchTest as BaseFetchTest;
use function array_merge;
class FetchTest extends BaseFetchTest
{
public function setUp() : void
{
parent::setUp();
$this->connection = DriverManager::getConnection(
array_merge($this->connection->getParams(), [
'wrapperClass' => Connection::class,
]),
$this->connection->getConfiguration(),
$this->connection->getEventManager()
);
}
}
<?php
namespace Doctrine\DBAL\Tests\Functional\Connection\BackwardCompatibility;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use function assert;
/**
* A wrapper that does not implement the forward-compatible statement interface.
*/
class Statement implements IteratorAggregate, DriverStatement
{
/** @var DriverStatement|ResultStatement */
private $stmt;
/**
* @param DriverStatement|ResultStatement $stmt
*/
public function __construct($stmt)
{
$this->stmt = $stmt;
}
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
{
assert($this->stmt instanceof DriverStatement);
return $this->stmt->bindParam($column, $variable, $type, $length);
}
/**
* {@inheritdoc}
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
{
assert($this->stmt instanceof DriverStatement);
return $this->stmt->bindValue($param, $value, $type);
}
/**
* {@inheritdoc}
*/
public function closeCursor()
{
return $this->stmt->closeCursor();
}
/**
* {@inheritdoc}
*/
public function columnCount()
{
return $this->stmt->columnCount();
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
assert($this->stmt instanceof DriverStatement);
return $this->stmt->errorCode();
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
assert($this->stmt instanceof DriverStatement);
return $this->stmt->errorInfo();
}
/**
* {@inheritdoc}
*/
public function execute($params = null)
{
assert($this->stmt instanceof DriverStatement);
return $this->stmt->execute($params);
}
/**
* {@inheritdoc}
*
* @deprecated Use one of the fetch- or iterate-related methods.
*/
public function setFetchMode($fetchMode)
{
return $this->stmt->setFetchMode($fetchMode);
}
/**
* {@inheritdoc}
*
* @deprecated Use iterateNumeric(), iterateAssociative() or iterateColumn() instead.
*/
public function getIterator()
{
return new StatementIterator($this);
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchNumeric(), fetchAssociative() or fetchOne() instead.
*/
public function fetch($fetchMode = null)
{
return $this->stmt->fetch($fetchMode);
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchColumn() instead.
*/
public function fetchAll($fetchMode = null)
{
return $this->stmt->fetchAll($fetchMode);
}
/**
* {@inheritdoc}
*
* @deprecated Use fetchOne() instead.
*/
public function fetchColumn()
{
return $this->stmt->fetchColumn();
}
public function rowCount() : int
{
assert($this->stmt instanceof DriverStatement);
return $this->stmt->rowCount();
}
}
...@@ -116,7 +116,7 @@ class ConnectionTest extends FunctionalTestCase ...@@ -116,7 +116,7 @@ class ConnectionTest extends FunctionalTestCase
$connection->executeQuery('insert into test_nesting values (33)'); $connection->executeQuery('insert into test_nesting values (33)');
$connection->rollBack(); $connection->rollBack();
self::assertEquals(0, $connection->fetchColumn('select count(*) from test_nesting')); self::assertEquals(0, $connection->fetchOne('select count(*) from test_nesting'));
} }
public function testTransactionNestingBehaviorWithSavepoints() : void public function testTransactionNestingBehaviorWithSavepoints() : void
......
This diff is collapsed.
...@@ -33,7 +33,7 @@ class StatementTest extends FunctionalTestCase ...@@ -33,7 +33,7 @@ class StatementTest extends FunctionalTestCase
{ {
self::assertEquals( self::assertEquals(
$expected, $expected,
$this->connection->executeQuery($query, $params)->fetch() $this->connection->executeQuery($query, $params)->fetchAssociative()
); );
} }
...@@ -52,7 +52,7 @@ class StatementTest extends FunctionalTestCase ...@@ -52,7 +52,7 @@ class StatementTest extends FunctionalTestCase
self::assertEquals( self::assertEquals(
$expected, $expected,
$stmt->fetch() $stmt->fetchAssociative()
); );
} }
......
...@@ -85,7 +85,7 @@ class DriverTest extends AbstractDriverTest ...@@ -85,7 +85,7 @@ class DriverTest extends AbstractDriverTest
$hash = microtime(true); // required to identify the record in the results uniquely $hash = microtime(true); // required to identify the record in the results uniquely
$sql = sprintf('SELECT * FROM pg_stat_activity WHERE %d = %d', $hash, $hash); $sql = sprintf('SELECT * FROM pg_stat_activity WHERE %d = %d', $hash, $hash);
$statement = $connection->query($sql); $statement = $connection->query($sql);
$records = $statement->fetchAll(); $records = $statement->fetchAllAssociative();
foreach ($records as $record) { foreach ($records as $record) {
// The query column is named "current_query" on PostgreSQL < 9.2 // The query column is named "current_query" on PostgreSQL < 9.2
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Doctrine\DBAL\Tests\Functional\Driver; namespace Doctrine\DBAL\Tests\Functional\Driver;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Tests\FunctionalTestCase; use Doctrine\DBAL\Tests\FunctionalTestCase;
use function extension_loaded; use function extension_loaded;
...@@ -44,7 +43,7 @@ class PDOPgsqlConnectionTest extends FunctionalTestCase ...@@ -44,7 +43,7 @@ class PDOPgsqlConnectionTest extends FunctionalTestCase
self::assertEquals( self::assertEquals(
$charset, $charset,
$connection->query('SHOW client_encoding') $connection->query('SHOW client_encoding')
->fetch(FetchMode::COLUMN) ->fetchOne()
); );
} }
......
...@@ -57,7 +57,7 @@ class DriverTest extends AbstractDriverTest ...@@ -57,7 +57,7 @@ class DriverTest extends AbstractDriverTest
public function testConnectionOptions() : void public function testConnectionOptions() : void
{ {
$connection = $this->getConnection(['APP' => 'APP_NAME']); $connection = $this->getConnection(['APP' => 'APP_NAME']);
$result = $connection->query('SELECT APP_NAME()')->fetchColumn(); $result = $connection->query('SELECT APP_NAME()')->fetchOne();
self::assertSame('APP_NAME', $result); self::assertSame('APP_NAME', $result);
} }
......
...@@ -23,6 +23,6 @@ final class LikeWildcardsEscapingTest extends FunctionalTestCase ...@@ -23,6 +23,6 @@ final class LikeWildcardsEscapingTest extends FunctionalTestCase
) )
); );
$stmt->execute(); $stmt->execute();
self::assertTrue((bool) $stmt->fetchColumn()); self::assertTrue((bool) $stmt->fetchOne());
} }
} }
...@@ -89,7 +89,7 @@ class MasterSlaveConnectionTest extends FunctionalTestCase ...@@ -89,7 +89,7 @@ class MasterSlaveConnectionTest extends FunctionalTestCase
self::assertFalse($conn->isConnectedToMaster()); self::assertFalse($conn->isConnectedToMaster());
$clientCharset = $conn->fetchColumn('select @@character_set_client as c'); $clientCharset = $conn->fetchOne('select @@character_set_client as c');
self::assertSame( self::assertSame(
$charset, $charset,
...@@ -114,7 +114,7 @@ class MasterSlaveConnectionTest extends FunctionalTestCase ...@@ -114,7 +114,7 @@ class MasterSlaveConnectionTest extends FunctionalTestCase
$conn = $this->createMasterSlaveConnection(); $conn = $this->createMasterSlaveConnection();
$sql = 'SELECT count(*) as num FROM master_slave_table'; $sql = 'SELECT count(*) as num FROM master_slave_table';
$data = $conn->fetchAll($sql); $data = $conn->fetchAllAssociative($sql);
$data[0] = array_change_key_case($data[0], CASE_LOWER); $data[0] = array_change_key_case($data[0], CASE_LOWER);
self::assertEquals(1, $data[0]['num']); self::assertEquals(1, $data[0]['num']);
...@@ -129,7 +129,7 @@ class MasterSlaveConnectionTest extends FunctionalTestCase ...@@ -129,7 +129,7 @@ class MasterSlaveConnectionTest extends FunctionalTestCase
self::assertTrue($conn->isConnectedToMaster()); self::assertTrue($conn->isConnectedToMaster());
$sql = 'SELECT count(*) as num FROM master_slave_table'; $sql = 'SELECT count(*) as num FROM master_slave_table';
$data = $conn->fetchAll($sql); $data = $conn->fetchAllAssociative($sql);
$data[0] = array_change_key_case($data[0], CASE_LOWER); $data[0] = array_change_key_case($data[0], CASE_LOWER);
self::assertEquals(2, $data[0]['num']); self::assertEquals(2, $data[0]['num']);
...@@ -202,9 +202,8 @@ class MasterSlaveConnectionTest extends FunctionalTestCase ...@@ -202,9 +202,8 @@ class MasterSlaveConnectionTest extends FunctionalTestCase
//Query must be executed only on Master //Query must be executed only on Master
self::assertTrue($conn->isConnectedToMaster()); self::assertTrue($conn->isConnectedToMaster());
$data = $statement->fetchAll(); $data = $statement->fetchAllAssociative();
//Default fetchmode is FetchMode::ASSOCIATIVE
self::assertArrayHasKey(0, $data); self::assertArrayHasKey(0, $data);
self::assertArrayHasKey('num', $data[0]); self::assertArrayHasKey('num', $data[0]);
...@@ -227,9 +226,8 @@ class MasterSlaveConnectionTest extends FunctionalTestCase ...@@ -227,9 +226,8 @@ class MasterSlaveConnectionTest extends FunctionalTestCase
//Query must be executed only on Master, even when we connect to the slave //Query must be executed only on Master, even when we connect to the slave
self::assertTrue($conn->isConnectedToMaster()); self::assertTrue($conn->isConnectedToMaster());
$data = $statement->fetchAll(); $data = $statement->fetchAllAssociative();
//Default fetchmode is FetchMode::ASSOCIATIVE
self::assertArrayHasKey(0, $data); self::assertArrayHasKey(0, $data);
self::assertArrayHasKey('num', $data[0]); self::assertArrayHasKey('num', $data[0]);
......
...@@ -169,7 +169,7 @@ SQL; ...@@ -169,7 +169,7 @@ SQL;
{ {
$p = $this->connection->getDatabasePlatform(); $p = $this->connection->getDatabasePlatform();
$data = []; $data = [];
foreach ($this->connection->fetchAll($p->modifyLimitQuery($sql, $limit, $offset)) as $row) { foreach ($this->connection->fetchAllAssociative($p->modifyLimitQuery($sql, $limit, $offset)) as $row) {
$row = array_change_key_case($row, CASE_LOWER); $row = array_change_key_case($row, CASE_LOWER);
$data[] = $row['test_int']; $data[] = $row['test_int'];
} }
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Doctrine\DBAL\Tests\Functional; namespace Doctrine\DBAL\Tests\Functional;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase; use Doctrine\DBAL\Tests\FunctionalTestCase;
...@@ -213,7 +212,7 @@ class NamedParametersTest extends FunctionalTestCase ...@@ -213,7 +212,7 @@ class NamedParametersTest extends FunctionalTestCase
public function testTicket(string $query, array $params, array $types, array $expected) : void public function testTicket(string $query, array $params, array $types, array $expected) : void
{ {
$stmt = $this->connection->executeQuery($query, $params, $types); $stmt = $this->connection->executeQuery($query, $params, $types);
$result = $stmt->fetchAll(FetchMode::ASSOCIATIVE); $result = $stmt->fetchAllAssociative();
foreach ($result as $k => $v) { foreach ($result as $k => $v) {
$result[$k] = array_change_key_case($v, CASE_LOWER); $result[$k] = array_change_key_case($v, CASE_LOWER);
......
...@@ -26,7 +26,7 @@ class DateExpressionTest extends FunctionalTestCase ...@@ -26,7 +26,7 @@ class DateExpressionTest extends FunctionalTestCase
$platform = $this->connection->getDatabasePlatform(); $platform = $this->connection->getDatabasePlatform();
$sql = sprintf('SELECT %s FROM date_expr_test', $platform->getDateDiffExpression('date1', 'date2')); $sql = sprintf('SELECT %s FROM date_expr_test', $platform->getDateDiffExpression('date1', 'date2'));
$diff = $this->connection->query($sql)->fetchColumn(); $diff = $this->connection->query($sql)->fetchOne();
self::assertEquals($expected, $diff); self::assertEquals($expected, $diff);
} }
......
...@@ -4,7 +4,6 @@ declare(strict_types=1); ...@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Functional\Platform; namespace Doctrine\DBAL\Tests\Functional\Platform;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\OraclePlatform;
...@@ -71,7 +70,7 @@ class DefaultExpressionTest extends FunctionalTestCase ...@@ -71,7 +70,7 @@ class DefaultExpressionTest extends FunctionalTestCase
[$actualValue, $defaultValue] = $this->connection->query( [$actualValue, $defaultValue] = $this->connection->query(
'SELECT default_value, actual_value FROM default_expr_test' 'SELECT default_value, actual_value FROM default_expr_test'
)->fetch(FetchMode::NUMERIC); )->fetchNumeric();
self::assertEquals($actualValue, $defaultValue); self::assertEquals($actualValue, $defaultValue);
} }
......
...@@ -16,7 +16,7 @@ class QuotingTest extends FunctionalTestCase ...@@ -16,7 +16,7 @@ class QuotingTest extends FunctionalTestCase
$platform->quoteStringLiteral($string) $platform->quoteStringLiteral($string)
); );
self::assertSame($string, $this->connection->fetchColumn($query)); self::assertSame($string, $this->connection->fetchOne($query));
} }
/** /**
......
...@@ -5,7 +5,6 @@ namespace Doctrine\DBAL\Tests\Functional; ...@@ -5,7 +5,6 @@ namespace Doctrine\DBAL\Tests\Functional;
use Doctrine\DBAL\ColumnCase; use Doctrine\DBAL\ColumnCase;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Portability\Connection as ConnectionPortability; use Doctrine\DBAL\Portability\Connection as ConnectionPortability;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase; use Doctrine\DBAL\Tests\FunctionalTestCase;
...@@ -63,26 +62,19 @@ class PortabilityTest extends FunctionalTestCase ...@@ -63,26 +62,19 @@ class PortabilityTest extends FunctionalTestCase
public function testFullFetchMode() : void public function testFullFetchMode() : void
{ {
$rows = $this->getPortableConnection()->fetchAll('SELECT * FROM portability_table'); $rows = $this->getPortableConnection()->fetchAllAssociative('SELECT * FROM portability_table');
$this->assertFetchResultRows($rows); $this->assertFetchResultRows($rows);
$stmt = $this->getPortableConnection()->query('SELECT * FROM portability_table'); $stmt = $this->getPortableConnection()->query('SELECT * FROM portability_table');
$stmt->setFetchMode(FetchMode::ASSOCIATIVE);
foreach ($stmt as $row) { while (($row = $stmt->fetchAssociative())) {
$this->assertFetchResultRow($row);
}
$stmt = $this->getPortableConnection()->query('SELECT * FROM portability_table');
while (($row = $stmt->fetch(FetchMode::ASSOCIATIVE))) {
$this->assertFetchResultRow($row); $this->assertFetchResultRow($row);
} }
$stmt = $this->getPortableConnection()->prepare('SELECT * FROM portability_table'); $stmt = $this->getPortableConnection()->prepare('SELECT * FROM portability_table');
$stmt->execute(); $stmt->execute();
while (($row = $stmt->fetch(FetchMode::ASSOCIATIVE))) { while (($row = $stmt->fetchAssociative())) {
$this->assertFetchResultRow($row); $this->assertFetchResultRow($row);
} }
} }
...@@ -90,24 +82,18 @@ class PortabilityTest extends FunctionalTestCase ...@@ -90,24 +82,18 @@ class PortabilityTest extends FunctionalTestCase
public function testConnFetchMode() : void public function testConnFetchMode() : void
{ {
$conn = $this->getPortableConnection(); $conn = $this->getPortableConnection();
$conn->setFetchMode(FetchMode::ASSOCIATIVE);
$rows = $conn->fetchAll('SELECT * FROM portability_table'); $rows = $conn->fetchAllAssociative('SELECT * FROM portability_table');
$this->assertFetchResultRows($rows); $this->assertFetchResultRows($rows);
$stmt = $conn->query('SELECT * FROM portability_table'); $stmt = $conn->query('SELECT * FROM portability_table');
foreach ($stmt as $row) { while (($row = $stmt->fetchAssociative())) {
$this->assertFetchResultRow($row);
}
$stmt = $conn->query('SELECT * FROM portability_table');
while (($row = $stmt->fetch())) {
$this->assertFetchResultRow($row); $this->assertFetchResultRow($row);
} }
$stmt = $conn->prepare('SELECT * FROM portability_table'); $stmt = $conn->prepare('SELECT * FROM portability_table');
$stmt->execute(); $stmt->execute();
while (($row = $stmt->fetch())) { while (($row = $stmt->fetchAssociative())) {
$this->assertFetchResultRow($row); $this->assertFetchResultRow($row);
} }
} }
...@@ -142,21 +128,21 @@ class PortabilityTest extends FunctionalTestCase ...@@ -142,21 +128,21 @@ class PortabilityTest extends FunctionalTestCase
/** /**
* @param mixed[] $expected * @param mixed[] $expected
* *
* @dataProvider fetchAllColumnProvider * @dataProvider fetchColumnProvider
*/ */
public function testFetchAllColumn(string $field, array $expected) : void public function testfetchColumn(string $field, array $expected) : void
{ {
$conn = $this->getPortableConnection(); $conn = $this->getPortableConnection();
$stmt = $conn->query('SELECT ' . $field . ' FROM portability_table'); $stmt = $conn->query('SELECT ' . $field . ' FROM portability_table');
$column = $stmt->fetchAll(FetchMode::COLUMN); $column = $stmt->fetchColumn();
self::assertEquals($expected, $column); self::assertEquals($expected, $column);
} }
/** /**
* @return iterable<string, array<int, mixed>> * @return iterable<string, array<int, mixed>>
*/ */
public static function fetchAllColumnProvider() : iterable public static function fetchColumnProvider() : iterable
{ {
return [ return [
'int' => [ 'int' => [
...@@ -175,7 +161,7 @@ class PortabilityTest extends FunctionalTestCase ...@@ -175,7 +161,7 @@ class PortabilityTest extends FunctionalTestCase
$conn = $this->getPortableConnection(); $conn = $this->getPortableConnection();
$stmt = $conn->query('SELECT Test_Null FROM portability_table'); $stmt = $conn->query('SELECT Test_Null FROM portability_table');
$column = $stmt->fetchAll(FetchMode::COLUMN); $column = $stmt->fetchColumn();
self::assertSame([null, null], $column); self::assertSame([null, null], $column);
} }
} }
This diff is collapsed.
...@@ -63,7 +63,7 @@ class DefaultValueTest extends FunctionalTestCase ...@@ -63,7 +63,7 @@ class DefaultValueTest extends FunctionalTestCase
*/ */
public function testEscapedDefaultValueCanBeInserted(string $name, ?string $expectedDefault) : void public function testEscapedDefaultValueCanBeInserted(string $name, ?string $expectedDefault) : void
{ {
$value = $this->connection->fetchColumn( $value = $this->connection->fetchOne(
sprintf('SELECT %s FROM default_value', $name) sprintf('SELECT %s FROM default_value', $name)
); );
......
...@@ -462,7 +462,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -462,7 +462,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
'INSERT INTO test_column_defaults_are_valid () VALUES()' 'INSERT INTO test_column_defaults_are_valid () VALUES()'
); );
$row = $this->connection->fetchAssoc( $row = $this->connection->fetchAssociative(
'SELECT *, DATEDIFF(CURRENT_TIMESTAMP(), col_datetime) as diff_seconds FROM test_column_defaults_are_valid' 'SELECT *, DATEDIFF(CURRENT_TIMESTAMP(), col_datetime) as diff_seconds FROM test_column_defaults_are_valid'
); );
......
...@@ -1562,7 +1562,7 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase ...@@ -1562,7 +1562,7 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
$query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'1\''); $query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'1\'');
$query->execute(); $query->execute();
$lastUsedIdBeforeDelete = (int) $query->fetchColumn(); $lastUsedIdBeforeDelete = (int) $query->fetchOne();
$this->connection->query('DELETE FROM test_pk_auto_increment'); $this->connection->query('DELETE FROM test_pk_auto_increment');
...@@ -1570,7 +1570,7 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase ...@@ -1570,7 +1570,7 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
$query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'2\''); $query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'2\'');
$query->execute(); $query->execute();
$lastUsedIdAfterDelete = (int) $query->fetchColumn(); $lastUsedIdAfterDelete = (int) $query->fetchOne();
self::assertGreaterThan($lastUsedIdBeforeDelete, $lastUsedIdAfterDelete); self::assertGreaterThan($lastUsedIdBeforeDelete, $lastUsedIdAfterDelete);
} }
......
...@@ -274,7 +274,7 @@ SQL; ...@@ -274,7 +274,7 @@ SQL;
$query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = "2"'); $query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = "2"');
$query->execute(); $query->execute();
$lastUsedIdAfterDelete = (int) $query->fetchColumn(); $lastUsedIdAfterDelete = (int) $query->fetchOne();
// with an empty table, non autoincrement rowid is always 1 // with an empty table, non autoincrement rowid is always 1
self::assertEquals(1, $lastUsedIdAfterDelete); self::assertEquals(1, $lastUsedIdAfterDelete);
......
...@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Tests\Functional; ...@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Tests\Functional;
use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver; use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver;
use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase; use Doctrine\DBAL\Tests\FunctionalTestCase;
...@@ -37,15 +36,15 @@ class StatementTest extends FunctionalTestCase ...@@ -37,15 +36,15 @@ class StatementTest extends FunctionalTestCase
$stmt->execute(); $stmt->execute();
$id = $stmt->fetchColumn(); $id = $stmt->fetchOne();
self::assertEquals(1, $id); self::assertEquals(1, $id);
$stmt->closeCursor(); $stmt->closeCursor();
$stmt->execute(); $stmt->execute();
$id = $stmt->fetchColumn(); $id = $stmt->fetchOne();
self::assertEquals(1, $id); self::assertEquals(1, $id);
$id = $stmt->fetchColumn(); $id = $stmt->fetchOne();
self::assertEquals(2, $id); self::assertEquals(2, $id);
} }
...@@ -71,7 +70,7 @@ class StatementTest extends FunctionalTestCase ...@@ -71,7 +70,7 @@ class StatementTest extends FunctionalTestCase
$stmt->execute(); $stmt->execute();
self::assertEquals([ self::assertEquals([
['param1', 'X'], ['param1', 'X'],
], $stmt->fetchAll(FetchMode::NUMERIC)); ], $stmt->fetchAllNumeric());
$row2 = [ $row2 = [
'param' => 'param2', 'param' => 'param2',
...@@ -83,7 +82,7 @@ class StatementTest extends FunctionalTestCase ...@@ -83,7 +82,7 @@ class StatementTest extends FunctionalTestCase
self::assertEquals([ self::assertEquals([
['param1', 'X'], ['param1', 'X'],
['param2', 'A bit longer value'], ['param2', 'A bit longer value'],
], $stmt->fetchAll(FetchMode::NUMERIC)); ], $stmt->fetchAllNumeric());
} }
public function testFetchLongBlob() : void public function testFetchLongBlob() : void
...@@ -127,7 +126,7 @@ EOF ...@@ -127,7 +126,7 @@ EOF
$stream = Type::getType('blob') $stream = Type::getType('blob')
->convertToPHPValue( ->convertToPHPValue(
$stmt->fetchColumn(), $stmt->fetchOne(),
$this->connection->getDatabasePlatform() $this->connection->getDatabasePlatform()
); );
...@@ -141,14 +140,14 @@ EOF ...@@ -141,14 +140,14 @@ EOF
$stmt1 = $this->connection->prepare('SELECT id FROM stmt_test'); $stmt1 = $this->connection->prepare('SELECT id FROM stmt_test');
$stmt1->execute(); $stmt1->execute();
$stmt1->fetch(); $stmt1->fetchAssociative();
$stmt1->execute(); $stmt1->execute();
// fetching only one record out of two // fetching only one record out of two
$stmt1->fetch(); $stmt1->fetchAssociative();
$stmt2 = $this->connection->prepare('SELECT id FROM stmt_test WHERE id = ?'); $stmt2 = $this->connection->prepare('SELECT id FROM stmt_test WHERE id = ?');
$stmt2->execute([1]); $stmt2->execute([1]);
self::assertEquals(1, $stmt2->fetchColumn()); self::assertEquals(1, $stmt2->fetchOne());
} }
public function testReuseStatementAfterClosingCursor() : void public function testReuseStatementAfterClosingCursor() : void
...@@ -163,13 +162,13 @@ EOF ...@@ -163,13 +162,13 @@ EOF
$stmt = $this->connection->prepare('SELECT id FROM stmt_test WHERE id = ?'); $stmt = $this->connection->prepare('SELECT id FROM stmt_test WHERE id = ?');
$stmt->execute([1]); $stmt->execute([1]);
$id = $stmt->fetchColumn(); $id = $stmt->fetchOne();
self::assertEquals(1, $id); self::assertEquals(1, $id);
$stmt->closeCursor(); $stmt->closeCursor();
$stmt->execute([2]); $stmt->execute([2]);
$id = $stmt->fetchColumn(); $id = $stmt->fetchOne();
self::assertEquals(2, $id); self::assertEquals(2, $id);
} }
...@@ -183,11 +182,11 @@ EOF ...@@ -183,11 +182,11 @@ EOF
$id = 1; $id = 1;
$stmt->execute(); $stmt->execute();
self::assertEquals(1, $stmt->fetchColumn()); self::assertEquals(1, $stmt->fetchOne());
$id = 2; $id = 2;
$stmt->execute(); $stmt->execute();
self::assertEquals(2, $stmt->fetchColumn()); self::assertEquals(2, $stmt->fetchOne());
} }
public function testReuseStatementWithReboundValue() : void public function testReuseStatementWithReboundValue() : void
...@@ -199,11 +198,11 @@ EOF ...@@ -199,11 +198,11 @@ EOF
$stmt->bindValue(1, 1); $stmt->bindValue(1, 1);
$stmt->execute(); $stmt->execute();
self::assertEquals(1, $stmt->fetchColumn()); self::assertEquals(1, $stmt->fetchOne());
$stmt->bindValue(1, 2); $stmt->bindValue(1, 2);
$stmt->execute(); $stmt->execute();
self::assertEquals(2, $stmt->fetchColumn()); self::assertEquals(2, $stmt->fetchOne());
} }
public function testReuseStatementWithReboundParam() : void public function testReuseStatementWithReboundParam() : void
...@@ -216,12 +215,12 @@ EOF ...@@ -216,12 +215,12 @@ EOF
$x = 1; $x = 1;
$stmt->bindParam(1, $x); $stmt->bindParam(1, $x);
$stmt->execute(); $stmt->execute();
self::assertEquals(1, $stmt->fetchColumn()); self::assertEquals(1, $stmt->fetchOne());
$y = 2; $y = 2;
$stmt->bindParam(1, $y); $stmt->bindParam(1, $y);
$stmt->execute(); $stmt->execute();
self::assertEquals(2, $stmt->fetchColumn()); self::assertEquals(2, $stmt->fetchOne());
} }
/** /**
...@@ -250,7 +249,7 @@ EOF ...@@ -250,7 +249,7 @@ EOF
$stmt = $this->connection->prepare('SELECT name FROM stmt_test'); $stmt = $this->connection->prepare('SELECT name FROM stmt_test');
$stmt->execute(); $stmt->execute();
$stmt->fetch(); $stmt->fetchAssociative();
self::assertTrue($stmt->closeCursor()); self::assertTrue($stmt->closeCursor());
} }
...@@ -292,19 +291,19 @@ EOF ...@@ -292,19 +291,19 @@ EOF
return [ return [
'fetch' => [ 'fetch' => [
static function (Statement $stmt) { static function (Statement $stmt) {
return $stmt->fetch(); return $stmt->fetchAssociative();
}, },
false, false,
], ],
'fetch-column' => [ 'fetch-column' => [
static function (Statement $stmt) { static function (Statement $stmt) {
return $stmt->fetchColumn(); return $stmt->fetchOne();
}, },
false, false,
], ],
'fetch-all' => [ 'fetch-all' => [
static function (Statement $stmt) : array { static function (Statement $stmt) : array {
return $stmt->fetchAll(); return $stmt->fetchAllAssociative();
}, },
[], [],
], ],
...@@ -315,7 +314,7 @@ EOF ...@@ -315,7 +314,7 @@ EOF
{ {
$platform = $this->connection->getDatabasePlatform(); $platform = $this->connection->getDatabasePlatform();
$query = $platform->getDummySelectSQL(); $query = $platform->getDummySelectSQL();
$result = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN); $result = $this->connection->executeQuery($query)->fetchOne();
self::assertEquals(1, $result); self::assertEquals(1, $result);
} }
......
...@@ -62,7 +62,7 @@ class TemporaryTableTest extends FunctionalTestCase ...@@ -62,7 +62,7 @@ class TemporaryTableTest extends FunctionalTestCase
$this->connection->rollBack(); $this->connection->rollBack();
$rows = $this->connection->fetchAll('SELECT * FROM nontemporary'); $rows = $this->connection->fetchAllAssociative('SELECT * FROM nontemporary');
self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.'); self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.');
} }
...@@ -102,7 +102,7 @@ class TemporaryTableTest extends FunctionalTestCase ...@@ -102,7 +102,7 @@ class TemporaryTableTest extends FunctionalTestCase
} catch (Throwable $e) { } catch (Throwable $e) {
} }
$rows = $this->connection->fetchAll('SELECT * FROM nontemporary'); $rows = $this->connection->fetchAllAssociative('SELECT * FROM nontemporary');
self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.'); self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.');
} }
} }
...@@ -36,7 +36,7 @@ class DBAL202Test extends FunctionalTestCase ...@@ -36,7 +36,7 @@ class DBAL202Test extends FunctionalTestCase
$stmt->execute(); $stmt->execute();
$this->connection->rollBack(); $this->connection->rollBack();
self::assertEquals(0, $this->connection->query('SELECT COUNT(1) FROM DBAL202')->fetchColumn()); self::assertEquals(0, $this->connection->query('SELECT COUNT(1) FROM DBAL202')->fetchOne());
} }
public function testStatementCommit() : void public function testStatementCommit() : void
...@@ -46,6 +46,6 @@ class DBAL202Test extends FunctionalTestCase ...@@ -46,6 +46,6 @@ class DBAL202Test extends FunctionalTestCase
$stmt->execute(); $stmt->execute();
$this->connection->commit(); $this->connection->commit();
self::assertEquals(1, $this->connection->query('SELECT COUNT(1) FROM DBAL202')->fetchColumn()); self::assertEquals(1, $this->connection->query('SELECT COUNT(1) FROM DBAL202')->fetchOne());
} }
} }
...@@ -25,7 +25,7 @@ class DBAL421Test extends FunctionalTestCase ...@@ -25,7 +25,7 @@ class DBAL421Test extends FunctionalTestCase
public function testGuidShouldMatchPattern() : void public function testGuidShouldMatchPattern() : void
{ {
$guid = $this->connection->query($this->getSelectGuidSql())->fetchColumn(); $guid = $this->connection->query($this->getSelectGuidSql())->fetchOne();
$pattern = '/[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[8-9A-B][0-9A-F]{3}\-[0-9A-F]{12}/i'; $pattern = '/[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[8-9A-B][0-9A-F]{3}\-[0-9A-F]{12}/i';
self::assertEquals(1, preg_match($pattern, $guid), 'GUID does not match pattern'); self::assertEquals(1, preg_match($pattern, $guid), 'GUID does not match pattern');
} }
......
...@@ -50,7 +50,7 @@ class DBAL630Test extends FunctionalTestCase ...@@ -50,7 +50,7 @@ class DBAL630Test extends FunctionalTestCase
$id = $this->connection->lastInsertId('dbal630_id_seq'); $id = $this->connection->lastInsertId('dbal630_id_seq');
self::assertNotEmpty($id); self::assertNotEmpty($id);
$row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); $row = $this->connection->fetchAssociative('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]);
self::assertFalse($row['bool_col']); self::assertFalse($row['bool_col']);
} }
...@@ -65,7 +65,7 @@ class DBAL630Test extends FunctionalTestCase ...@@ -65,7 +65,7 @@ class DBAL630Test extends FunctionalTestCase
$id = $this->connection->lastInsertId('dbal630_id_seq'); $id = $this->connection->lastInsertId('dbal630_id_seq');
self::assertNotEmpty($id); self::assertNotEmpty($id);
$row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); $row = $this->connection->fetchAssociative('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]);
self::assertFalse($row['bool_col']); self::assertFalse($row['bool_col']);
} }
...@@ -86,7 +86,7 @@ class DBAL630Test extends FunctionalTestCase ...@@ -86,7 +86,7 @@ class DBAL630Test extends FunctionalTestCase
self::assertNotEmpty($id); self::assertNotEmpty($id);
$row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); $row = $this->connection->fetchAssociative('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]);
self::assertFalse($row['bool_col']); self::assertFalse($row['bool_col']);
} }
...@@ -112,7 +112,7 @@ class DBAL630Test extends FunctionalTestCase ...@@ -112,7 +112,7 @@ class DBAL630Test extends FunctionalTestCase
self::assertNotEmpty($id); self::assertNotEmpty($id);
$row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); $row = $this->connection->fetchAssociative('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]);
self::assertSame($databaseConvertedValue, $row['bool_col']); self::assertSame($databaseConvertedValue, $row['bool_col']);
} }
...@@ -142,7 +142,7 @@ class DBAL630Test extends FunctionalTestCase ...@@ -142,7 +142,7 @@ class DBAL630Test extends FunctionalTestCase
self::assertNotEmpty($id); self::assertNotEmpty($id);
$row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); $row = $this->connection->fetchAssociative('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]);
self::assertSame($databaseConvertedValue, $row['bool_col']); self::assertSame($databaseConvertedValue, $row['bool_col']);
} }
......
...@@ -244,7 +244,7 @@ class TypeConversionTest extends FunctionalTestCase ...@@ -244,7 +244,7 @@ class TypeConversionTest extends FunctionalTestCase
$sql = 'SELECT ' . $columnName . ' FROM type_conversion WHERE id = ' . self::$typeCounter; $sql = 'SELECT ' . $columnName . ' FROM type_conversion WHERE id = ' . self::$typeCounter;
return $typeInstance->convertToPHPValue( return $typeInstance->convertToPHPValue(
$this->connection->fetchColumn($sql), $this->connection->fetchOne($sql),
$this->connection->getDatabasePlatform() $this->connection->getDatabasePlatform()
); );
} }
......
...@@ -75,7 +75,7 @@ class BinaryTest extends FunctionalTestCase ...@@ -75,7 +75,7 @@ class BinaryTest extends FunctionalTestCase
*/ */
private function select(string $id) private function select(string $id)
{ {
$value = $this->connection->fetchColumn( $value = $this->connection->fetchOne(
'SELECT val FROM binary_table WHERE id = ?', 'SELECT val FROM binary_table WHERE id = ?',
[$id], [$id],
[ParameterType::BINARY] [ParameterType::BINARY]
......
...@@ -129,10 +129,10 @@ class WriteTest extends FunctionalTestCase ...@@ -129,10 +129,10 @@ class WriteTest extends FunctionalTestCase
$this->insertRows(); $this->insertRows();
self::assertEquals(1, $this->connection->delete('write_table', ['test_int' => 2])); self::assertEquals(1, $this->connection->delete('write_table', ['test_int' => 2]));
self::assertCount(1, $this->connection->fetchAll('SELECT * FROM write_table')); self::assertCount(1, $this->connection->fetchAllAssociative('SELECT * FROM write_table'));
self::assertEquals(1, $this->connection->delete('write_table', ['test_int' => 1])); self::assertEquals(1, $this->connection->delete('write_table', ['test_int' => 1]));
self::assertCount(0, $this->connection->fetchAll('SELECT * FROM write_table')); self::assertCount(0, $this->connection->fetchAllAssociative('SELECT * FROM write_table'));
} }
public function testUpdate() : void public function testUpdate() : void
...@@ -175,7 +175,7 @@ class WriteTest extends FunctionalTestCase ...@@ -175,7 +175,7 @@ class WriteTest extends FunctionalTestCase
})); }));
$stmt = $this->connection->query($this->connection->getDatabasePlatform()->getSequenceNextValSQL('write_table_id_seq')); $stmt = $this->connection->query($this->connection->getDatabasePlatform()->getSequenceNextValSQL('write_table_id_seq'));
$nextSequenceVal = $stmt->fetchColumn(); $nextSequenceVal = $stmt->fetchOne();
$lastInsertId = $this->lastInsertId('write_table_id_seq'); $lastInsertId = $this->lastInsertId('write_table_id_seq');
...@@ -205,7 +205,7 @@ class WriteTest extends FunctionalTestCase ...@@ -205,7 +205,7 @@ class WriteTest extends FunctionalTestCase
['test_string' => 'datetime', 'test_int' => 'integer'] ['test_string' => 'datetime', 'test_int' => 'integer']
); );
$data = $this->connection->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); $data = $this->connection->fetchOne('SELECT test_string FROM write_table WHERE test_int = 30');
self::assertEquals($testString->format($this->connection->getDatabasePlatform()->getDateTimeFormatString()), $data); self::assertEquals($testString->format($this->connection->getDatabasePlatform()->getDateTimeFormatString()), $data);
} }
...@@ -232,7 +232,7 @@ class WriteTest extends FunctionalTestCase ...@@ -232,7 +232,7 @@ class WriteTest extends FunctionalTestCase
['test_string' => 'datetime', 'test_int' => 'integer'] ['test_string' => 'datetime', 'test_int' => 'integer']
); );
$data = $this->connection->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); $data = $this->connection->fetchOne('SELECT test_string FROM write_table WHERE test_int = 30');
self::assertEquals($testString->format($this->connection->getDatabasePlatform()->getDateTimeFormatString()), $data); self::assertEquals($testString->format($this->connection->getDatabasePlatform()->getDateTimeFormatString()), $data);
} }
...@@ -251,7 +251,7 @@ class WriteTest extends FunctionalTestCase ...@@ -251,7 +251,7 @@ class WriteTest extends FunctionalTestCase
$this->connection->delete('write_table', ['test_int' => 30, 'test_string' => $val], ['test_string' => 'datetime', 'test_int' => 'integer']); $this->connection->delete('write_table', ['test_int' => 30, 'test_string' => $val], ['test_string' => 'datetime', 'test_int' => 'integer']);
$data = $this->connection->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); $data = $this->connection->fetchOne('SELECT test_string FROM write_table WHERE test_int = 30');
self::assertFalse($data); self::assertFalse($data);
} }
...@@ -307,13 +307,13 @@ class WriteTest extends FunctionalTestCase ...@@ -307,13 +307,13 @@ class WriteTest extends FunctionalTestCase
['test_string' => 'string', 'test_int' => 'integer'] ['test_string' => 'string', 'test_int' => 'integer']
); );
$data = $this->connection->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); $data = $this->connection->fetchAllAssociative('SELECT * FROM write_table WHERE test_int = 30');
self::assertCount(1, $data); self::assertCount(1, $data);
$this->connection->update('write_table', ['test_int' => 10], ['test_string' => null], ['test_string' => 'string', 'test_int' => 'integer']); $this->connection->update('write_table', ['test_int' => 10], ['test_string' => null], ['test_string' => 'string', 'test_int' => 'integer']);
$data = $this->connection->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); $data = $this->connection->fetchAllAssociative('SELECT * FROM write_table WHERE test_int = 30');
self::assertCount(0, $data); self::assertCount(0, $data);
} }
...@@ -326,13 +326,13 @@ class WriteTest extends FunctionalTestCase ...@@ -326,13 +326,13 @@ class WriteTest extends FunctionalTestCase
['test_string' => 'string', 'test_int' => 'integer'] ['test_string' => 'string', 'test_int' => 'integer']
); );
$data = $this->connection->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); $data = $this->connection->fetchAllAssociative('SELECT * FROM write_table WHERE test_int = 30');
self::assertCount(1, $data); self::assertCount(1, $data);
$this->connection->delete('write_table', ['test_string' => null], ['test_string' => 'string']); $this->connection->delete('write_table', ['test_string' => null], ['test_string' => 'string']);
$data = $this->connection->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); $data = $this->connection->fetchAllAssociative('SELECT * FROM write_table WHERE test_int = 30');
self::assertCount(0, $data); self::assertCount(0, $data);
} }
......
...@@ -8,7 +8,6 @@ use Doctrine\DBAL\Portability\Connection; ...@@ -8,7 +8,6 @@ use Doctrine\DBAL\Portability\Connection;
use Doctrine\DBAL\Portability\Statement; use Doctrine\DBAL\Portability\Statement;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use function iterator_to_array;
class StatementTest extends TestCase class StatementTest extends TestCase
{ {
...@@ -95,15 +94,6 @@ class StatementTest extends TestCase ...@@ -95,15 +94,6 @@ class StatementTest extends TestCase
self::assertTrue($this->stmt->execute($params)); self::assertTrue($this->stmt->execute($params));
} }
public function testGetIterator() : void
{
$this->wrappedStmt->expects(self::exactly(3))
->method('fetch')
->willReturnOnConsecutiveCalls('foo', 'bar', false);
self::assertSame(['foo', 'bar'], iterator_to_array($this->stmt->getIterator()));
}
public function testRowCount() : void public function testRowCount() : void
{ {
$rowCount = 666; $rowCount = 666;
......
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