Skip to content

Commit 876c45d

Browse files
author
Vincent Hornikx
committed
Added backticks to table names in mysql schema reader. Otherwise indexes cannot be added to tables whose name coïncide with reserved mysql words (e.g. order).
1 parent 496a855 commit 876c45d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 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
@@ -170,7 +170,7 @@ public function readReferences($tableName, $resource)
170170
public function getCreateTableSql($tableName, $resource)
171171
{
172172
$adapter = $this->resourceConnection->getConnection($resource);
173-
$sql = sprintf('SHOW CREATE TABLE %s', $tableName);
173+
$sql = sprintf('SHOW CREATE TABLE `%s`', $tableName);
174174
$stmt = $adapter->query($sql);
175175
return $stmt->fetch(\Zend_Db::FETCH_ASSOC);
176176
}
@@ -186,7 +186,7 @@ public function readConstraints($tableName, $resource)
186186
$constraints = [];
187187
$adapter = $this->resourceConnection->getConnection($resource);
188188
$condition = sprintf('`Non_unique` = 0');
189-
$sql = sprintf('SHOW INDEXES FROM %s WHERE %s', $tableName, $condition);
189+
$sql = sprintf('SHOW INDEXES FROM `%s` WHERE %s', $tableName, $condition);
190190
$stmt = $adapter->query($sql);
191191

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

0 commit comments

Comments
 (0)