Skip to content

Commit

Permalink
Avoid ambigous TABLE_NAME in query (#6275)
Browse files Browse the repository at this point in the history
<!-- Fill in the relevant information below to help triage your pull
request. -->

|      Q       |   A
|------------- | -----------
| Type         | bug
| Fixed issues | #6274 

#### Summary

The current produced query leads to an ambigous column reference as
described in the linked issue.
  • Loading branch information
dsentker authored Feb 1, 2024
1 parent f78899c commit a9cd978
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Platforms/MariaDb1043Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,19 @@ public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $datab
);
}

$subQueryAlias = 'i_' . $tableAlias;

$databaseName = $this->getDatabaseNameSQL($databaseName);

// The check for `CONSTRAINT_SCHEMA = $databaseName` is mandatory here to prevent performance issues
return <<<SQL
IF(
$tableAlias.COLUMN_TYPE = 'longtext'
AND EXISTS(
SELECT * from information_schema.CHECK_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = $databaseName
AND TABLE_NAME = $tableAlias.TABLE_NAME
AND CHECK_CLAUSE = CONCAT(
SELECT * from information_schema.CHECK_CONSTRAINTS $subQueryAlias
WHERE $subQueryAlias.CONSTRAINT_SCHEMA = $databaseName
AND $subQueryAlias.TABLE_NAME = $tableAlias.TABLE_NAME
AND $subQueryAlias.CHECK_CLAUSE = CONCAT(
'json_valid(`',
$tableAlias.COLUMN_NAME,
'`)'
Expand Down

0 comments on commit a9cd978

Please sign in to comment.