Fixed bug #14182: Multiple join conditions are not supported
authorXavier Perseguers <typo3@perseguers.ch>
Thu, 22 Apr 2010 14:27:48 +0000 (14:27 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Thu, 22 Apr 2010 14:27:48 +0000 (14:27 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/dbal/trunk@32481 735d13b6-9817-0410-8766-e36946ffe9aa

typo3/sysext/dbal/ChangeLog
typo3/sysext/dbal/class.ux_t3lib_db.php
typo3/sysext/dbal/tests/sqlparser_general_testcase.php

index ce7514c..139cc3d 100644 (file)
@@ -1,3 +1,7 @@
+2010-04-22  Xavier Perseguers  <typo3@perseguers.ch>
+
+       * Fixed bug #14182: Multiple join conditions are not supported
+
 2010-04-15  Xavier Perseguers  <typo3@perseguers.ch>
 
        * Fixed bug #14120: Add a method to check if database is connected
index 5a8c66e..352a23b 100644 (file)
@@ -1254,10 +1254,12 @@ class ux_t3lib_DB extends t3lib_DB {
                                foreach ($v['JOIN'] as $joinCnt => $join) {
                                        $from_table[$k]['JOIN'][$joinCnt]['withTable'] = $this->quoteName($join['withTable']);
                                        $from_table[$k]['JOIN'][$joinCnt]['as'] = ($join['as']) ? $this->quoteName($join['as']) : '';
-                                       $from_table[$k]['JOIN'][$joinCnt]['ON'][0]['table'] = ($join['ON'][0]['table']) ? $this->quoteName($join['ON'][0]['table']) : '';
-                                       $from_table[$k]['JOIN'][$joinCnt]['ON'][0]['field'] = $this->quoteName($join['ON'][0]['field']);
-                                       $from_table[$k]['JOIN'][$joinCnt]['ON'][1]['table'] = ($join['ON'][1]['table']) ? $this->quoteName($join['ON'][1]['table']) : '';
-                                       $from_table[$k]['JOIN'][$joinCnt]['ON'][1]['field'] = $this->quoteName($join['ON'][1]['field']);
+                                       foreach ($from_table[$k]['JOIN'][$joinCnt]['ON'] as &$condition) {
+                                               $condition['left']['table'] = ($condition['left']['table']) ? $this->quoteName($condition['left']['table']) : '';
+                                               $condition['left']['field'] = $this->quoteName($condition['left']['field']);
+                                               $condition['right']['table'] = ($condition['right']['table']) ? $this->quoteName($condition['right']['table']) : '';
+                                               $condition['right']['field'] = $this->quoteName($condition['right']['field']);
+                                       }
                                }
                        }
                }
@@ -2755,17 +2757,23 @@ class ux_t3lib_DB extends t3lib_DB {
                                        }
                                        $onPartsArray = array();
                                                // Mapping ON parts of the JOIN
-                                       if (is_array($join['ON'])) {
-                                               foreach ($join['ON'] as $onParts) {
-                                                       if (isset($this->mapping[$onParts['table']]['mapFieldNames'][$onParts['field']])) {
-                                                               $onParts['field'] = $this->mapping[$onParts['table']]['mapFieldNames'][$onParts['field']];
+                                       if (is_array($tables[$k]['JOIN'][$joinCnt]['ON'])) {
+                                               foreach ($tables[$k]['JOIN'][$joinCnt]['ON'] as &$condition) {
+                                                               // Left side of the comparator
+                                                       if (isset($this->mapping[$condition['left']['table']]['mapFieldNames'][$condition['left']['field']])) {
+                                                               $condition['left']['field'] = $this->mapping[$condition['left']['table']]['mapFieldNames'][$condition['left']['field']];
+                                                       }
+                                                       if (isset($this->mapping[$condition['left']['table']]['mapTableName'])) {
+                                                               $condition['left']['table'] = $this->mapping[$condition['left']['table']]['mapTableName'];
+                                                       }
+                                                               // Right side of the comparator
+                                                       if (isset($this->mapping[$condition['right']['table']]['mapFieldNames'][$condition['right']['field']])) {
+                                                               $condition['right']['field'] = $this->mapping[$condition['right']['table']]['mapFieldNames'][$condition['right']['field']];
                                                        }
-                                                       if (isset($this->mapping[$onParts['table']]['mapTableName'])) {
-                                                               $onParts['table'] = $this->mapping[$onParts['table']]['mapTableName'];
+                                                       if (isset($this->mapping[$condition['right']['table']]['mapTableName'])) {
+                                                               $condition['right']['table'] = $this->mapping[$condition['right']['table']]['mapTableName'];
                                                        }
-                                                       $onPartsArray[] = $onParts;
                                                }
-                                               $tables[$k]['JOIN'][$joinCnt]['ON'] = $onPartsArray;
                                        }
                                }
                        }
index 04798d1..7c531c3 100644 (file)
@@ -420,6 +420,30 @@ class sqlparser_general_testcase extends BaseTestCase {
                $this->assertEquals($expected, $actual);
        }
 
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=14182
+        */
+       public function canParseMultipleJoinConditions() {
+               $sql = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.pid = T1.uid AND T2.size = 4 WHERE T1.cr_userid = 1';
+               $expected = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.pid=T1.uid AND T2.size=4 WHERE T1.cr_userid = 1';
+               $actual = $this->cleanSql($this->fixture->debug_testSQL($sql));
+
+               $this->assertEquals($expected, $actual);
+       }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=14182 
+        */
+       public function canParseMultipleJoinConditionsWithLessThanOperator() {
+               $sql = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.size < 4 OR T2.pid = T1.uid WHERE T1.cr_userid = 1';
+               $expected = 'SELECT * FROM T1 LEFT OUTER JOIN T2 ON T2.size<4 OR T2.pid=T1.uid WHERE T1.cr_userid = 1';
+               $actual = $this->cleanSql($this->fixture->debug_testSQL($sql));
+
+               $this->assertEquals($expected, $actual);
+       }
+
        ///////////////////////////////////////
        // Tests concerning DB management
        ///////////////////////////////////////