diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 32c8645e4e3..9e77adabd44 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -1580,26 +1580,6 @@ public function getWriteLockSQL() return $this->getForUpdateSQL(); } - /** - * Returns the SQL snippet to drop an existing database. - * - * @param string $name The name of the database that should be dropped. - * - * @return string - */ - public function getDropDatabaseSQL($name) - { - return 'DROP DATABASE ' . $name; - } - - /** - * Returns the SQL snippet to drop a schema. - */ - public function getDropSchemaSQL(string $schemaName): string - { - return 'DROP SCHEMA ' . $schemaName; - } - /** * Returns the SQL snippet to drop an existing table. * @@ -1967,6 +1947,28 @@ public function getAlterSequenceSQL(Sequence $sequence) throw Exception::notSupported(__METHOD__); } + /** + * Returns the SQL snippet to drop an existing sequence. + * + * @param Sequence|string $sequence + * + * @return string + * + * @throws Exception If not supported on this platform. + */ + public function getDropSequenceSQL($sequence) + { + if (! $this->supportsSequences()) { + throw Exception::notSupported(__METHOD__); + } + + if ($sequence instanceof Sequence) { + $sequence = $sequence->getQuotedName($this); + } + + return 'DROP SEQUENCE ' . $sequence; + } + /** * Returns the SQL to create a constraint on a table on this platform. * @@ -2094,7 +2096,25 @@ public function getCreatePrimaryKeySQL(Index $index, $table) */ public function getCreateSchemaSQL($schemaName) { - throw Exception::notSupported(__METHOD__); + if (! $this->supportsSchemas()) { + throw Exception::notSupported(__METHOD__); + } + + return 'CREATE SCHEMA ' . $schemaName; + } + + /** + * Returns the SQL snippet to drop a schema. + * + * @throws Exception If not supported on this platform. + */ + public function getDropSchemaSQL(string $schemaName): string + { + if (! $this->supportsSchemas()) { + throw Exception::notSupported(__METHOD__); + } + + return 'DROP SCHEMA ' . $schemaName; } /** @@ -3125,64 +3145,66 @@ public function getListTableForeignKeysSQL($table) * @param string $sql * * @return string - * - * @throws Exception If not supported on this platform. */ public function getCreateViewSQL($name, $sql) { - throw Exception::notSupported(__METHOD__); + return 'CREATE VIEW ' . $name . ' AS ' . $sql; } /** * @param string $name * * @return string - * - * @throws Exception If not supported on this platform. */ public function getDropViewSQL($name) { - throw Exception::notSupported(__METHOD__); + return 'DROP VIEW ' . $name; } /** - * Returns the SQL snippet to drop an existing sequence. - * - * @param Sequence|string $sequence + * @param string $sequence * * @return string * * @throws Exception If not supported on this platform. */ - public function getDropSequenceSQL($sequence) + public function getSequenceNextValSQL($sequence) { throw Exception::notSupported(__METHOD__); } /** - * @param string $sequence + * Returns the SQL to create a new database. + * + * @param string $name The name of the database that should be created. * * @return string * * @throws Exception If not supported on this platform. */ - public function getSequenceNextValSQL($sequence) + public function getCreateDatabaseSQL($name) { - throw Exception::notSupported(__METHOD__); + if (! $this->supportsCreateDropDatabase()) { + throw Exception::notSupported(__METHOD__); + } + + return 'CREATE DATABASE ' . $name; } /** - * Returns the SQL to create a new database. + * Returns the SQL snippet to drop an existing database. * - * @param string $name The name of the database that should be created. + * @param string $name The name of the database that should be dropped. * * @return string - * - * @throws Exception If not supported on this platform. */ - public function getCreateDatabaseSQL($name) + public function getDropDatabaseSQL($name) { - throw Exception::notSupported(__METHOD__); + if (! $this->supportsCreateDropDatabase()) { + throw Exception::notSupported(__METHOD__); + } + + return 'DROP DATABASE ' . $name; } /** diff --git a/src/Platforms/DB2Platform.php b/src/Platforms/DB2Platform.php index 6e984f5bdaf..c1ffa3c22e5 100644 --- a/src/Platforms/DB2Platform.php +++ b/src/Platforms/DB2Platform.php @@ -402,38 +402,6 @@ public function getListTableForeignKeysSQL($table) ORDER BY fkcol.COLSEQ ASC'; } - /** - * {@inheritDoc} - */ - public function getCreateViewSQL($name, $sql) - { - return 'CREATE VIEW ' . $name . ' AS ' . $sql; - } - - /** - * {@inheritDoc} - */ - public function getDropViewSQL($name) - { - return 'DROP VIEW ' . $name; - } - - /** - * {@inheritDoc} - */ - public function getCreateDatabaseSQL($name) - { - return 'CREATE DATABASE ' . $name; - } - - /** - * {@inheritDoc} - */ - public function getDropDatabaseSQL($name) - { - return 'DROP DATABASE ' . $name; - } - /** * {@inheritDoc} */ diff --git a/src/Platforms/MySQLPlatform.php b/src/Platforms/MySQLPlatform.php index dd600720867..2c98d7b35db 100644 --- a/src/Platforms/MySQLPlatform.php +++ b/src/Platforms/MySQLPlatform.php @@ -198,22 +198,6 @@ public function getListTableForeignKeysSQL($table, $database = null) . ' AND k.`REFERENCED_COLUMN_NAME` is not NULL'; } - /** - * {@inheritDoc} - */ - public function getCreateViewSQL($name, $sql) - { - return 'CREATE VIEW ' . $name . ' AS ' . $sql; - } - - /** - * {@inheritDoc} - */ - public function getDropViewSQL($name) - { - return 'DROP VIEW ' . $name; - } - /** * {@inheritDoc} */ @@ -385,22 +369,6 @@ public function getListTableMetadataSQL(string $table, ?string $database = null) ); } - /** - * {@inheritDoc} - */ - public function getCreateDatabaseSQL($name) - { - return 'CREATE DATABASE ' . $name; - } - - /** - * {@inheritDoc} - */ - public function getDropDatabaseSQL($name) - { - return 'DROP DATABASE ' . $name; - } - /** * {@inheritDoc} */ diff --git a/src/Platforms/OraclePlatform.php b/src/Platforms/OraclePlatform.php index 7a0d82e0b2f..0d9cabd0ab6 100644 --- a/src/Platforms/OraclePlatform.php +++ b/src/Platforms/OraclePlatform.php @@ -475,22 +475,6 @@ public function getListViewsSQL($database) return 'SELECT view_name, text FROM sys.user_views'; } - /** - * {@inheritDoc} - */ - public function getCreateViewSQL($name, $sql) - { - return 'CREATE VIEW ' . $name . ' AS ' . $sql; - } - - /** - * {@inheritDoc} - */ - public function getDropViewSQL($name) - { - return 'DROP VIEW ' . $name; - } - /** * @internal The method should be only used from within the OraclePlatform class hierarchy. * @@ -724,18 +708,6 @@ public function getListTableColumnsSQL($table, $database = null) ); } - /** - * {@inheritDoc} - */ - public function getDropSequenceSQL($sequence) - { - if ($sequence instanceof Sequence) { - $sequence = $sequence->getQuotedName($this); - } - - return 'DROP SEQUENCE ' . $sequence; - } - /** * {@inheritDoc} */ @@ -797,6 +769,14 @@ public function getForeignKeyReferentialActionSQL($action) } } + /** + * {@inheritDoc} + */ + public function getCreateDatabaseSQL($name) + { + return 'CREATE USER ' . $name; + } + /** * {@inheritDoc} */ diff --git a/src/Platforms/PostgreSQLPlatform.php b/src/Platforms/PostgreSQLPlatform.php index 4ec87c856d6..12219231a22 100644 --- a/src/Platforms/PostgreSQLPlatform.php +++ b/src/Platforms/PostgreSQLPlatform.php @@ -312,22 +312,6 @@ public function getListTableForeignKeysSQL($table, $database = null) AND r.contype = 'f'"; } - /** - * {@inheritDoc} - */ - public function getCreateViewSQL($name, $sql) - { - return 'CREATE VIEW ' . $name . ' AS ' . $sql; - } - - /** - * {@inheritDoc} - */ - public function getDropViewSQL($name) - { - return 'DROP VIEW ' . $name; - } - /** * {@inheritDoc} */ @@ -441,14 +425,6 @@ public function getListTableColumnsSQL($table, $database = null) ORDER BY a.attnum'; } - /** - * {@inheritDoc} - */ - public function getCreateDatabaseSQL($name) - { - return 'CREATE DATABASE ' . $name; - } - /** * {@inheritDoc} */ @@ -748,19 +724,7 @@ private function getSequenceCacheSQL(Sequence $sequence) */ public function getDropSequenceSQL($sequence) { - if ($sequence instanceof Sequence) { - $sequence = $sequence->getQuotedName($this); - } - - return 'DROP SEQUENCE ' . $sequence . ' CASCADE'; - } - - /** - * {@inheritDoc} - */ - public function getCreateSchemaSQL($schemaName) - { - return 'CREATE SCHEMA ' . $schemaName; + return parent::getDropSequenceSQL($sequence) . ' CASCADE'; } /** diff --git a/src/Platforms/SQLServerPlatform.php b/src/Platforms/SQLServerPlatform.php index f772b0ba7d6..65193d42839 100644 --- a/src/Platforms/SQLServerPlatform.php +++ b/src/Platforms/SQLServerPlatform.php @@ -167,18 +167,6 @@ public function getCreateSequenceSQL(Sequence $sequence): string ' MINVALUE ' . $sequence->getInitialValue(); } - /** - * {@inheritdoc} - */ - public function getDropSequenceSQL($sequence): string - { - if ($sequence instanceof Sequence) { - $sequence = $sequence->getQuotedName($this); - } - - return 'DROP SEQUENCE ' . $sequence; - } - /** * {@inheritdoc} */ @@ -210,38 +198,6 @@ public function hasNativeGuidType() return true; } - /** - * {@inheritDoc} - */ - public function getCreateDatabaseSQL($name) - { - return 'CREATE DATABASE ' . $name; - } - - /** - * {@inheritDoc} - */ - public function getDropDatabaseSQL($name) - { - return 'DROP DATABASE ' . $name; - } - - /** - * {@inheritDoc} - */ - public function supportsCreateDropDatabase() - { - return true; - } - - /** - * {@inheritDoc} - */ - public function getCreateSchemaSQL($schemaName) - { - return 'CREATE SCHEMA ' . $schemaName; - } - /** * {@inheritDoc} */ @@ -1032,14 +988,6 @@ public function getListTableIndexesSQL($table, $database = null) ORDER BY idx.index_id ASC, idxcol.key_ordinal ASC'; } - /** - * {@inheritDoc} - */ - public function getCreateViewSQL($name, $sql) - { - return 'CREATE VIEW ' . $name . ' AS ' . $sql; - } - /** * {@inheritDoc} */ @@ -1071,14 +1019,6 @@ private function getTableWhereClause($table, $schemaColumn, $tableColumn) return sprintf('(%s = %s AND %s = %s)', $tableColumn, $table, $schemaColumn, $schema); } - /** - * {@inheritDoc} - */ - public function getDropViewSQL($name) - { - return 'DROP VIEW ' . $name; - } - /** * {@inheritDoc} */ diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index d1aa741b51e..b4709721eb1 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -503,22 +503,6 @@ public function getListViewsSQL($database) return "SELECT name, sql FROM sqlite_master WHERE type='view' AND sql NOT NULL"; } - /** - * {@inheritDoc} - */ - public function getCreateViewSQL($name, $sql) - { - return 'CREATE VIEW ' . $name . ' AS ' . $sql; - } - - /** - * {@inheritDoc} - */ - public function getDropViewSQL($name) - { - return 'DROP VIEW ' . $name; - } - /** * {@inheritDoc} */ diff --git a/src/Schema/OracleSchemaManager.php b/src/Schema/OracleSchemaManager.php index 58f98972781..63209c93622 100644 --- a/src/Schema/OracleSchemaManager.php +++ b/src/Schema/OracleSchemaManager.php @@ -258,7 +258,7 @@ protected function _getPortableDatabaseDefinition($database) */ public function createDatabase($database) { - $statement = 'CREATE USER ' . $database; + $statement = $this->_platform->getCreateDatabaseSQL($database); $params = $this->_conn->getParams(); diff --git a/tests/Platforms/DB2PlatformTest.php b/tests/Platforms/DB2PlatformTest.php index fe07ca6f6b3..5cd8f75d57e 100644 --- a/tests/Platforms/DB2PlatformTest.php +++ b/tests/Platforms/DB2PlatformTest.php @@ -347,8 +347,6 @@ public function getIsCommentedDoctrineType(): array public function testGeneratesDDLSnippets(): void { - self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); - self::assertEquals('DROP DATABASE foobar', $this->platform->getDropDatabaseSQL('foobar')); self::assertEquals('DECLARE GLOBAL TEMPORARY TABLE', $this->platform->getCreateTemporaryTableSnippetSQL()); self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->platform->getTruncateTableSQL('foobar')); self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->platform->getTruncateTableSQL('foobar'), true); diff --git a/tests/Platforms/OraclePlatformTest.php b/tests/Platforms/OraclePlatformTest.php index 54358854654..3ea844df881 100644 --- a/tests/Platforms/OraclePlatformTest.php +++ b/tests/Platforms/OraclePlatformTest.php @@ -149,14 +149,12 @@ public function testGeneratesTransactionsCommands(): void ); } - public function testCreateDatabaseThrowsException(): void + public function testCreateDatabaseSQL(): void { - $this->expectException(Exception::class); - - self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); + self::assertEquals('CREATE USER foobar', $this->platform->getCreateDatabaseSQL('foobar')); } - public function testDropDatabaseThrowsException(): void + public function testDropDatabaseSQL(): void { self::assertEquals('DROP USER foobar CASCADE', $this->platform->getDropDatabaseSQL('foobar')); }