[BUGFIX] Missing table definitions crash Dbal
authorNicole Cordes <nicole@cordes.co>
Sat, 24 Nov 2012 00:15:27 +0000 (01:15 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sun, 25 Nov 2012 16:21:56 +0000 (17:21 +0100)
The function
\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend::parseQuery
returns table names not as numeric array but as associative array. To pass
a valid tablename for Dbal compatibility it is necessary to adjust the
current value.

Change-Id: Ia932e86436bd9365913e2e2723273d8ecc6a9d93
Fixes: #43263
Releases: 6.0
Reviewed-on: http://review.typo3.org/16705
Reviewed-by: Stefan Neufeind
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php

index 6842233..1c8d9ff 100644 (file)
@@ -297,10 +297,12 @@ class Typo3DbBackend implements \TYPO3\CMS\Extbase\Persistence\Generic\Storage\B
                }
                $parameters = array();
                $statementParts = $this->parseQuery($query, $parameters);
+               // Reset $statementParts for valid table return
+               reset($statementParts);
                // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints
                if (!empty($statementParts['limit'])) {
                        $statement = $this->buildQuery($statementParts, $parameters);
-                       $this->replacePlaceholders($statement, $parameters, $statementParts['tables'][0]);
+                       $this->replacePlaceholders($statement, $parameters, current($statementParts['tables']));
                        $result = $this->databaseHandle->sql_query($statement);
                        $this->checkSqlErrors($statement);
                        $count = $this->databaseHandle->sql_num_rows($result);
@@ -311,7 +313,7 @@ class Typo3DbBackend implements \TYPO3\CMS\Extbase\Persistence\Generic\Storage\B
                                $statementParts['fields'] = array('COUNT(DISTINCT ' . reset($statementParts['tables']) . '.uid)');
                        }
                        $statement = $this->buildQuery($statementParts, $parameters);
-                       $this->replacePlaceholders($statement, $parameters, $statementParts['tables'][0]);
+                       $this->replacePlaceholders($statement, $parameters, current($statementParts['tables']));
                        $result = $this->databaseHandle->sql_query($statement);
                        $this->checkSqlErrors($statement);
                        $rows = $this->getRowsFromResult($query->getSource(), $result);