diff --git a/src/Schema/MySQLSchemaManager.php b/src/Schema/MySQLSchemaManager.php index d79fe668b7b..7a1fb629659 100644 --- a/src/Schema/MySQLSchemaManager.php +++ b/src/Schema/MySQLSchemaManager.php @@ -400,27 +400,30 @@ protected function selectTableColumns(string $databaseName, ?string $tableName = $sql = 'SELECT'; if ($tableName === null) { - $sql .= ' TABLE_NAME,'; + $sql .= ' c.TABLE_NAME,'; } $sql .= <<<'SQL' - COLUMN_NAME AS field, - COLUMN_TYPE AS type, - IS_NULLABLE AS `null`, - COLUMN_KEY AS `key`, - COLUMN_DEFAULT AS `default`, - EXTRA, - COLUMN_COMMENT AS comment, - CHARACTER_SET_NAME AS characterset, - COLLATION_NAME AS collation -FROM information_schema.COLUMNS + c.COLUMN_NAME AS field, + c.COLUMN_TYPE AS type, + c.IS_NULLABLE AS `null`, + c.COLUMN_KEY AS `key`, + c.COLUMN_DEFAULT AS `default`, + c.EXTRA, + c.COLUMN_COMMENT AS comment, + c.CHARACTER_SET_NAME AS characterset, + c.COLLATION_NAME AS collation +FROM information_schema.COLUMNS c + INNER JOIN information_schema.TABLES t + ON t.TABLE_SCHEMA = c.TABLE_SCHEMA + AND t.TABLE_NAME = c.TABLE_NAME SQL; - $conditions = ['TABLE_SCHEMA = ?']; + $conditions = ['c.TABLE_SCHEMA = ?', "t.TABLE_TYPE = 'BASE TABLE'"]; $params = [$databaseName]; if ($tableName !== null) { - $conditions[] = 'TABLE_NAME = ?'; + $conditions[] = 't.TABLE_NAME = ?'; $params[] = $tableName; } diff --git a/src/Schema/OracleSchemaManager.php b/src/Schema/OracleSchemaManager.php index 6894f618e9e..8ed7e7ea7f5 100644 --- a/src/Schema/OracleSchemaManager.php +++ b/src/Schema/OracleSchemaManager.php @@ -391,6 +391,9 @@ protected function selectTableColumns(string $databaseName, ?string $tableName = C.NULLABLE, D.COMMENTS FROM ALL_TAB_COLUMNS C + INNER JOIN ALL_TABLES T + ON T.OWNER = C.OWNER + AND T.TABLE_NAME = C.TABLE_NAME LEFT JOIN ALL_COL_COMMENTS D ON D.OWNER = C.OWNER AND D.TABLE_NAME = C.TABLE_NAME diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index 6efb04ea976..249e79bad5d 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -218,21 +218,26 @@ public function testListTables(): void $this->createTestTable('list_tables_test'); $tables = $this->schemaManager->listTables(); - $foundTable = false; - foreach ($tables as $table) { - self::assertInstanceOf(Table::class, $table); - if (strtolower($table->getName()) !== 'list_tables_test') { - continue; - } + $table = $this->findTableByName($tables, 'list_tables_test'); + self::assertNotNull($table); - $foundTable = true; + self::assertTrue($table->hasColumn('id')); + self::assertTrue($table->hasColumn('test')); + self::assertTrue($table->hasColumn('foreign_key_test')); + } - self::assertTrue($table->hasColumn('id')); - self::assertTrue($table->hasColumn('test')); - self::assertTrue($table->hasColumn('foreign_key_test')); - } + public function testListTablesDoesNotIncludeViews(): void + { + $this->createTestTable('test_table_for_view'); + + $sql = 'SELECT * FROM test_table_for_view'; - self::assertTrue($foundTable, "The 'list_tables_test' table has to be found."); + $view = new View('test_view', $sql); + $this->schemaManager->createView($view); + + $tables = $this->schemaManager->listTables(); + $view = $this->findTableByName($tables, 'test_view'); + self::assertNull($view); } /**