[BUGFIX] compileWhereClause causes Extbase errors with DBAL
authorPatrick Schriner <patrick.schriner@diemedialen.de>
Mon, 30 May 2011 06:54:00 +0000 (08:54 +0200)
committerXavier Perseguers <typo3@perseguers.ch>
Mon, 30 May 2011 12:40:39 +0000 (14:40 +0200)
t3lib_sqlparser::compileWhereClause iterates over the where subparts. It is called from
DBAL when running DBAL in native (MySQL) mode.

It does however resets its output string whenever the subpart is either FIND_IN_SET or
IFNULL. This causes the queries built by Extbase to fail.

Change-Id: I1c37232fa11a9c3018b07b150fb0478efdef6aa5
Fixes: #25488
Releases: 4.6, 4.5
Reviewed-on: http://review.typo3.org/2421
Reviewed-by: Georg Schönweger
Tested-by: Georg Schönweger
Reviewed-by: Patrick Schriner
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
t3lib/class.t3lib_sqlparser.php
tests/t3lib/class.t3lib_sqlparserTest.php [new file with mode: 0644]

index b41365b..3acf88b 100644 (file)
@@ -2057,12 +2057,12 @@ class t3lib_sqlparser {
                                                $output .= isset($v['func']['pos']) ? ', ' . $v['func']['pos'][0] : '';
                                                $output .= ')';
                                        } elseif (isset($v['func']) && $v['func']['type'] === 'IFNULL') {
-                                               $output = ' ' . trim($v['modifier']) . ' IFNULL(';
+                                               $output .= ' ' . trim($v['modifier']) . ' IFNULL(';
                                                $output .= ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field'];
                                                $output .= ', ' . $v['func']['default'][1] . $this->compileAddslashes($v['func']['default'][0]) . $v['func']['default'][1];
                                                $output .= ')';
                                        } elseif (isset($v['func']) && $v['func']['type'] === 'FIND_IN_SET') {
-                                               $output = ' ' . trim($v['modifier']) . ' FIND_IN_SET(';
+                                               $output .= ' ' . trim($v['modifier']) . ' FIND_IN_SET(';
                                                $output .= $v['func']['str'][1] . $v['func']['str'][0] . $v['func']['str'][1];
                                                $output .= ', ' . ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field'];
                                                $output .= ')';
diff --git a/tests/t3lib/class.t3lib_sqlparserTest.php b/tests/t3lib/class.t3lib_sqlparserTest.php
new file mode 100644 (file)
index 0000000..d6ed240
--- /dev/null
@@ -0,0 +1,128 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Patrick Schriner <patrick.schriner@diemedialen.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Testcase for class t3lib_sqlparser.
+ *
+ * @author Patrick Schriner <patrick.schriner@diemedialen.de>
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ */
+class t3lib_sqlparserTest extends tx_phpunit_testcase {
+       /**
+        * @var t3lib_sqlparser
+        */
+       private $fixture;
+
+       public function setUp() {
+               $this->fixture = new t3lib_sqlparser();
+       }
+
+       public function tearDown() {
+               unset(
+                       $this->fixture
+               );
+       }
+
+       /**
+        * Regression test
+        *
+        * @test
+        */
+       function compileWhereClauseDoesNotDropClauses() {
+               $clauses =      array(
+                       0 => array(
+                               'modifier' => '',
+                               'table' => 'pages',
+                               'field' => 'fe_group',
+                               'calc' => '',
+                               'comparator' => '=',
+                               'value' => array(
+                                       0 => '',
+                                       1 => '\'',
+                               ),
+                       ),
+                       1 => array(
+                               'operator' => 'OR',
+                               'modifier' => '',
+                               'func' => array(
+                                       'type' => 'IFNULL',
+                                       'default' => array(
+                                               0 => '1',
+                                               1 => '\'',
+                                       ),
+                                       'table' => 'pages',
+                                       'field' => 'fe_group',
+                               ),
+                       ),
+                       2 => array(
+                               'operator' => 'OR',
+                               'modifier' => '',
+                               'table' => 'pages',
+                               'field' => 'fe_group',
+                               'calc' => '',
+                               'comparator' => '=',
+                               'value' => array(
+                                       0 => '0',
+                                       1 => '\'',
+                               ),
+                       ),
+                       3 => array(
+                               'operator' => 'OR',
+                               'modifier' => '',
+                               'func' => array (
+                                       'type' => 'FIND_IN_SET',
+                                       'str' => array(
+                                               0 => '0',
+                                               1 => '\'',
+                                       ),
+                                       'table' => 'pages',
+                                       'field' => 'fe_group',
+                               ),
+                               'comparator' => '',
+                       ),
+                       4 => array(
+                               'operator' => 'OR',
+                               'modifier' => '',
+                               'func' => array(
+                                       'type' => 'FIND_IN_SET',
+                                       'str' => array (
+                                               0 => '-1',
+                                               1 => '\'',
+                                       ),
+                                       'table' => 'pages',
+                                       'field' => 'fe_group',
+                               ),
+                               'comparator' => '',
+                       ),
+               );
+               $output = $this->fixture->compileWhereClause($clauses);
+               $parts = explode(' OR ', $output);
+               $this->assertSame(count($clauses), count($parts));
+               $this->assertContains('IFNULL', $output);
+       }
+}
+
+?>
\ No newline at end of file