Fix #18365 : Move quoting of table names to upper level to function getSchemaMetadata() in MSSQL driver to get clean names from schema

This commit is contained in:
Valerii Gorbachev
2020-12-23 12:40:05 +03:00
committed by GitHub
parent b8f4958092
commit 82400fc33e
2 changed files with 26 additions and 12 deletions

View File

@ -19,6 +19,7 @@ Yii Framework 2 Change Log
- Bug #18435: Change the check order whether an object is an implementation of `Arrayable` or `JsonSerializable` in `\yii\base\ArrayableTrait::toArray()` and `\yii\rest\Serializer::serialize()` (spell6inder)
- Bug #18442: Fix calls with array access to strings (bizley)
- Bug #18395: Fix regression in `yii\helpers\BaseArrayHelper::filter()` (allowing filtering arrays with numeric keys) (bizley)
- Bug #18365 : Move quoting of table names to upper level to function `getSchemaMetadata()` in MSSQL driver to get clean names from schema (darkdef)
2.0.39.3 November 23, 2020

View File

@ -180,12 +180,7 @@ FROM [INFORMATION_SCHEMA].[TABLES] AS [t]
WHERE [t].[table_schema] = :schema AND [t].[table_type] IN ('BASE TABLE', 'VIEW')
ORDER BY [t].[table_name]
SQL;
$tables = $this->db->createCommand($sql, [':schema' => $schema])->queryColumn();
$tables = array_map(static function ($item) {
return '[' . $item . ']';
}, $tables);
return $tables;
return $this->db->createCommand($sql, [':schema' => $schema])->queryColumn();
}
/**
@ -204,6 +199,29 @@ SQL;
return null;
}
/**
* {@inheritdoc}
*/
protected function getSchemaMetadata($schema, $type, $refresh)
{
$metadata = [];
$methodName = 'getTable' . ucfirst($type);
$tableNames = array_map(function ($table) {
return $this->quoteSimpleTableName($table);
}, $this->getTableNames($schema, $refresh));
foreach ($tableNames as $name) {
if ($schema !== '') {
$name = $schema . '.' . $name;
}
$tableMetadata = $this->$methodName($name, $refresh);
if ($tableMetadata !== null) {
$metadata[] = $tableMetadata;
}
}
return $metadata;
}
/**
* {@inheritdoc}
*/
@ -597,12 +615,7 @@ WHERE [t].[table_schema] = :schema AND [t].[table_type] = 'VIEW'
ORDER BY [t].[table_name]
SQL;
$views = $this->db->createCommand($sql, [':schema' => $schema])->queryColumn();
$views = array_map(static function ($item) {
return '[' . $item . ']';
}, $views);
return $views;
return $this->db->createCommand($sql, [':schema' => $schema])->queryColumn();
}
/**