Skip to content

Commit 2c9c056

Browse files
ENGCOM-6204: Added backticks to table names in mysql schema reader. #25354
- Merge Pull Request #25354 from vincenthornikx/magento2:2.3-develop - Merged commits: 1. 876c45d 2. 01621ca
2 parents 54742d5 + 01621ca commit 2c9c056

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/DbSchemaReader.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function readIndexes($tableName, $resource)
126126
$indexes = [];
127127
$adapter = $this->resourceConnection->getConnection($resource);
128128
$condition = sprintf('`Non_unique` = 1');
129-
$sql = sprintf('SHOW INDEXES FROM %s WHERE %s', $tableName, $condition);
129+
$sql = sprintf('SHOW INDEXES FROM `%s` WHERE %s', $tableName, $condition);
130130
$stmt = $adapter->query($sql);
131131

132132
// Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection
@@ -147,9 +147,10 @@ public function readIndexes($tableName, $resource)
147147
}
148148

149149
/**
150+
* Read references (foreign keys) from Magento tables.
151+
*
150152
* As MySQL has bug and do not show foreign keys during DESCRIBE and other directives required
151-
* to take it from SHOW CREATE TABLE ...
152-
* command
153+
* to take it from "SHOW CREATE TABLE ..." command.
153154
*
154155
* @inheritdoc
155156
*/
@@ -170,13 +171,14 @@ public function readReferences($tableName, $resource)
170171
public function getCreateTableSql($tableName, $resource)
171172
{
172173
$adapter = $this->resourceConnection->getConnection($resource);
173-
$sql = sprintf('SHOW CREATE TABLE %s', $tableName);
174+
$sql = sprintf('SHOW CREATE TABLE `%s`', $tableName);
174175
$stmt = $adapter->query($sql);
175176
return $stmt->fetch(\Zend_Db::FETCH_ASSOC);
176177
}
177178

178179
/**
179180
* Reading DB constraints.
181+
*
180182
* Primary and unique constraints are always non_unique=0.
181183
*
182184
* @inheritdoc
@@ -186,7 +188,7 @@ public function readConstraints($tableName, $resource)
186188
$constraints = [];
187189
$adapter = $this->resourceConnection->getConnection($resource);
188190
$condition = sprintf('`Non_unique` = 0');
189-
$sql = sprintf('SHOW INDEXES FROM %s WHERE %s', $tableName, $condition);
191+
$sql = sprintf('SHOW INDEXES FROM `%s` WHERE %s', $tableName, $condition);
190192
$stmt = $adapter->query($sql);
191193

192194
// Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection

0 commit comments

Comments
 (0)