Fixed bug #12535: DAM-related: Element browser crashes as where-clause cannot be...
authorXavier Perseguers <typo3@perseguers.ch>
Sun, 8 Aug 2010 14:19:23 +0000 (14:19 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Sun, 8 Aug 2010 14:19:23 +0000 (14:19 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/dbal/trunk@36497 735d13b6-9817-0410-8766-e36946ffe9aa

typo3/sysext/dbal/ChangeLog
typo3/sysext/dbal/class.ux_t3lib_sqlparser.php
typo3/sysext/dbal/tests/dbGeneralTest.php
typo3/sysext/dbal/tests/dbOracleTest.php
typo3/sysext/dbal/tests/dbPostgresqlTest.php

index 8b0654f..49babb6 100644 (file)
@@ -1,3 +1,7 @@
+2010-08-08  Xavier Perseguers  <typo3@perseguers.ch>
+
+       * Fixed bug #12535: DAM-related: Element browser crashes as where-clause cannot be parsed
+
 2010-07-27  Xavier Perseguers  <typo3@perseguers.ch>
 
        * Fixed bug #15160: Queries should only be parsed once
index ec11b9d..c1b1d3d 100644 (file)
@@ -575,15 +575,16 @@ class ux_t3lib_sqlparser extends t3lib_sqlparser {
                                                                        } else {
                                                                                $output .= $v['calc_value'][1] . $this->compileAddslashes($v['calc_value'][0]) . $v['calc_value'][1];
                                                                        }
-                                                               } elseif (!($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8') && $v['comparator'] === 'LIKE' && $functionMapping)) {
+                                                               } elseif (!($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8') && preg_match('/(NOT )?LIKE( BINARY)?/', $v['comparator']) && $functionMapping)) {
                                                                        $output .= trim(($v['table'] ? $v['table'] . '.' : '') . $v['field']);
                                                                }
                                                        }
 
                                                                // Set comparator:
                                                        if ($v['comparator']) {
+                                                               $isLikeOperator = preg_match('/(NOT )?LIKE( BINARY)?/', $v['comparator']);
                                                                switch (TRUE) {
-                                                                       case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8') && $v['comparator'] === 'LIKE' && $functionMapping):
+                                                                       case ($GLOBALS['TYPO3_DB']->runningADOdbDriver('oci8') && $isLikeOperator && $functionMapping):
                                                                                                // Oracle cannot handle LIKE on CLOB fields - sigh
                                                                                        if (isset($v['value']['operator'])) {
                                                                                                $values = array();
@@ -594,6 +595,9 @@ class ux_t3lib_sqlparser extends t3lib_sqlparser {
                                                                                        } else {
                                                                                                $compareValue = $v['value'][1] . $this->compileAddslashes(trim($v['value'][0], '%')) . $v['value'][1]; 
                                                                                        }
+                                                                                       if (t3lib_div::isFirstPartOfStr($v['comparator'], 'NOT')) {
+                                                                                               $output .= 'NOT ';
+                                                                                       }
                                                                                                // To be on the safe side
                                                                                        $isLob = TRUE;
                                                                                        if ($v['table']) {
@@ -610,6 +614,32 @@ class ux_t3lib_sqlparser extends t3lib_sqlparser {
                                                                                        }
                                                                                break;
                                                                        default:
+                                                                               if ($isLikeOperator && $functionMapping) {
+                                                                                       if ($GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres') ||
+                                                                                               $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres64') ||
+                                                                                               $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres7') ||
+                                                                                               $GLOBALS['TYPO3_DB']->runningADOdbDriver('postgres8')) {
+
+                                                                                                       // Remap (NOT)? LIKE to (NOT)? ILIKE
+                                                                                                       // and (NOT)? LIKE BINARY to (NOT)? LIKE
+                                                                                               switch ($v['comparator']) {
+                                                                                                       // Remap (NOT)? LIKE to (NOT)? ILIKE
+                                                                                                       case 'LIKE':
+                                                                                                               $v['comparator'] = 'ILIKE';
+                                                                                                               break;
+                                                                                                       case 'NOT LIKE':
+                                                                                                               $v['comparator'] = 'NOT ILIKE';
+                                                                                                               break;
+                                                                                                       default:
+                                                                                                               $v['comparator'] = str_replace(' BINARY', '', $v['comparator']);
+                                                                                                               break;
+                                                                                               }
+                                                                                       } else {
+                                                                                                       // No more BINARY operator
+                                                                                               $v['comparator'] = str_replace(' BINARY', '', $v['comparator']);
+                                                                                       } 
+                                                                               }
+
                                                                                $output .= ' ' . $v['comparator'];
 
                                                                                        // Detecting value type; list or plain:
index deabb27..a541ab5 100644 (file)
@@ -242,5 +242,33 @@ class dbGeneralTest extends BaseTestCase {
                $expected = 'SELECT * FROM pages WHERE MAX(uid) IN (1,2,3,4)';
                $this->assertEquals($expected, $query);
        }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=12535
+        */
+       public function likeBinaryOperatorIsKept() {
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
+                       '*',
+                       'tt_content',
+                       'bodytext LIKE BINARY \'test\''
+               ));
+               $expected = 'SELECT * FROM tt_content WHERE bodytext LIKE BINARY \'test\'';
+               $this->assertEquals($expected, $query);
+       }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=12535
+        */
+       public function notLikeBinaryOperatorIsKept() {
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
+                       '*',
+                       'tt_content',
+                       'bodytext NOT LIKE BINARY \'test\''
+               ));
+               $expected = 'SELECT * FROM tt_content WHERE bodytext NOT LIKE BINARY \'test\'';
+               $this->assertEquals($expected, $query);
+       }
 }
 ?>
\ No newline at end of file
index 42dae51..0a2671e 100644 (file)
@@ -1083,5 +1083,19 @@ class dbOracleTest extends BaseTestCase {
                $expected = 'SELECT * FROM "fe_users" WHERE \',\'||"usergroup"||\',\' LIKE \'%,10,%\'';
                $this->assertEquals($expected, $query);
        }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=12535
+        */
+       public function likeBinaryOperatorIsRemoved() {
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
+                       '*',
+                       'tt_content',
+                       'bodytext LIKE BINARY \'test\''
+               ));
+               $expected = 'SELECT * FROM "tt_content" WHERE (dbms_lob.instr("bodytext", \'test\',1,1) > 0)';
+               $this->assertEquals($expected, $query);
+       }
 }
 ?>
