Commit 7cd962e4 authored by Ian Jenkins's avatar Ian Jenkins

Removed rewindable non pdo driver support and the wrapping of pdo

statements in a rewindable iterator. Skipped the test for iterating
multiple times with a message regarding that iterators are non
rewindable.
parent 3505a5ed
......@@ -19,7 +19,6 @@
namespace Doctrine\DBAL;
use Doctrine\DBAL\Driver\PDOStatementIterator;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use PDO;
......@@ -1034,7 +1033,7 @@ class Connection implements DriverConnection
$logger->stopQuery();
}
return new PDOStatementIterator($statement);
return $statement;
}
/**
......
......@@ -20,7 +20,6 @@
namespace Doctrine\DBAL\Driver\Mysqli;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\RewindableGenerator;
use PDO;
/**
......@@ -407,11 +406,8 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/
public function getIterator()
{
return new RewindableGenerator(function() {
$this->_stmt->data_seek(0);
while ($row = $this->fetch()) {
yield $row;
}
});
while ($row = $this->fetch()) {
yield $row;
}
}
}
<?php
namespace Doctrine\DBAL\Driver;
class PDOStatementIterator implements \Iterator
{
public $stmt;
public $cache;
public $position = 0;
public function __construct(\PDOStatement $stmt)
{
$this->cache = [];
$this->position = 0;
$this->stmt = $stmt;
$this->next();
}
public function rewind()
{
$this->position = 0;
}
public function valid()
{
return isset($this->cache[$this->position]);
}
public function current()
{
return $this->cache[$this->position];
}
public function key()
{
return $this->position;
}
public function next()
{
if ($this->valid()) {
$this->cache[$this->position];
$this->position++;
} else {
$this->cache[$this->position] = $this->stmt->fetch();
$this->position++;
}
}
public function __call($name, $arguments)
{
return call_user_func_array([$this->stmt, $name], $arguments);
}
}
<?php
namespace Doctrine\DBAL;
class RewindableGenerator implements \IteratorAggregate
{
private $generator;
/**
* @param callable $generator
*/
public function __construct(callable $generator)
{
$this->generator = $generator;
}
public function getIterator()
{
return ($this->generator)();
}
}
......@@ -869,6 +869,24 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testIteratorCanBeIteratedMultipleTimes()
{
$skippedMessage = <<<'MSG'
Iterators are not rewindable for either PDO or Non PDO drivers. This is because PDO by default is not rewindable and
to be consistent we have not implemented rewindable iterators for non PDO drivers. Should PDO ever become rewindable by
default we should wrap the legacy drivers in Doctrine\DBAL\RewindableGenerator for example on the Mysqli driver you
would do something like the following:
return new RewindableGenerator(function() {
$this->_stmt->data_seek(0);
while ($row = $this->fetch()) {
yield $row;
}
});
If this has been done you can include this test.
MSG;
$this->markTestSkipped($skippedMessage);
$sql = 'SELECT CURTIME(6) AS time_started, test_int, test_string FROM fetch_table';
$stmt = $this->_conn->query($sql);
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
......
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