Fixed bug #14985: FIND_IN_SET should be used isntead of complicated LIKE where clause
authorXavier Perseguers <typo3@perseguers.ch>
Fri, 16 Jul 2010 13:21:12 +0000 (13:21 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Fri, 16 Jul 2010 13:21:12 +0000 (13:21 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@8196 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_sqlparser.php

index 28aebde..3b0d345 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-07-16  Xavier Perseguers  <typo3@perseguers.ch>
+
+       * Fixed bug #14985: FIND_IN_SET should be used isntead of complicated LIKE where clause
+
 2010-07-16  Christian Kuhn  <lolli@schwarzbu.ch>
 
        * Fixed bug #15142: [Unit tests] Remove unnecessary require_once() calls
index 1f0f2f3..458d169 100644 (file)
@@ -1117,6 +1117,31 @@ class t3lib_sqlparser {
                                                if (!$this->nextPart($parseString, '^([)])')) {
                                                        return $this->parseError('No ) parenthesis at end of function');
                                                }
+                                       } elseif (preg_match('/^FIND_IN_SET[[:space:]]*[(]/i', $parseString)) {
+                                               $stack[$level][$pnt[$level]]['func']['type'] = $this->nextPart($parseString, '^(FIND_IN_SET)[[:space:]]*');
+                                               $parseString = trim(substr($parseString, 1));   // Strip of "("
+                                               if ($str = $this->getValue($parseString)) {
+                                                       $stack[$level][$pnt[$level]]['func']['str'] = $str;
+                                                       if ($fieldName = $this->nextPart($parseString, '^,[[:space:]]*([[:alnum:]._]+)[[:space:]]*', TRUE)) {
+
+                                                                       // Parse field name into field and table:
+                                                               $tableField = explode('.', $fieldName, 2);
+                                                               if (count($tableField) == 2) {
+                                                                       $stack[$level][$pnt[$level]]['func']['table'] = $tableField[0];
+                                                                       $stack[$level][$pnt[$level]]['func']['field'] = $tableField[1];
+                                                               } else {
+                                                                       $stack[$level][$pnt[$level]]['func']['table'] = '';
+                                                                       $stack[$level][$pnt[$level]]['func']['field'] = $tableField[0];
+                                                               }
+                                                       } else {
+                                                               return $this->parseError('No field name found as expected in parseWhereClause()', $parseString);
+                                                       }
+                                                       if (!$this->nextPart($parseString, '^([)])')) {
+                                                               return $this->parseError('No ) parenthesis at end of function', $parseString);
+                                                       }
+                                               } else {
+                                                       return $this->parseError('No item to look for found as expected in parseWhereClause()', $parseString);
+                                               }
                                        } else {
 
                                                        // Support calculated value only for:
@@ -1954,6 +1979,11 @@ class t3lib_sqlparser {
                                                $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 .= $v['func']['str'][1] . $v['func']['str'][0] . $v['func']['str'][1];
+                                               $output .= ', ' . ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field'];
+                                               $output .= ')';
                                        } else {
 
                                                        // Set field/table with modifying prefix if any: