View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0006908 | OXID eShop (all versions) | 4.01. Database handling | public | 2018-10-11 09:19 | 2018-10-12 09:53 |
| Reporter | s.diez | Assigned To | |||
| Priority | normal | Severity | major | Reproducibility | always |
| Status | closed | Resolution | no change required | ||
| Product Version | 6.1.0 | ||||
| Summary | 0006908: OxidEsales\EshopCommunity\Core\Database\Adapter\Doctrine\ResultSetInterface does not allow access to the first row | ||||
| Description | OxidEsales\EshopCommunity\Core\Database\Adapter\Doctrine\ResultSet implements OxidEsales\EshopCommunity\Core\Database\Adapter\Doctrine\ResultSetInterface but it already loads the first line when you create it. If you now try to get the result only via the API of the interface, it is impossible to get the first line, because the first call of fetchRow directly returns the second line. | ||||
| Steps To Reproduce | OxidEsales\EshopCommunity\Core\Database\Adapter\Doctrine\Database::select() and then use fetchRow to query the result rows. | ||||
| Additional Information | Aus der Dokumentation von OxidEsales\EshopCommunity\Core\Database\Adapter\Doctrine\ResultSet "The doctrine statement wrapper, to support the old adodblite interface.". Das sagt die Doku von ADOdb zu fetchRow (http://adodb.org/dokuwiki/doku.php?id=v5:reference:recordset:fetchrow): The function fetchRow() returns the current row of a recordset as an array or false if past end-of-file and advances the pointer of the result. If the end-of-file is reached, the EOF attribute is set. Es wird aber nicht die aktuelle Reihe zurückgegeben und dann der Zeiger incrementiert sondern andersrum. | ||||
| Tags | No tags attached. | ||||
| Theme | Not defined | ||||
| Browser | Not defined | ||||
| PHP Version | Not defined | ||||
| Database Version | Not defined | ||||
|
|
IMPORTANT NOTE: Do not try something like this, you will lose the first result row: $resultSet = \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->select($query); while ($row = $resultSet->fetchRow()) { //do something }; What will happen: the ResultSet immediately executes the first call to ResultSet::fetchRow() in its constructor and each following call to ResultSet::fetchRow() advances the content of ResultSet::fields to the next row. Always access ResultSet::fields before calling ResultSet::fetchRow() again. Thats the right way: $resultSet = \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->select($query); //Fetch the results row by row if ($resultSet != false && $resultSet->count() > 0) { while (!$resultSet->EOF) { $row = $resultSet->getFields(); //do something $resultSet->fetchRow(); |