Fixed bug #6196: IFNULL operator cannot be parsed
authorXavier Perseguers <typo3@perseguers.ch>
Sat, 13 Feb 2010 13:16:52 +0000 (13:16 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Sat, 13 Feb 2010 13:16:52 +0000 (13:16 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@6899 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_sqlparser.php

index 7875b7a..d07d27b 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2010-02-13  Xavier Perseguers  <typo3@perseguers.ch>
 
 2010-02-13  Xavier Perseguers  <typo3@perseguers.ch>
 
+       * Fixed bug #6196: IFNULL operator cannot be parsed
        * Fixed bug #13529: DISTINCT should not be used as a function
 
 2010-02-11  Xavier Perseguers  <typo3@perseguers.ch>
        * Fixed bug #13529: DISTINCT should not be used as a function
 
 2010-02-11  Xavier Perseguers  <typo3@perseguers.ch>
index c82c461..e9561c0 100644 (file)
@@ -1066,7 +1066,30 @@ class t3lib_sqlparser {
                                                }
                                                if (!$this->nextPart($parseString, '^([)])')) {
                                                        return $this->parseError('No ) parenthesis at end of function');
                                                }
                                                if (!$this->nextPart($parseString, '^([)])')) {
                                                        return $this->parseError('No ) parenthesis at end of function');
-                                               }                                               
+                                               }
+                                       } elseif (preg_match('/^IFNULL[[:space:]]*[(]/i', $parseString)) {
+                                               $stack[$level][$pnt[$level]]['func']['type'] = $this->nextPart($parseString, '^(IFNULL)[[:space:]]*');
+                                               $parseString = trim(substr($parseString, 1));   // Strip of "("
+                                               if ($fieldName = $this->nextPart($parseString, '^([[:alnum:]\*._]+)[[:space:]]*')) {
+                                                               // 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, '^(,)')) {
+                                                       $stack[$level][$pnt[$level]]['func']['default'] = $this->getValue($parseString);
+                                               }
+                                               if (!$this->nextPart($parseString, '^([)])')) {
+                                                       return $this->parseError('No ) parenthesis at end of function');
+                                               }
                                        } else {
 
                                                        // Support calculated value only for:
                                        } else {
 
                                                        // Support calculated value only for:
@@ -1885,6 +1908,11 @@ class t3lib_sqlparser {
                                                $output .= ', ' . ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field'];
                                                $output .= isset($v['func']['pos']) ? ', ' . $v['func']['pos'][0] : '';
                                                $output .= ')';
                                                $output .= ', ' . ($v['func']['table'] ? $v['func']['table'] . '.' : '') . $v['func']['field'];
                                                $output .= isset($v['func']['pos']) ? ', ' . $v['func']['pos'][0] : '';
                                                $output .= ')';
+                                       } elseif (isset($v['func']) && $v['func']['type'] === '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 .= ')';
                                        } else {
                                                
                                                        // Set field/table with modifying prefix if any:
                                        } else {
                                                
                                                        // Set field/table with modifying prefix if any: