Backported changeset 27116 from branch DBAL_1-0
authorXavier Perseguers <typo3@perseguers.ch>
Sun, 29 Nov 2009 12:35:31 +0000 (12:35 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Sun, 29 Nov 2009 12:35:31 +0000 (12:35 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/dbal/trunk@27117 735d13b6-9817-0410-8766-e36946ffe9aa

typo3/sysext/dbal/ChangeLog
typo3/sysext/dbal/class.ux_t3lib_sqlparser.php
typo3/sysext/dbal/tests/db_oracle_testcase.php

index 9638b81..f35702b 100644 (file)
@@ -1,6 +1,7 @@
 2009-11-29  Xavier Perseguers  <typo3@perseguers.ch>
 
        * Set version to 1.0.2 [TYPO3 4.3.0]
+       * Follow-up of changeset 26118: parts of initial patch for RFC 12231 had actually not been integrated
 
 2009-11-27  Xavier Perseguers  <typo3@perseguers.ch>
 
index 26d07e0..c696da9 100644 (file)
@@ -210,7 +210,19 @@ class ux_t3lib_sqlparser extends t3lib_sqlparser {
                                $stack[$level][$pnt[$level]]['calc'] = $this->nextPart($parseString, '^(' . $calcOperators . ')');
                                if (strlen($stack[$level][$pnt[$level]]['calc'])) {
                                                // Finding value for calculation:
-                                       $stack[$level][$pnt[$level]]['calc_value'] = $this->getValue($parseString);
+                                       $calc_value = $this->getValue($parseString);
+                                       $stack[$level][$pnt[$level]]['calc_value'] = $calc_value;
+                                       if (count($calc_value) == 1 && is_string($calc_value[0])) {
+                                                       // Value is a field, store it to allow DBAL to post-process it (quoting, remapping)
+                                               $tableField = explode('.', $calc_value[0], 2);
+                                               if (count($tableField) == 2) {
+                                                       $stack[$level][$pnt[$level]]['calc_table'] = $tableField[0];
+                                                       $stack[$level][$pnt[$level]]['calc_field'] = $tableField[1];
+                                               } else {
+                                                       $stack[$level][$pnt[$level]]['calc_table'] = '';
+                                                       $stack[$level][$pnt[$level]]['calc_field'] = $tableField[0];
+                                               }
+                                       }
                                }
 
                                        // Find "comparator":
index 1fa2cdc..2cc1f73 100644 (file)
@@ -208,6 +208,37 @@ class db_oracle_testcase extends BaseTestCase {
                $this->assertEquals($expected, $query);
        }
 
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=12231
+        */
+       public function cachingFrameworkQueryIsProperlyQuoted() {
+               $currentTime = time();
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
+                       'content',
+                       'cache_hash',
+                       'identifier = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('abbbabaf2d4b3f9a63e8dde781f1c106', 'cache_hash') .
+                               ' AND (crdate + lifetime >= ' . $currentTime . ' OR lifetime = 0)'
+               ));
+               $expected = 'SELECT "content" FROM "cache_hash" WHERE "identifier" = \'abbbabaf2d4b3f9a63e8dde781f1c106\' AND ("crdate"+"lifetime" >= ' . $currentTime . ' OR "lifetime" = 0)';
+               $this->assertEquals($expected, $query);
+       }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=12231
+        */
+       public function calculatedFieldsAreProperlyQuoted() {
+               $currentTime = time();
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
+                       'identifier',
+                       'cachingframework_cache_pages',
+                       'crdate + lifetime < ' . $currentTime . ' AND lifetime > 0'
+               ));
+               $expected = 'SELECT "identifier" FROM "cachingframework_cache_pages" WHERE "crdate"+"lifetime" < ' . $currentTime . ' AND "lifetime" > 0';
+               $this->assertEquals($expected, $query);
+       }
+
        ///////////////////////////////////////
        // Tests concerning remapping
        ///////////////////////////////////////