\ No newline at end of file
index 5be3784..9fb87a7 100644 (file)
@@ -174,5 +174,61 @@ class dbPostgresqlTest extends BaseTestCase {
                $expected = 'SELECT * FROM "fe_users" WHERE FIND_IN_SET(10, "usergroup") != 0';
                $this->assertEquals($expected, $query);
        }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=12535
+        */
+       public function likeBinaryOperatorIsRemappedToLike() {
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
+                       '*',
+                       'tt_content',
+                       'bodytext LIKE BINARY \'test\''
+               ));
+               $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" LIKE \'test\'';
+               $this->assertEquals($expected, $query);
+       }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=12535
+        */
+       public function notLikeBinaryOperatorIsRemappedToNotLike() {
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
+                       '*',
+                       'tt_content',
+                       'bodytext NOT LIKE BINARY \'test\''
+               ));
+               $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT LIKE \'test\'';
+               $this->assertEquals($expected, $query);
+       }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=12535
+        */
+       public function likeOperatorIsRemappedToIlike() {
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
+                       '*',
+                       'tt_content',
+                       'bodytext LIKE \'test\''
+               ));
+               $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" ILIKE \'test\'';
+               $this->assertEquals($expected, $query);
+       }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=12535
+        */
+       public function notLikeOperatorIsRemappedToNotIlike() {
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
+                       '*',
+                       'tt_content',
+                       'bodytext NOT LIKE \'test\''
+               ));
+               $expected = 'SELECT * FROM "tt_content" WHERE "bodytext" NOT ILIKE \'test\'';
+               $this->assertEquals($expected, $query);
+       }
 }
 ?>
\ No newline at end of file