Skip to content
Snippets Groups Projects
Commit 57305182 authored by Morton Jonuschat's avatar Morton Jonuschat
Browse files

[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: default avatarNicole Cordes <typo3@cordes.co>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: default avatarAndreas Fernandez <typo3@scripting-base.de>
Reviewed-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
parent e2d2b187
Branches
Tags
No related merge requests found
......@@ -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 {
......
......@@ -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"),
);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment