From e02e8d69cfb8a36489619e8ccfffa1b27f75b3b3 Mon Sep 17 00:00:00 2001 From: dsentker Date: Thu, 25 Jan 2024 10:02:52 +0100 Subject: [PATCH 1/6] Avoid ambigous TABLE_NAME in query --- src/Platforms/MariaDb1043Platform.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Platforms/MariaDb1043Platform.php b/src/Platforms/MariaDb1043Platform.php index 5f51ac34cc9..63bd26a3a17 100644 --- a/src/Platforms/MariaDb1043Platform.php +++ b/src/Platforms/MariaDb1043Platform.php @@ -99,9 +99,9 @@ public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $datab IF( $tableAlias.COLUMN_TYPE = 'longtext' AND EXISTS( - SELECT * from information_schema.CHECK_CONSTRAINTS - WHERE CONSTRAINT_SCHEMA = $databaseName - AND TABLE_NAME = $tableAlias.TABLE_NAME + SELECT * from information_schema.CHECK_CONSTRAINTS t + WHERE t.CONSTRAINT_SCHEMA = $databaseName + AND t.TABLE_NAME = $tableAlias.TABLE_NAME AND CHECK_CLAUSE = CONCAT( 'json_valid(`', $tableAlias.COLUMN_NAME, From 1941c39cd7c53670d0a362413e11575e16858ce6 Mon Sep 17 00:00:00 2001 From: dsentker Date: Fri, 26 Jan 2024 15:46:55 +0100 Subject: [PATCH 2/6] Rebase 3.8.0 from upstream --- src/Platforms/MariaDb1043Platform.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Platforms/MariaDb1043Platform.php b/src/Platforms/MariaDb1043Platform.php index 63bd26a3a17..406ad2dd5a3 100644 --- a/src/Platforms/MariaDb1043Platform.php +++ b/src/Platforms/MariaDb1043Platform.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Platforms; +use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Types\JsonType; use Doctrine\Deprecations\Deprecation; @@ -92,6 +93,11 @@ public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $datab ); } + // 't' alias is already in use for following query + if ($tableAlias === 't') { + throw new InvalidArgumentException('Table alias "t" is not allowed, please choose another one.'); + } + $databaseName = $this->getDatabaseNameSQL($databaseName); // The check for `CONSTRAINT_SCHEMA = $databaseName` is mandatory here to prevent performance issues @@ -102,7 +108,7 @@ public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $datab SELECT * from information_schema.CHECK_CONSTRAINTS t WHERE t.CONSTRAINT_SCHEMA = $databaseName AND t.TABLE_NAME = $tableAlias.TABLE_NAME - AND CHECK_CLAUSE = CONCAT( + AND t.CHECK_CLAUSE = CONCAT( 'json_valid(`', $tableAlias.COLUMN_NAME, '`)' From a43de21c2bebea9493e01d43fcd925b502d4ec5f Mon Sep 17 00:00:00 2001 From: dsentker Date: Fri, 26 Jan 2024 15:54:05 +0100 Subject: [PATCH 3/6] Use a more elegant way to avoid same aliases --- src/Platforms/MariaDb1043Platform.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Platforms/MariaDb1043Platform.php b/src/Platforms/MariaDb1043Platform.php index 406ad2dd5a3..9bcd3e538bd 100644 --- a/src/Platforms/MariaDb1043Platform.php +++ b/src/Platforms/MariaDb1043Platform.php @@ -93,10 +93,8 @@ public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $datab ); } - // 't' alias is already in use for following query - if ($tableAlias === 't') { - throw new InvalidArgumentException('Table alias "t" is not allowed, please choose another one.'); - } + // do not collide with $tableAlias + $subQueryAlias = $tableAlias === '_t' ? 't' : '_t'; $databaseName = $this->getDatabaseNameSQL($databaseName); @@ -106,9 +104,9 @@ public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $datab $tableAlias.COLUMN_TYPE = 'longtext' AND EXISTS( SELECT * from information_schema.CHECK_CONSTRAINTS t - WHERE t.CONSTRAINT_SCHEMA = $databaseName - AND t.TABLE_NAME = $tableAlias.TABLE_NAME - AND t.CHECK_CLAUSE = CONCAT( + WHERE $subQueryAlias.CONSTRAINT_SCHEMA = $databaseName + AND $subQueryAlias.TABLE_NAME = $tableAlias.TABLE_NAME + AND $subQueryAlias.CHECK_CLAUSE = CONCAT( 'json_valid(`', $tableAlias.COLUMN_NAME, '`)' From 4273f9d8fcb2567bd94fe7d33aaab31edfb74c40 Mon Sep 17 00:00:00 2001 From: dsentker Date: Fri, 26 Jan 2024 16:04:25 +0100 Subject: [PATCH 4/6] Fix missing alias definition --- src/Platforms/MariaDb1043Platform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Platforms/MariaDb1043Platform.php b/src/Platforms/MariaDb1043Platform.php index 9bcd3e538bd..716c780e640 100644 --- a/src/Platforms/MariaDb1043Platform.php +++ b/src/Platforms/MariaDb1043Platform.php @@ -103,7 +103,7 @@ public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $datab IF( $tableAlias.COLUMN_TYPE = 'longtext' AND EXISTS( - SELECT * from information_schema.CHECK_CONSTRAINTS t + SELECT * from information_schema.CHECK_CONSTRAINTS $subQueryAlias WHERE $subQueryAlias.CONSTRAINT_SCHEMA = $databaseName AND $subQueryAlias.TABLE_NAME = $tableAlias.TABLE_NAME AND $subQueryAlias.CHECK_CLAUSE = CONCAT( From 5e495418997cd56d56088b6cdae8a6d912b97f28 Mon Sep 17 00:00:00 2001 From: dsentker Date: Fri, 26 Jan 2024 16:05:00 +0100 Subject: [PATCH 5/6] remove unused import --- src/Platforms/MariaDb1043Platform.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Platforms/MariaDb1043Platform.php b/src/Platforms/MariaDb1043Platform.php index 716c780e640..eafbcb3fbcb 100644 --- a/src/Platforms/MariaDb1043Platform.php +++ b/src/Platforms/MariaDb1043Platform.php @@ -2,7 +2,6 @@ namespace Doctrine\DBAL\Platforms; -use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Types\JsonType; use Doctrine\Deprecations\Deprecation; From 5021fb778eda134a3ac9da80d22b90cccf88d68c Mon Sep 17 00:00:00 2001 From: dsentker Date: Mon, 29 Jan 2024 09:14:49 +0100 Subject: [PATCH 6/6] Simplify name collision handling --- src/Platforms/MariaDb1043Platform.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Platforms/MariaDb1043Platform.php b/src/Platforms/MariaDb1043Platform.php index eafbcb3fbcb..9076b41d437 100644 --- a/src/Platforms/MariaDb1043Platform.php +++ b/src/Platforms/MariaDb1043Platform.php @@ -92,8 +92,7 @@ public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $datab ); } - // do not collide with $tableAlias - $subQueryAlias = $tableAlias === '_t' ? 't' : '_t'; + $subQueryAlias = 'i_' . $tableAlias; $databaseName = $this->getDatabaseNameSQL($databaseName);