Fixed bug #12071: t3lib_sqlparser is not able to parse alias of a joined table
authorOliver Hader <oliver.hader@typo3.org>
Thu, 1 Oct 2009 09:52:12 +0000 (09:52 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 1 Oct 2009 09:52:12 +0000 (09:52 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@6082 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_sqlparser.php

index b7351e4..4bc68ee 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-10-01  Oliver Hader  <oliver@typo3.org>
+
+       * Fixed bug #12071: t3lib_sqlparser is not able to parse alias of a joined table (thanks to Xavier Perseguers)
+
 2009-10-01  Rupert Germann  <rupi@gmx.li>
 
        * Follow-up to bug #11357: fixed a parse error in index_re.php
index e2078c4..2c2b0bc 100644 (file)
@@ -817,7 +817,14 @@ class t3lib_sqlparser {
                                // Looking for JOIN
                        if ($join = $this->nextPart($parseString,'^(LEFT[[:space:]]+JOIN|LEFT[[:space:]]+OUTER[[:space:]]+JOIN|JOIN)[[:space:]]+'))     {
                                $stack[$pnt]['JOIN']['type'] = $join;
-                               if ($stack[$pnt]['JOIN']['withTable'] = $this->nextPart($parseString,'^([[:alnum:]_]+)[[:space:]]+ON[[:space:]]+',1))   {
+                               if ($stack[$pnt]['JOIN']['withTable'] = $this->nextPart($parseString, '^([[:alnum:]_]+)[[:space:]]+', 1)) {
+                                       if (!preg_match('/^ON[[:space:]]+/i', $parseString)) {
+                                               $stack[$pnt]['JOIN']['as_keyword'] = $this->nextPart($parseString, '^(AS[[:space:]]+)');
+                                               $stack[$pnt]['JOIN']['as'] = $this->nextPart($parseString, '^([[:alnum:]_]+)[[:space:]]+');
+                                       }
+                                       if (!$this->nextPart($parseString, '^(ON[[:space:]]+)')) {
+                                               return $this->parseError('No join condition found in parseFromTables()!', $parseString);
+                                       }
                                        $field1 = $this->nextPart($parseString,'^([[:alnum:]_.]+)[[:space:]]*=[[:space:]]*',1);
                                        $field2 = $this->nextPart($parseString,'^([[:alnum:]_.]+)[[:space:]]+');
                                        if ($field1 && $field2) {
@@ -1533,7 +1540,12 @@ return $str;
                                }
 
                                if (is_array($v['JOIN']))       {
-                                       $outputParts[$k] .= ' '.$v['JOIN']['type'].' '.$v['JOIN']['withTable'].' ON ';
+                                       $outputParts[$k] .= ' ' . $v['JOIN']['type'] . ' ' . $v['JOIN']['withTable'];
+                                               // Add alias AS if there:
+                                       if (isset($v['JOIN']['as']) && $v['JOIN']['as']) {
+                                               $outputParts[$k] .= ' ' . $v['JOIN']['as_keyword'] . ' ' . $v['JOIN']['as'];
+                                       }
+                                       $outputParts[$k] .= ' ON ';
                                        $outputParts[$k] .= ($v['JOIN']['ON'][0]['table']) ? $v['JOIN']['ON'][0]['table'].'.' : '';
                                        $outputParts[$k] .= $v['JOIN']['ON'][0]['field'];
                                        $outputParts[$k] .= '=';