From b9756f6733f17a894248c7b6d9735152ca6ae544 Mon Sep 17 00:00:00 2001 From: Andreas Fernandez <andreas.fernandez@aspedia.de> Date: Wed, 26 Nov 2014 16:07:19 +0100 Subject: [PATCH] [BUGFIX] Follow up: Use strrpos to find last occurence The patch #61654 introduced a bug, where strpos is mistakenly used to get the last position of the currently processed field. It must be changed to strrpos, otherwise the opening brace breaks the SQL. Also, a unit test for this case is added. Resolves: #63345 Related: #61654 Releases: master, 6.2 Change-Id: Ibdbc7975b8f750060980f811cd0089b1a7b7de2b Reviewed-on: http://review.typo3.org/34639 Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Markus Klein <klein.t3@reelworx.at> Tested-by: Markus Klein <klein.t3@reelworx.at> Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org> Reviewed-by: Oliver Hader <oliver.hader@typo3.org> Tested-by: Oliver Hader <oliver.hader@typo3.org> --- .../dbal/Classes/Database/SqlParser.php | 2 +- .../Database/DatabaseConnectionOracleTest.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/typo3/sysext/dbal/Classes/Database/SqlParser.php b/typo3/sysext/dbal/Classes/Database/SqlParser.php index 3100541c86bc..020a629b7ab7 100644 --- a/typo3/sysext/dbal/Classes/Database/SqlParser.php +++ b/typo3/sysext/dbal/Classes/Database/SqlParser.php @@ -694,7 +694,7 @@ class SqlParser extends \TYPO3\CMS\Core\Database\SqlParser { $implodeString = ' ' . $operator . ' ' . $field . ' ' . $v['comparator']; // add opening brace before field - $lastFieldPos = strpos($output, $field); + $lastFieldPos = strrpos($output, $field); $output = substr_replace($output, '(', $lastFieldPos, 0); $output .= implode($implodeString, $listExpressions) . ')'; } diff --git a/typo3/sysext/dbal/Tests/Unit/Database/DatabaseConnectionOracleTest.php b/typo3/sysext/dbal/Tests/Unit/Database/DatabaseConnectionOracleTest.php index 3b7a241a61be..7e57bc6f3cb5 100644 --- a/typo3/sysext/dbal/Tests/Unit/Database/DatabaseConnectionOracleTest.php +++ b/typo3/sysext/dbal/Tests/Unit/Database/DatabaseConnectionOracleTest.php @@ -972,4 +972,28 @@ class DatabaseConnectionOracleTest extends AbstractTestCase { $expectedQuery = 'SELECT * FROM "tt_content" WHERE "uid" IN (0,1,2,3,4,5,6,7,8,9,10)'; $this->assertEquals($expectedQuery, $this->cleanSql($result)); } + + /** + * @test + */ + public function expressionListBracesAreSetCorrectly() { + $listMaxExpressions = 1000; + + $mockSpecificsOci8 = $this->getAccessibleMock('TYPO3\\CMS\\Dbal\\Database\\Specifics\\Oci8', array(), array(), '', FALSE); + $mockSpecificsOci8->expects($this->any())->method('getSpecific')->will($this->returnValue($listMaxExpressions)); + + $items = range(0, 1250); + $where = 'uid = 1981 AND uid IN(' . implode(',', $items) . ')'; + $result = $this->subject->SELECTquery('uid, pid', 'tt_content', $where); + + $chunks = array_chunk($items, $listMaxExpressions); + $whereExpr = array(); + foreach ($chunks as $chunk) { + $whereExpr[] = '"uid" IN (' . implode(',', $chunk) . ')'; + } + + $expectedWhere = '"uid" = 1981 AND (' . implode(' OR ', $whereExpr) . ')'; + $expectedQuery = 'SELECT "uid", "pid" FROM "tt_content" WHERE ' . $expectedWhere; + $this->assertEquals($expectedQuery, $this->cleanSql($result)); + } } \ No newline at end of file -- GitLab