[BUGFIX] DBAL: VARCHAR DEFAULT NULL PostgreSQL->MySQL syntax conversion 57/43957/3
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 9 Oct 2015 21:21:40 +0000 (23:21 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Sat, 10 Oct 2015 09:20:39 +0000 (11:20 +0200)
PostgreSQL returns 'NULL::character varying' as the default value for a
field defined with 'VARCHAR(255) DEFAULT NULL'. The schema compare in
the InstallTool expects the MySQL syntax without the trailing
::character varying. Add support for this default value type to the
converter that rewrites the PostgreSQL default values to MySQL.

Resolves: #70558
Releases: master
Change-Id: If49962a3be265ca7a51e3f178a0682a9a073e9b7
Reviewed-on: http://review.typo3.org/43957
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/dbal/Classes/Database/Specifics/PostgresSpecifics.php
typo3/sysext/dbal/Tests/Unit/Database/DatabaseSpecificsPostgresqlTest.php

index b149327..af3fe35 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Dbal\Database\Specifics;
  */
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
  * This class contains the specifics for PostgreSQL DBMS.
@@ -100,7 +101,11 @@ class PostgresSpecifics extends AbstractSpecifics
             $returnValue = null;
         } elseif ($fieldDefinition['type'] === 'varchar') {
             // Strip character class and unquote string
-            $returnValue = str_replace("\\'", "'", preg_replace('/\'(.*)\'(::(?:character\svarying|varchar|character|char|text)(?:\(\d+\))?)?\z/', '\\1', $fieldDefinition['default_value']));
+            if (StringUtility::beginsWith($fieldDefinition['default_value'], 'NULL::')) {
+                $returnValue = null;
+            } else {
+                $returnValue = str_replace("\\'", "'", preg_replace('/\'(.*)\'(::(?:character\svarying|varchar|character|char|text)(?:\(\d+\))?)?\z/', '\\1', $fieldDefinition['default_value']));
+            }
         } elseif (substr($fieldDefinition['type'], 0, 3) === 'int') {
             $returnValue = (int)preg_replace('/^\(?(\-?\d+)\)?$/', '\\1', $fieldDefinition['default_value']);
         } else {
index b900c4d..ede0465 100644 (file)
@@ -158,6 +158,7 @@ class DatabaseSpecificsPostgresqlTest extends DatabaseSpecificsTest
             array(array('type' => 'int4', 'has_default' => true, 'default_value' => '(-1)'), -1),
             array(array('type' => 'text', 'has_default' => false, 'default_value' => null), null),
             array(array('type' => 'varchar', 'has_default' => true, 'default_value' => "''::character varying"), ""),
+            array(array('type' => 'varchar', 'has_default' => true, 'default_value' => "NULL::character varying"), null),
             array(array('type' => 'varchar', 'has_default' => true, 'default_value' => "'something'::character varying"), "something"),
             array(array('type' => 'varchar', 'has_default' => true, 'default_value' => "'some''thing'::character varying"), "some''thing"),
         );