Skip to content

Commit

Permalink
Merge pull request #4807 from morozov/generalize-platform-sql
Browse files Browse the repository at this point in the history
Generalize platform SQL
  • Loading branch information
morozov authored Sep 19, 2021
2 parents ba3e2f7 + f6f7955 commit 14a0824
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 253 deletions.
102 changes: 62 additions & 40 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down
32 changes: 0 additions & 32 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
32 changes: 0 additions & 32 deletions src/Platforms/MySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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}
*/
Expand Down
36 changes: 8 additions & 28 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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}
*/
Expand Down Expand Up @@ -797,6 +769,14 @@ public function getForeignKeyReferentialActionSQL($action)
}
}

/**
* {@inheritDoc}
*/
public function getCreateDatabaseSQL($name)
{
return 'CREATE USER ' . $name;
}

/**
* {@inheritDoc}
*/
Expand Down
38 changes: 1 addition & 37 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down Expand Up @@ -441,14 +425,6 @@ public function getListTableColumnsSQL($table, $database = null)
ORDER BY a.attnum';
}

/**
* {@inheritDoc}
*/
public function getCreateDatabaseSQL($name)
{
return 'CREATE DATABASE ' . $name;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -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';
}

/**
Expand Down
Loading

0 comments on commit 14a0824

Please sign in to comment.