diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index e0f9835749..c1b658850f 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -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 diff --git a/framework/db/mssql/Schema.php b/framework/db/mssql/Schema.php index 1ffad32a92..34f9976dae 100644 --- a/framework/db/mssql/Schema.php +++ b/framework/db/mssql/Schema.php @@ -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(); } /**