[BUGFIX] DBAL: Add support for date/time column types to SqlParser 79/42379/3
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 7 Aug 2015 12:54:04 +0000 (14:54 +0200)
committerBenni Mack <benni@typo3.org>
Thu, 13 Aug 2015 05:19:40 +0000 (07:19 +0200)
Add support for the MySQL column types DATE, DATETIME, TIMESTAMP, TIME
and YEAR to the SQL parser. These column types are all supported by
ADOdb an can be remapped to the appropriate type supported by the DBMS.

Resolves: #66929
Releases: master
Change-Id: Ia7c975bee2c19ca0433d164616dcf520f7cb8794
Reviewed-on: http://review.typo3.org/42379
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/dbal/Classes/Database/SqlParser.php
typo3/sysext/dbal/Tests/Unit/Database/SqlParserTest.php

index df47261..b66e5fa 100644 (file)
@@ -1433,7 +1433,7 @@ class SqlParser {
                $this->parse_error = '';
                $result = array();
                // Field type:
-               if ($result['fieldType'] = $this->nextPart($parseString, '^(int|smallint|tinyint|mediumint|bigint|double|numeric|decimal|float|varchar|char|text|tinytext|mediumtext|longtext|blob|tinyblob|mediumblob|longblob)([[:space:],]+|\\()')) {
+               if ($result['fieldType'] = $this->nextPart($parseString, '^(int|smallint|tinyint|mediumint|bigint|double|numeric|decimal|float|varchar|char|text|tinytext|mediumtext|longtext|blob|tinyblob|mediumblob|longblob|date|datetime|time|year|timestamp)([[:space:],]+|\\()')) {
                        // Looking for value:
                        if ($parseString[0] === '(') {
                                $parseString = substr($parseString, 1);
index 6e9c4d5..613a786 100644 (file)
@@ -1012,6 +1012,23 @@ class SqlParserTest extends AbstractTestCase {
 
        /**
         * @test
+        * @see http://forge.typo3.org/issues/66929
+        */
+       public function createTableSupportsDateAndTimeTypes() {
+               $parseString = 'CREATE TABLE fe_users (' .
+                       'testdate date DEFAULT \'0000-00-00\',' .
+                       'testdatetime datetime DEFAULT \'0000-00-00 00:00:00\',' .
+                       'testtimestamp timestamp DEFAULT \'0000-00-00 00:00:00\',' .
+                       'testtime time DEFAULT \'00:00:00\',' .
+                       'testyear year DEFAULT \'0000\')';
+
+               $components = $this->subject->_callRef('parseCREATETABLE', $parseString);
+               $actual = $this->subject->compileSQL($components);
+               $this->assertEquals($this->cleanSql($parseString), $actual);
+       }
+
+       /**
+        * @test
         * @see http://forge.typo3.org/issues/21730
         */
        public function indexMayContainALengthRestrictionInAlterTable() {