Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare abstract methods in AbstractPlatform as abstract #4723

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ awareness about deprecated code.

# Upgrade to 4.0

## Abstract methods in the `AbstractPlatform` class have been declared as `abstract`.

The following abstract methods in the `AbstractPlatform` class have been declared as `abstract`:

- `getListTablesSQL()`,
- `getAlterTableSQL()`,
- `getListTableColumnsSQL()`,
- `getListTableIndexesSQL()`,
- `getListTableForeignKeysSQL()`,
- `getCreateViewSQL()`,
- `getListViewsSQL()`,
- `getDropViewSQL()`,
- `getDateArithmeticIntervalExpression()`,
- `getDateDiffExpression()`,
- `getTimeTypeDeclarationSQL()`,
- `getDateTimeTypeDeclarationSQL()`,
- `getLocateExpression()`,
- `getSetTransactionIsolationSQL()`.

Every non-abstract platform class must implement them in order to satisfy the API.

## `Connection::lastInsertId()` throws an exception when there's no identity value.

Instead of returning an empty value, `Connection::lastInsertId()` throws an exception when there's no identity value.
Expand Down
109 changes: 16 additions & 93 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,8 @@ public function getLowerExpression(string $string): string
* @param string $substring SQL expression producing the substring to locate.
* @param string|null $start SQL expression producing the position to start at.
* Defaults to the beginning of the string.
*
* @throws Exception If not supported on this platform.
*/
public function getLocateExpression(string $string, string $substring, ?string $start = null): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getLocateExpression(string $string, string $substring, ?string $start = null): string;

/**
* Returns the SQL snippet to get the current system date.
Expand Down Expand Up @@ -859,13 +854,8 @@ public function getCosExpression(string $number): string
* Returns the SQL to calculate the difference in days between the two passed dates.
*
* Computes diff = date1 - date2.
*
* @throws Exception If not supported on this platform.
*/
public function getDateDiffExpression(string $date1, string $date2): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getDateDiffExpression(string $date1, string $date2): string;

/**
* Returns the SQL to add the number of given seconds to a date.
Expand Down Expand Up @@ -1084,17 +1074,13 @@ public function getDateSubYearsExpression(string $date, string $years): string
* into the date.
* @param string $unit The unit of the interval that shall be calculated into the date.
* One of the DATE_INTERVAL_UNIT_* constants.
*
* @throws Exception If not supported on this platform.
*/
protected function getDateArithmeticIntervalExpression(
abstract protected function getDateArithmeticIntervalExpression(
string $date,
string $operator,
string $interval,
string $unit
): string {
throw NotSupported::new(__METHOD__);
}
): string;

/**
* Generates the SQL expression which represents the given date interval multiplied by a number
Expand Down Expand Up @@ -1717,10 +1703,7 @@ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
*
* @throws Exception If not supported on this platform.
*/
public function getAlterTableSQL(TableDiff $diff): array
{
throw NotSupported::new(__METHOD__);
}
abstract public function getAlterTableSQL(TableDiff $diff): array;

/**
* @param mixed[] $columnSql
Expand Down Expand Up @@ -2522,21 +2505,9 @@ public function getListTableConstraintsSQL(string $table): string
throw NotSupported::new(__METHOD__);
}

/**
* @throws Exception If not supported on this platform.
*/
public function getListTableColumnsSQL(string $table, ?string $database = null): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getListTableColumnsSQL(string $table, ?string $database = null): string;

/**
* @throws Exception If not supported on this platform.
*/
public function getListTablesSQL(): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getListTablesSQL(): string;

/**
* @throws Exception If not supported on this platform.
Expand All @@ -2548,13 +2519,8 @@ public function getListUsersSQL(): string

/**
* Returns the SQL to list all views of a database or user.
*
* @throws Exception If not supported on this platform.
*/
public function getListViewsSQL(string $database): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getListViewsSQL(string $database): string;

/**
* Returns the list of indexes for the current database.
Expand All @@ -2565,37 +2531,14 @@ public function getListViewsSQL(string $database): string
* Attention: Some platforms only support currentDatabase when they
* are connected with that database. Cross-database information schema
* requests may be impossible.
*
* @throws Exception If not supported on this platform.
*/
public function getListTableIndexesSQL(string $table, ?string $database = null): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getListTableIndexesSQL(string $table, ?string $database = null): string;

/**
* @throws Exception If not supported on this platform.
*/
public function getListTableForeignKeysSQL(string $table, ?string $database = null): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getListTableForeignKeysSQL(string $table, ?string $database = null): string;

/**
* @throws Exception If not supported on this platform.
*/
public function getCreateViewSQL(string $name, string $sql): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getCreateViewSQL(string $name, string $sql): string;

/**
* @throws Exception If not supported on this platform.
*/
public function getDropViewSQL(string $name): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getDropViewSQL(string $name): string;

/**
* Returns the SQL snippet to drop an existing sequence.
Expand Down Expand Up @@ -2631,26 +2574,16 @@ public function getCreateDatabaseSQL(string $name): string

/**
* Returns the SQL to set the transaction isolation level.
*
* @throws Exception If not supported on this platform.
*/
public function getSetTransactionIsolationSQL(int $level): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getSetTransactionIsolationSQL(int $level): string;

/**
* Obtains DBMS specific SQL to be used to create datetime columns in
* statements like CREATE TABLE.
*
* @param mixed[] $column
*
* @throws Exception If not supported on this platform.
*/
public function getDateTimeTypeDeclarationSQL(array $column): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getDateTimeTypeDeclarationSQL(array $column): string;

/**
* Obtains DBMS specific SQL to be used to create datetime with timezone offset columns.
Expand All @@ -2667,26 +2600,16 @@ public function getDateTimeTzTypeDeclarationSQL(array $column): string
* like CREATE TABLE.
*
* @param mixed[] $column
*
* @throws Exception If not supported on this platform.
*/
public function getDateTypeDeclarationSQL(array $column): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getDateTypeDeclarationSQL(array $column): string;

/**
* Obtains DBMS specific SQL to be used to create time columns in statements
* like CREATE TABLE.
*
* @param mixed[] $column
*
* @throws Exception If not supported on this platform.
*/
public function getTimeTypeDeclarationSQL(array $column): string
{
throw NotSupported::new(__METHOD__);
}
abstract public function getTimeTypeDeclarationSQL(array $column): string;

/**
* @param mixed[] $column
Expand Down
11 changes: 11 additions & 0 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\DBAL\Platforms;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\Exception\NotSupported;
use Doctrine\DBAL\Platforms\Keywords\DB2Keywords;
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
Expand Down Expand Up @@ -205,6 +206,16 @@ public function getTruncateTableSQL(string $tableName, bool $cascade = false): s
return 'TRUNCATE ' . $tableIdentifier->getQuotedName($this) . ' IMMEDIATE';
}

/**
* {@inheritdoc}
*
* @throws Exception
*/
public function getSetTransactionIsolationSQL(int $level): string
{
throw NotSupported::new(__METHOD__);
}

/**
* This code fragment is originally from the Zend_Db_Adapter_Db2 class, but has been edited.
*/
Expand Down