From 573051827670c5f11c47d52acdd534d057d8bed5 Mon Sep 17 00:00:00 2001 From: Morton Jonuschat <m.jonuschat@mojocode.de> Date: Fri, 9 Oct 2015 23:21:40 +0200 Subject: [PATCH] [BUGFIX] DBAL: VARCHAR DEFAULT NULL PostgreSQL->MySQL syntax conversion 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> --- .../dbal/Classes/Database/Specifics/PostgresSpecifics.php | 7 ++++++- .../Unit/Database/DatabaseSpecificsPostgresqlTest.php | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/typo3/sysext/dbal/Classes/Database/Specifics/PostgresSpecifics.php b/typo3/sysext/dbal/Classes/Database/Specifics/PostgresSpecifics.php index b149327cd74a..af3fe3502143 100644 --- a/typo3/sysext/dbal/Classes/Database/Specifics/PostgresSpecifics.php +++ b/typo3/sysext/dbal/Classes/Database/Specifics/PostgresSpecifics.php @@ -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 { diff --git a/typo3/sysext/dbal/Tests/Unit/Database/DatabaseSpecificsPostgresqlTest.php b/typo3/sysext/dbal/Tests/Unit/Database/DatabaseSpecificsPostgresqlTest.php index b900c4d204be..ede0465c28c6 100644 --- a/typo3/sysext/dbal/Tests/Unit/Database/DatabaseSpecificsPostgresqlTest.php +++ b/typo3/sysext/dbal/Tests/Unit/Database/DatabaseSpecificsPostgresqlTest.php @@ -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"), ); -- GitLab