-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Zend\Db\Resultset fix buffering #5308
Zend\Db\Resultset fix buffering #5308
Conversation
@@ -56,6 +58,16 @@ public function setObjectPrototype($objectPrototype) | |||
} | |||
|
|||
/** | |||
* Get the row object prototype | |||
* | |||
* @return stdObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stdClass maybe ?
My local tests is ok - where i wrong? |
it seems the error is on ZendTest\Http\ClientTest::testUsageOfCustomResponseInvalidCode which not related with your commits. |
Can you expand on the problems you're trying to solve in these commits? |
ResultSet and HydratingResultSet not use the buffer for converted values (see |
Sorry - only |
optimize some methods
fixes for added tests
Hey @Turris, I can't seem to duplicate your problem. Using my repo at Zend_Db-Example (https://github.com/ralphschindler/Zend_Db-Examples): I've created the following script and witness that the buffered values are in fact utilized: <?php
/** @var $adapter Zend\Db\Adapter\Adapter */
$adapter = include ((file_exists('bootstrap.php')) ? 'bootstrap.php' : 'bootstrap.dist.php');
refresh_data($adapter);
use Zend\Db\ResultSet\HydratingResultSet;
use Zend\Db\ResultSet\ResultSet;
$stmt = $adapter->query('SELECT * FROM album');
$result = $stmt->execute();
if (1) {
class Foo extends ArrayObject { public function __clone() { echo 'cloning' . PHP_EOL; } }
$hrs = new HydratingResultSet();
$hrs->setObjectPrototype(new Foo);
$hrs->initialize($result);
$hrs->buffer();
foreach ($hrs as $row) {
var_dump($row['title']);
}
foreach ($hrs as $row) {
var_dump($row['title']);
}
} else {
$rs = new ResultSet;
$rs->initialize($result);
$rs->buffer();
foreach ($rs as $row) {
var_dump($row['title']);
}
foreach ($rs as $row) {
var_dump($row['title']);
}
} If you still find that not to be the case, how can I setup a reproduction of your problem? |
@ralphschindler If merge last commit to develop, only |
So what you're saying is concurrent calls to |
@ralphschindler you're right, sorry - this is my inaccurate description. |
@ralphschindler Can you update and specify a target milestone, please? |
Hey @turrsis, while I admit there is an issue with iteration and buffering, there is also too much unnecessary refactoring going on in this PR to take as is. I will work backwards from your unit tests and produce an alternative PR. |
For the record, this would be the unit test to prove this is an issue: namespace ZendTest\Db\ResultSet;
class AbstractResultSetIntegrationTest extends \PHPUnit_Framework_TestCase
{
protected $resultSet;
protected function setUp() {
$this->resultSet = $this->getMockForAbstractClass('Zend\Db\ResultSet\AbstractResultSet');
}
public function testCurrentCallsDataSourceOnceWithoutBuffer()
{
$result = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
$this->resultSet->initialize($result);
$result->expects($this->once())->method('current')->will($this->returnValue(array('foo' => 'bar')));
$value1 = $this->resultSet->current();
$value2 = $this->resultSet->current();
$this->assertEquals($value1, $value2);
}
} That said, after thinking about this issue, I don't think this is a valid use case. I would expect that at the abstract level, without any buffering, that if I called current() twice, it should do just that with respect to the DataSource. |
} | ||
|
||
if (is_array($dataSource)) { | ||
} elseif (is_array($dataSource)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for this to be turned into elseif
?
@turrsis what happens if the data source is mutable? Shouldn't the value for |
Merge branch 'hotfix/db-resultset-current-with-buffer-alt' into develop * hotfix/db-resultset-current-with-buffer-alt: Added unit tests for Zend\Db\ResultSet current() handling
I've committed a few unit tests that describe the current behavior as the expected intended behavior. |
fix buffering
optimize some methods