View Issue Details

IDProjectCategoryView StatusLast Update
0006908OXID eShop (all versions)4.01. Database handlingpublic2018-10-12 09:53
Reporters.diez Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionno change required 
Product Version6.1.0 
Summary0006908: OxidEsales\EshopCommunity\Core\Database\Adapter\Doctrine\ResultSetInterface does not allow access to the first row
DescriptionOxidEsales\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 ReproduceOxidEsales\EshopCommunity\Core\Database\Adapter\Doctrine\Database::select() and then use fetchRow to query the result rows.
Additional InformationAus 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.
TagsNo tags attached.
ThemeNot defined
BrowserNot defined
PHP VersionNot defined
Database VersionNot defined

Activities

QA

2018-10-12 09:52

administrator   ~0012640

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();