[BUGFIX] Follow up: Use strrpos to find last occurence 39/34639/2
authorAndreas Fernandez <andreas.fernandez@aspedia.de>
Wed, 26 Nov 2014 15:07:19 +0000 (16:07 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 27 Nov 2014 10:31:40 +0000 (11:31 +0100)
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>
typo3/sysext/dbal/Classes/Database/SqlParser.php
typo3/sysext/dbal/Tests/Unit/Database/DatabaseConnectionOracleTest.php

index 3100541..020a629 100644 (file)
@@ -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) . ')';
                                                                                                        }
index 3b7a241..7e57bc6 100644 (file)
@@ -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