From 0e00958f4fd74a394b022edfb9d354b618222282 Mon Sep 17 00:00:00 2001 From: manfred Date: Tue, 5 Mar 2024 16:51:00 +0100 Subject: [PATCH 1/2] removed blob/text default value checks, implemented unquote of default values on TEXT/BLOB fields --- src/Propel/Generator/Platform/MysqlPlatform.php | 4 ---- src/Propel/Generator/Reverse/MysqlSchemaParser.php | 9 ++++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Propel/Generator/Platform/MysqlPlatform.php b/src/Propel/Generator/Platform/MysqlPlatform.php index 674da5667..2815b909f 100644 --- a/src/Propel/Generator/Platform/MysqlPlatform.php +++ b/src/Propel/Generator/Platform/MysqlPlatform.php @@ -464,10 +464,6 @@ public function getColumnDDL(Column $col): string if ($def && $def->isExpression()) { throw new EngineException('DATE columns cannot have default *expressions* in MySQL.'); } - } elseif ($sqlType === 'TEXT' || $sqlType === 'BLOB') { - if ($domain->getDefaultValue()) { - throw new EngineException('BLOB and TEXT columns cannot have DEFAULT values. in MySQL.'); - } } $ddl = [$this->quoteIdentifier($col->getName())]; diff --git a/src/Propel/Generator/Reverse/MysqlSchemaParser.php b/src/Propel/Generator/Reverse/MysqlSchemaParser.php index 0e1350739..708a85eb7 100644 --- a/src/Propel/Generator/Reverse/MysqlSchemaParser.php +++ b/src/Propel/Generator/Reverse/MysqlSchemaParser.php @@ -262,7 +262,14 @@ public function getColumnFromRow(array $row, Table $table): Column } // BLOBs can't have any default values in MySQL - $default = preg_match('~blob|text~', $nativeType) ? null : $row['Default']; + + $default = $row['Default']; + if (!empty($default)) { + if (preg_match('~blob|text~', $nativeType)) { + // mariadb has extra single quotes on TEXT type default values, but not on other types + $default = preg_replace('@^\'(.*)\'$@', '$1', $row['Default']); + } + } $propelType = $this->getMappedPropelType($nativeType); if (!$propelType) { From b2638db73a8026047d66323b55b62a628952513a Mon Sep 17 00:00:00 2001 From: manfred Date: Tue, 5 Mar 2024 17:21:13 +0100 Subject: [PATCH 2/2] fixed phpcs code style --- src/Propel/Generator/Reverse/MysqlSchemaParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Propel/Generator/Reverse/MysqlSchemaParser.php b/src/Propel/Generator/Reverse/MysqlSchemaParser.php index 708a85eb7..1b24730b5 100644 --- a/src/Propel/Generator/Reverse/MysqlSchemaParser.php +++ b/src/Propel/Generator/Reverse/MysqlSchemaParser.php @@ -264,7 +264,7 @@ public function getColumnFromRow(array $row, Table $table): Column // BLOBs can't have any default values in MySQL $default = $row['Default']; - if (!empty($default)) { + if ($default !== null) { if (preg_match('~blob|text~', $nativeType)) { // mariadb has extra single quotes on TEXT type default values, but not on other types $default = preg_replace('@^\'(.*)\'$@', '$1', $row['Default']);