diff --git a/src/Cache/ArrayStatement.php b/src/Cache/ArrayStatement.php index 73aed53c9da..8227c9fc2cf 100644 --- a/src/Cache/ArrayStatement.php +++ b/src/Cache/ArrayStatement.php @@ -26,9 +26,6 @@ final class ArrayStatement implements IteratorAggregate, ResultStatement /** @var int */ private $num = 0; - /** @var int */ - private $defaultFetchMode = FetchMode::MIXED; - /** * @param mixed[] $data */ @@ -57,11 +54,6 @@ public function rowCount() : int return count($this->data); } - public function setFetchMode(int $fetchMode) : void - { - $this->defaultFetchMode = $fetchMode; - } - /** * {@inheritdoc} */ @@ -75,14 +67,13 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch(?int $fetchMode = null) + public function fetch(int $fetchMode = FetchMode::ASSOCIATIVE) { if (! isset($this->data[$this->num])) { return false; } - $row = $this->data[$this->num++]; - $fetchMode = $fetchMode ?? $this->defaultFetchMode; + $row = $this->data[$this->num++]; if ($fetchMode === FetchMode::ASSOCIATIVE) { return $row; @@ -108,7 +99,7 @@ public function fetch(?int $fetchMode = null) /** * {@inheritdoc} */ - public function fetchAll(?int $fetchMode = null) : array + public function fetchAll(int $fetchMode = FetchMode::ASSOCIATIVE) : array { $rows = []; while ($row = $this->fetch($fetchMode)) { diff --git a/src/Cache/ResultCacheStatement.php b/src/Cache/ResultCacheStatement.php index eea7233620e..bb36ab3f631 100644 --- a/src/Cache/ResultCacheStatement.php +++ b/src/Cache/ResultCacheStatement.php @@ -54,9 +54,6 @@ final class ResultCacheStatement implements IteratorAggregate, ResultStatement /** @var mixed[] */ private $data; - /** @var int */ - private $defaultFetchMode = FetchMode::MIXED; - public function __construct(ResultStatement $stmt, Cache $resultCache, string $cacheKey, string $realKey, int $lifetime) { $this->statement = $stmt; @@ -90,11 +87,6 @@ public function columnCount() : int return $this->statement->columnCount(); } - public function setFetchMode(int $fetchMode) : void - { - $this->defaultFetchMode = $fetchMode; - } - /** * {@inheritdoc} */ @@ -108,7 +100,7 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch(?int $fetchMode = null) + public function fetch(int $fetchMode = FetchMode::ASSOCIATIVE) { if ($this->data === null) { $this->data = []; @@ -119,8 +111,6 @@ public function fetch(?int $fetchMode = null) if ($row !== false) { $this->data[] = $row; - $fetchMode = $fetchMode ?? $this->defaultFetchMode; - if ($fetchMode === FetchMode::ASSOCIATIVE) { return $row; } @@ -148,7 +138,7 @@ public function fetch(?int $fetchMode = null) /** * {@inheritdoc} */ - public function fetchAll(?int $fetchMode = null) : array + public function fetchAll(int $fetchMode = FetchMode::ASSOCIATIVE) : array { $data = $this->statement->fetchAll($fetchMode); diff --git a/src/Connection.php b/src/Connection.php index be5ec58c01d..0aed956b5d1 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -148,9 +148,6 @@ class Connection implements DriverConnection */ private $isRollbackOnly = false; - /** @var int */ - protected $defaultFetchMode = FetchMode::ASSOCIATIVE; - /** * Initializes a new instance of the Connection class. * @@ -446,14 +443,6 @@ public function setAutoCommit(bool $autoCommit) : void $this->commitAll(); } - /** - * Sets the fetch mode. - */ - public function setFetchMode(int $fetchMode) : void - { - $this->defaultFetchMode = $fetchMode; - } - /** * Prepares and executes an SQL query and returns the first row of the result * as an associative array. @@ -760,14 +749,10 @@ public function fetchAll(string $query, array $params = [], array $types = []) : public function prepare(string $sql) : DriverStatement { try { - $stmt = new Statement($sql, $this); + return new Statement($sql, $this); } catch (Throwable $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $sql); } - - $stmt->setFetchMode($this->defaultFetchMode); - - return $stmt; } /** @@ -818,8 +803,6 @@ public function executeQuery( throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); } - $stmt->setFetchMode($this->defaultFetchMode); - $logger->stopQuery(); return $stmt; @@ -864,8 +847,6 @@ public function executeCacheQuery(string $query, array $params, array $types, Qu $stmt = new ResultCacheStatement($this->executeQuery($query, $params, $types), $resultCache, $cacheKey, $realKey, $qcp->getLifetime()); } - $stmt->setFetchMode($this->defaultFetchMode); - return $stmt; } @@ -882,8 +863,6 @@ public function query(string $sql) : ResultStatement throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $sql); } - $statement->setFetchMode($this->defaultFetchMode); - $logger->stopQuery(); return $statement; diff --git a/src/Connections/MasterSlaveConnection.php b/src/Connections/MasterSlaveConnection.php index 0e808c2f589..d2b9f27d893 100644 --- a/src/Connections/MasterSlaveConnection.php +++ b/src/Connections/MasterSlaveConnection.php @@ -324,8 +324,6 @@ public function query(string $sql) : ResultStatement $statement = $this->_conn->query($sql); - $statement->setFetchMode($this->defaultFetchMode); - $logger->stopQuery(); return $statement; diff --git a/src/Driver/IBMDB2/DB2Statement.php b/src/Driver/IBMDB2/DB2Statement.php index c4949a3a871..3e789f54f8e 100644 --- a/src/Driver/IBMDB2/DB2Statement.php +++ b/src/Driver/IBMDB2/DB2Statement.php @@ -49,9 +49,6 @@ final class DB2Statement implements IteratorAggregate, Statement */ private $lobs = []; - /** @var int */ - private $defaultFetchMode = FetchMode::MIXED; - /** * Indicates whether the statement is in the state when fetching results is possible * @@ -171,11 +168,6 @@ public function execute(?array $params = null) : void $this->result = true; } - public function setFetchMode(int $fetchMode) : void - { - $this->defaultFetchMode = $fetchMode; - } - /** * {@inheritdoc} */ @@ -187,7 +179,7 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch(?int $fetchMode = null) + public function fetch(int $fetchMode = FetchMode::ASSOCIATIVE) { // do not try fetching from the statement if it's not expected to contain result // in order to prevent exceptional situation @@ -195,7 +187,6 @@ public function fetch(?int $fetchMode = null) return false; } - $fetchMode = $fetchMode ?? $this->defaultFetchMode; switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); @@ -217,7 +208,7 @@ public function fetch(?int $fetchMode = null) /** * {@inheritdoc} */ - public function fetchAll(?int $fetchMode = null) : array + public function fetchAll(int $fetchMode = FetchMode::ASSOCIATIVE) : array { $rows = []; diff --git a/src/Driver/Mysqli/MysqliStatement.php b/src/Driver/Mysqli/MysqliStatement.php index 8f09aeda8c4..0196c1ef028 100644 --- a/src/Driver/Mysqli/MysqliStatement.php +++ b/src/Driver/Mysqli/MysqliStatement.php @@ -89,9 +89,6 @@ final class MysqliStatement implements IteratorAggregate, Statement */ private $values = []; - /** @var int */ - private $defaultFetchMode = FetchMode::MIXED; - /** * Indicates whether the statement is in the state when fetching results is possible * @@ -326,7 +323,7 @@ private function _fetch() /** * {@inheritdoc} */ - public function fetch(?int $fetchMode = null) + public function fetch(int $fetchMode = FetchMode::ASSOCIATIVE) { // do not try fetching from the statement if it's not expected to contain result // in order to prevent exceptional situation @@ -334,8 +331,6 @@ public function fetch(?int $fetchMode = null) return false; } - $fetchMode = $fetchMode ?? $this->defaultFetchMode; - if ($fetchMode === FetchMode::COLUMN) { return $this->fetchColumn(); } @@ -372,10 +367,8 @@ public function fetch(?int $fetchMode = null) /** * {@inheritdoc} */ - public function fetchAll(?int $fetchMode = null) : array + public function fetchAll(int $fetchMode = FetchMode::ASSOCIATIVE) : array { - $fetchMode = $fetchMode ?? $this->defaultFetchMode; - $rows = []; if ($fetchMode === FetchMode::COLUMN) { @@ -425,11 +418,6 @@ public function columnCount() : int return $this->stmt->field_count; } - public function setFetchMode(int $fetchMode) : void - { - $this->defaultFetchMode = $fetchMode; - } - /** * {@inheritdoc} */ diff --git a/src/Driver/OCI8/OCI8Statement.php b/src/Driver/OCI8/OCI8Statement.php index a3a75e7ece1..36991502ab2 100644 --- a/src/Driver/OCI8/OCI8Statement.php +++ b/src/Driver/OCI8/OCI8Statement.php @@ -32,6 +32,7 @@ use const OCI_D_LOB; use const OCI_FETCHSTATEMENT_BY_COLUMN; use const OCI_FETCHSTATEMENT_BY_ROW; +use const OCI_NO_AUTO_COMMIT; use const OCI_NUM; use const OCI_RETURN_LOBS; use const OCI_RETURN_NULLS; @@ -60,9 +61,6 @@ final class OCI8Statement implements IteratorAggregate, Statement FetchMode::COLUMN => OCI_NUM, ]; - /** @var int */ - protected $_defaultFetchMode = FetchMode::MIXED; - /** @var string[] */ protected $_paramMap = []; @@ -219,11 +217,6 @@ public function execute(?array $params = null) : void $this->result = true; } - public function setFetchMode(int $fetchMode) : void - { - $this->_defaultFetchMode = $fetchMode; - } - /** * {@inheritdoc} */ @@ -235,7 +228,7 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch(?int $fetchMode = null) + public function fetch(int $fetchMode = FetchMode::ASSOCIATIVE) { // do not try fetching from the statement if it's not expected to contain result // in order to prevent exceptional situation @@ -243,8 +236,6 @@ public function fetch(?int $fetchMode = null) return false; } - $fetchMode = $fetchMode ?? $this->_defaultFetchMode; - if ($fetchMode === FetchMode::COLUMN) { return $this->fetchColumn(); } @@ -262,10 +253,8 @@ public function fetch(?int $fetchMode = null) /** * {@inheritdoc} */ - public function fetchAll(?int $fetchMode = null) : array + public function fetchAll(int $fetchMode = FetchMode::ASSOCIATIVE) : array { - $fetchMode = $fetchMode ?? $this->_defaultFetchMode; - $result = []; if (! isset(self::$fetchModeMap[$fetchMode])) { diff --git a/src/Driver/PDOConnection.php b/src/Driver/PDOConnection.php index fcfc7caf5ee..023741330b5 100644 --- a/src/Driver/PDOConnection.php +++ b/src/Driver/PDOConnection.php @@ -92,6 +92,8 @@ public function lastInsertId(?string $name = null) : string */ protected function createStatement(\PDOStatement $stmt) : PDOStatement { + $stmt->setFetchMode(PDO::FETCH_ASSOC); + return new PDOStatement($stmt); } diff --git a/src/Driver/PDOStatement.php b/src/Driver/PDOStatement.php index be2552fa469..b9667f41dd6 100644 --- a/src/Driver/PDOStatement.php +++ b/src/Driver/PDOStatement.php @@ -46,17 +46,6 @@ public function __construct(\PDOStatement $stmt) $this->stmt = $stmt; } - public function setFetchMode(int $fetchMode) : void - { - $fetchMode = $this->convertFetchMode($fetchMode); - - try { - $this->stmt->setFetchMode($fetchMode); - } catch (\PDOException $exception) { - throw new PDOException($exception); - } - } - /** * {@inheritdoc} */ @@ -122,13 +111,9 @@ public function rowCount() : int /** * {@inheritdoc} */ - public function fetch(?int $fetchMode = null) + public function fetch(int $fetchMode = FetchMode::ASSOCIATIVE) { try { - if ($fetchMode === null) { - return $this->stmt->fetch(); - } - return $this->stmt->fetch( $this->convertFetchMode($fetchMode) ); @@ -140,16 +125,12 @@ public function fetch(?int $fetchMode = null) /** * {@inheritdoc} */ - public function fetchAll(?int $fetchMode = null) : array + public function fetchAll(int $fetchMode = FetchMode::ASSOCIATIVE) : array { try { - if ($fetchMode === null) { - $data = $this->stmt->fetchAll(); - } else { - $data = $this->stmt->fetchAll( - $this->convertFetchMode($fetchMode) - ); - } + $data = $this->stmt->fetchAll( + $this->convertFetchMode($fetchMode) + ); } catch (\PDOException $exception) { throw new PDOException($exception); } diff --git a/src/Driver/ResultStatement.php b/src/Driver/ResultStatement.php index 1bc40dfaf39..eb4ac70871f 100644 --- a/src/Driver/ResultStatement.php +++ b/src/Driver/ResultStatement.php @@ -4,6 +4,7 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\FetchMode; use Traversable; /** @@ -37,35 +38,25 @@ public function columnCount() : int; public function rowCount() : int; /** - * Sets the fetch mode to use while iterating this statement. + * Returns the next row of a result set. * * @param int $fetchMode Controls how the next row will be returned to the caller. * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants. - */ - public function setFetchMode(int $fetchMode) : void; - - /** - * Returns the next row of a result set. - * - * @param int|null $fetchMode Controls how the next row will be returned to the caller. - * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants, - * defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}. * * @return mixed The return value of this method on success depends on the fetch mode. In all cases, FALSE is * returned on failure. */ - public function fetch(?int $fetchMode = null); + public function fetch(int $fetchMode = FetchMode::ASSOCIATIVE); /** * Returns an array containing all of the result set rows. * - * @param int|null $fetchMode Controls how the next row will be returned to the caller. - * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants, - * defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}. + * @param int $fetchMode Controls how the next row will be returned to the caller. + * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants. * * @return mixed[] */ - public function fetchAll(?int $fetchMode = null) : array; + public function fetchAll(int $fetchMode = FetchMode::ASSOCIATIVE) : array; /** * Returns a single column from the next row of a result set or FALSE if there are no more rows. diff --git a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php index fd0d39b7986..11553be7b42 100644 --- a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -35,9 +35,6 @@ final class SQLAnywhereStatement implements IteratorAggregate, Statement /** @var resource The connection resource. */ private $conn; - /** @var int Default fetch mode to use. */ - private $defaultFetchMode = FetchMode::MIXED; - /** @var resource|null The result set resource to fetch. */ private $result; @@ -157,14 +154,12 @@ public function execute(?array $params = null) : void * * @throws SQLAnywhereException */ - public function fetch(?int $fetchMode = null) + public function fetch(int $fetchMode = FetchMode::ASSOCIATIVE) { if (! is_resource($this->result)) { return false; } - $fetchMode = $fetchMode ?? $this->defaultFetchMode; - switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); @@ -186,7 +181,7 @@ public function fetch(?int $fetchMode = null) /** * {@inheritdoc} */ - public function fetchAll(?int $fetchMode = null) : array + public function fetchAll(int $fetchMode = FetchMode::ASSOCIATIVE) : array { $rows = []; @@ -233,9 +228,4 @@ public function rowCount() : int { return sasql_stmt_affected_rows($this->stmt); } - - public function setFetchMode(int $fetchMode) : void - { - $this->defaultFetchMode = $fetchMode; - } } diff --git a/src/Driver/SQLSrv/SQLSrvStatement.php b/src/Driver/SQLSrv/SQLSrvStatement.php index 04014edc960..3f5545ce668 100644 --- a/src/Driver/SQLSrv/SQLSrvStatement.php +++ b/src/Driver/SQLSrv/SQLSrvStatement.php @@ -80,13 +80,6 @@ final class SQLSrvStatement implements IteratorAggregate, Statement FetchMode::NUMERIC => SQLSRV_FETCH_NUMERIC, ]; - /** - * The fetch style. - * - * @var int - */ - private $defaultFetchMode = FetchMode::MIXED; - /** * The last insert ID. * @@ -211,11 +204,6 @@ public function execute(?array $params = null) : void $this->result = true; } - public function setFetchMode(int $fetchMode) : void - { - $this->defaultFetchMode = $fetchMode; - } - /** * {@inheritdoc} */ @@ -229,7 +217,7 @@ public function getIterator() * * @throws SQLSrvException */ - public function fetch(?int $fetchMode = null) + public function fetch(int $fetchMode = FetchMode::ASSOCIATIVE) { // do not try fetching from the statement if it's not expected to contain result // in order to prevent exceptional situation @@ -237,8 +225,6 @@ public function fetch(?int $fetchMode = null) return false; } - $fetchMode = $fetchMode ?? $this->defaultFetchMode; - if ($fetchMode === FetchMode::COLUMN) { return $this->fetchColumn(); } @@ -253,7 +239,7 @@ public function fetch(?int $fetchMode = null) /** * {@inheritdoc} */ - public function fetchAll(?int $fetchMode = null) : array + public function fetchAll(int $fetchMode = FetchMode::ASSOCIATIVE) : array { $rows = []; diff --git a/src/Portability/Connection.php b/src/Portability/Connection.php index 794725edbdd..9e287bb0d36 100644 --- a/src/Portability/Connection.php +++ b/src/Portability/Connection.php @@ -99,28 +99,20 @@ public function executeQuery( array $types = [], ?QueryCacheProfile $qcp = null ) : ResultStatement { - $stmt = new Statement(parent::executeQuery($query, $params, $types, $qcp), $this); - $stmt->setFetchMode($this->defaultFetchMode); - - return $stmt; + return new Statement(parent::executeQuery($query, $params, $types, $qcp), $this); } public function prepare(string $sql) : DriverStatement { - $stmt = new Statement(parent::prepare($sql), $this); - $stmt->setFetchMode($this->defaultFetchMode); - - return $stmt; + return new Statement(parent::prepare($sql), $this); } public function query(string $sql) : ResultStatement { - $connection = $this->getWrappedConnection(); - - $stmt = $connection->query($sql); - $stmt = new Statement($stmt, $this); - $stmt->setFetchMode($this->defaultFetchMode); - - return $stmt; + return new Statement( + $this->getWrappedConnection() + ->query($sql), + $this + ); } } diff --git a/src/Portability/Statement.php b/src/Portability/Statement.php index 80f160af3b2..2889eb2ce59 100644 --- a/src/Portability/Statement.php +++ b/src/Portability/Statement.php @@ -29,9 +29,6 @@ final class Statement implements IteratorAggregate, DriverStatement /** @var int|null */ private $case; - /** @var int */ - private $defaultFetchMode = FetchMode::MIXED; - /** * Wraps Statement and applies portability measures. * @@ -84,13 +81,6 @@ public function execute(?array $params = null) : void $this->stmt->execute($params); } - public function setFetchMode(int $fetchMode) : void - { - $this->defaultFetchMode = $fetchMode; - - $this->stmt->setFetchMode($fetchMode); - } - /** * {@inheritdoc} */ @@ -102,10 +92,8 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch(?int $fetchMode = null) + public function fetch(int $fetchMode = FetchMode::ASSOCIATIVE) { - $fetchMode = $fetchMode ?? $this->defaultFetchMode; - $row = $this->stmt->fetch($fetchMode); $iterateRow = ($this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM)) !== 0; @@ -121,10 +109,8 @@ public function fetch(?int $fetchMode = null) /** * {@inheritdoc} */ - public function fetchAll(?int $fetchMode = null) : array + public function fetchAll(int $fetchMode = FetchMode::ASSOCIATIVE) : array { - $fetchMode = $fetchMode ?? $this->defaultFetchMode; - $rows = $this->stmt->fetchAll($fetchMode); $iterateRow = ($this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM)) !== 0; diff --git a/src/Statement.php b/src/Statement.php index 874c80cb306..e794605ef36 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -180,11 +180,6 @@ public function columnCount() : int return $this->stmt->columnCount(); } - public function setFetchMode(int $fetchMode) : void - { - $this->stmt->setFetchMode($fetchMode); - } - /** * Required by interface IteratorAggregate. * @@ -198,7 +193,7 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch(?int $fetchMode = null) + public function fetch(int $fetchMode = FetchMode::ASSOCIATIVE) { return $this->stmt->fetch($fetchMode); } @@ -206,7 +201,7 @@ public function fetch(?int $fetchMode = null) /** * {@inheritdoc} */ - public function fetchAll(?int $fetchMode = null) : array + public function fetchAll(int $fetchMode = FetchMode::ASSOCIATIVE) : array { return $this->stmt->fetchAll($fetchMode); } diff --git a/tests/Cache/ArrayStatementTest.php b/tests/Cache/ArrayStatementTest.php index 1e23bc28e53..70d7d73be71 100644 --- a/tests/Cache/ArrayStatementTest.php +++ b/tests/Cache/ArrayStatementTest.php @@ -50,19 +50,9 @@ public function testRowCount() : void self::assertSame(2, $statement->rowCount()); } - public function testSetFetchMode() : void - { - $statement = $this->createTestArrayStatement(); - - $statement->setFetchMode(FetchMode::ASSOCIATIVE); - - self::assertSame($this->users[0], $statement->fetch()); - } - public function testGetIterator() : void { $statement = $this->createTestArrayStatement(); - $statement->setFetchMode(FetchMode::ASSOCIATIVE); self::assertSame($this->users, iterator_to_array($statement->getIterator())); } diff --git a/tests/Functional/DataAccessTest.php b/tests/Functional/DataAccessTest.php index e321ae8e4ee..ffcf662873a 100644 --- a/tests/Functional/DataAccessTest.php +++ b/tests/Functional/DataAccessTest.php @@ -20,13 +20,10 @@ use Doctrine\DBAL\Types\Types; use InvalidArgumentException; use function array_change_key_case; -use function array_filter; -use function array_keys; use function assert; use function count; use function date; use function is_array; -use function is_numeric; use function json_encode; use function sprintf; use function strtotime; @@ -161,7 +158,7 @@ public function testPrepareWithIterator() : void $stmt->execute(); $rows = []; - $stmt->setFetchMode(FetchMode::ASSOCIATIVE); + foreach ($stmt as $row) { $rows[] = array_change_key_case($row, CASE_LOWER); } @@ -1041,17 +1038,6 @@ public function testBitComparisonExpressionSupport() : void } } - public function testSetDefaultFetchMode() : void - { - $stmt = $this->connection->query('SELECT * FROM fetch_table'); - $stmt->setFetchMode(FetchMode::NUMERIC); - - $row = array_keys($stmt->fetch()); - self::assertCount(0, array_filter($row, static function ($v) : bool { - return ! is_numeric($v); - }), 'should be no non-numerical elements in the result.'); - } - /** * @group DBAL-241 */ @@ -1081,22 +1067,6 @@ public function testEmptyFetchColumnReturnsFalse() : void $this->connection->rollBack(); } - /** - * @group DBAL-339 - */ - public function testSetFetchModeOnDbalStatement() : void - { - $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $stmt = $this->connection->executeQuery($sql, [1, 'foo']); - $stmt->setFetchMode(FetchMode::NUMERIC); - - $row = $stmt->fetch(); - - self::assertArrayHasKey(0, $row); - self::assertArrayHasKey(1, $row); - self::assertFalse($stmt->fetch()); - } - /** * @group DBAL-435 */ diff --git a/tests/Functional/PortabilityTest.php b/tests/Functional/PortabilityTest.php index 9828bd4e549..89aca6edbf7 100644 --- a/tests/Functional/PortabilityTest.php +++ b/tests/Functional/PortabilityTest.php @@ -82,7 +82,6 @@ public function testFullFetchMode() : void $this->assertFetchResultRows($rows); $stmt = $this->portableConnection->query('SELECT * FROM portability_table'); - $stmt->setFetchMode(FetchMode::ASSOCIATIVE); foreach ($stmt as $row) { $this->assertFetchResultRow($row); @@ -104,8 +103,6 @@ public function testFullFetchMode() : void public function testConnFetchMode() : void { - $this->portableConnection->setFetchMode(FetchMode::ASSOCIATIVE); - $rows = $this->portableConnection->fetchAll('SELECT * FROM portability_table'); $this->assertFetchResultRows($rows); diff --git a/tests/Functional/ResultCacheTest.php b/tests/Functional/ResultCacheTest.php index aafca09f694..e27bab43d0a 100644 --- a/tests/Functional/ResultCacheTest.php +++ b/tests/Functional/ResultCacheTest.php @@ -256,8 +256,8 @@ private function hydrateStmt(ResultStatement $stmt, int $fetchMode = FetchMode:: private function hydrateStmtIterator(ResultStatement $stmt, int $fetchMode = FetchMode::ASSOCIATIVE) : array { $data = []; - $stmt->setFetchMode($fetchMode); - foreach ($stmt as $row) { + + while (($row = $stmt->fetch($fetchMode)) !== false) { $data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row; }