[BUGFIX] SQL parser does not support string as join condition 44/40144/2
authorXavier Perseguers <xavier@typo3.org>
Wed, 10 Jun 2015 09:04:47 +0000 (11:04 +0200)
committerXavier Perseguers <xavier@typo3.org>
Wed, 10 Jun 2015 09:19:56 +0000 (11:19 +0200)
The SQL parser is capable of parsing

    JOIN T1 ON T1.some_field = T2.some_other_field

and

    JOIN T1 ON T1.some_field = 4

but not

    JOIN T1 ON T1.some_field = 'some string'

Change-Id: I7806699ea44685ab717cc0e8a75f7b53a1b2b1cc
Resolves: #67385
Related: #66614
Releases: master, 6.2
Reviewed-on: http://review.typo3.org/40144
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
typo3/sysext/core/Classes/Database/SqlParser.php
typo3/sysext/dbal/Tests/Unit/Database/SqlParserTest.php

index 6772562..a982d46 100644 (file)
@@ -914,6 +914,8 @@ class SqlParser {
                                                                $condition['right']['table'] = '';
                                                                $condition['right']['field'] = $tableField[0];
                                                        }
+                                               } elseif ($value = $this->getValue($parseString)) {
+                                                       $condition['right']['value'] = $value;
                                                } else {
                                                        return $this->parseError('No join field found in parseFromTables()!', $parseString);
                                                }
@@ -1804,8 +1806,13 @@ class SqlParser {
                                                        $outputParts[$k] .= $condition['left']['table'] ? $condition['left']['table'] . '.' : '';
                                                        $outputParts[$k] .= $condition['left']['field'];
                                                        $outputParts[$k] .= $condition['comparator'];
-                                                       $outputParts[$k] .= $condition['right']['table'] ? $condition['right']['table'] . '.' : '';
-                                                       $outputParts[$k] .= $condition['right']['field'];
+                                                       if (!empty($condition['right']['value'])) {
+                                                               $value = $condition['right']['value'];
+                                                               $outputParts[$k] .= $value[1] . $this->compileAddslashes($value[0]) . $value[1];
+                                                       } else {
+                                                               $outputParts[$k] .= $condition['right']['table'] ? $condition['right']['table'] . '.' : '';
+                                                               $outputParts[$k] .= $condition['right']['field'];
+                                                       }
                                                }
                                        }
                                }
index d2aa287..af33f98 100644 (file)
@@ -416,6 +416,18 @@ class SqlParserTest extends AbstractTestCase {
 
        /**
         * @test
+        * @see http://forge.typo3.org/issues/67385
+        */
+       public function canParseMultiJoinConditionsWithStrings() {
+               $sql = 'SELECT * FROM sys_file_processedfile LEFT JOIN sys_registry ON entry_key = sys_file_processedfile.uid AND entry_namespace = \'ProcessedFileChecksumUpdate\'';
+
+               $result = $this->subject->debug_testSQL($sql);
+               $expected = 'SELECT * FROM sys_file_processedfile LEFT JOIN sys_registry ON entry_key=sys_file_processedfile.uid AND entry_namespace=\'ProcessedFileChecksumUpdate\'';
+               $this->assertEquals($expected, $this->cleanSql($result));
+       }
+
+       /**
+        * @test
         * @see http://forge.typo3.org/issues/22501
         */
        public function canParseMultipleJoinConditionsWithLessThanOperator() {