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

Remove schema introspection methods from AbstractPlatform #5283

Merged
merged 1 commit into from Feb 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions UPGRADE.md
Expand Up @@ -8,6 +8,15 @@ awareness about deprecated code.

# Upgrade to 4.0

## Removed `AbstractPlatform` schema introspection methods

The following schema introspection methods have been removed:

- `AbstractPlatform::getListTableColumnsSQL()`,
- `AbstractPlatform::getListTableIndexesSQL()`,
- `AbstractPlatform::getListTableForeignKeysSQL()`,
- `AbstractPlatform::getListTableConstraintsSQL()`.

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

The following abstract methods in the `AbstractSchemaManager` class have been declared as `abstract`:
Expand Down
30 changes: 0 additions & 30 deletions psalm.xml.dist
Expand Up @@ -49,37 +49,7 @@
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getListTablesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\DB2Platform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\DB2Platform::getListTableCommentsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\DB2Platform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\DB2Platform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\OraclePlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\OraclePlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\OraclePlatform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\PostgreSQLPlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\PostgreSQLPlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\PostgreSQLPlatform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\PostgreSQLPlatform::getListTableMetadataSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SQLServerPlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SQLServerPlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SQLServerPlatform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SQLServerPlatform::getListTableMetadataSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SqlitePlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SqlitePlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SqlitePlatform::getListTableIndexesSQL"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Platforms\OraclePlatform::getListTableConstraintsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\PostgreSQLPlatform::getListTableConstraintsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SqlitePlatform::getListTableConstraintsSQL"/>
</errorLevel>
</DeprecatedMethod>
<DocblockTypeContradiction>
Expand Down
97 changes: 0 additions & 97 deletions src/Platforms/AbstractMySQLPlatform.php
Expand Up @@ -113,60 +113,11 @@ public function getListDatabasesSQL(): string
return 'SHOW DATABASES';
}

/**
* @deprecated
*/
public function getListTableConstraintsSQL(string $table): string
{
return 'SHOW INDEX FROM ' . $table;
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*
* Two approaches to listing the table indexes. The information_schema is
* preferred, because it doesn't cause problems with SQL keywords such as "order" or "table".
*/
public function getListTableIndexesSQL(string $table, ?string $database = null): string
{
if ($database !== null) {
return 'SELECT NON_UNIQUE AS Non_Unique, INDEX_NAME AS Key_name, COLUMN_NAME AS Column_Name,' .
' SUB_PART AS Sub_Part, INDEX_TYPE AS Index_Type' .
' FROM information_schema.STATISTICS WHERE TABLE_NAME = ' . $this->quoteStringLiteral($table) .
' AND TABLE_SCHEMA = ' . $this->quoteStringLiteral($database) .
' ORDER BY SEQ_IN_INDEX ASC';
}

return 'SHOW INDEX FROM ' . $table;
}

public function getListViewsSQL(string $database): string
{
return 'SELECT * FROM information_schema.VIEWS WHERE TABLE_SCHEMA = ' . $this->quoteStringLiteral($database);
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
public function getListTableForeignKeysSQL(string $table, ?string $database = null): string
{
// The schema name is passed multiple times as a literal in the WHERE clause instead of using a JOIN condition
// in order to avoid performance issues on MySQL older than 8.0 and the corresponding MariaDB versions
// caused by https://bugs.mysql.com/bug.php?id=81347
return 'SELECT k.CONSTRAINT_NAME, k.COLUMN_NAME, k.REFERENCED_TABLE_NAME, ' .
'k.REFERENCED_COLUMN_NAME /*!50116 , c.UPDATE_RULE, c.DELETE_RULE */ ' .
'FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE k /*!50116 ' .
'INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS c ON ' .
'c.CONSTRAINT_NAME = k.CONSTRAINT_NAME AND ' .
'c.TABLE_NAME = k.TABLE_NAME */ ' .
'WHERE k.TABLE_NAME = ' . $this->quoteStringLiteral($table) . ' ' .
'AND k.TABLE_SCHEMA = ' . $this->getDatabaseNameSQL($database) . ' /*!50116 ' .
'AND c.CONSTRAINT_SCHEMA = ' . $this->getDatabaseNameSQL($database) . ' */' .
'ORDER BY k.ORDINAL_POSITION';
}

/**
* Gets the SQL snippet used to declare a CLOB column type.
* TINYTEXT : 2 ^ 8 - 1 = 255
Expand Down Expand Up @@ -261,42 +212,6 @@ public function getListTablesSQL(): string
return "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'";
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
public function getListTableColumnsSQL(string $table, ?string $database = null): string
{
return 'SELECT COLUMN_NAME AS Field, COLUMN_TYPE AS Type, IS_NULLABLE AS `Null`, ' .
'COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS Extra, COLUMN_COMMENT AS Comment, ' .
'CHARACTER_SET_NAME AS CharacterSet, COLLATION_NAME AS Collation ' .
'FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ' . $this->getDatabaseNameSQL($database) . ' ' .
'AND TABLE_NAME = ' . $this->quoteStringLiteral($table) . ' ORDER BY ORDINAL_POSITION';
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
public function getListTableMetadataSQL(string $table, ?string $database = null): string
{
return sprintf(
<<<'SQL'
SELECT t.ENGINE,
t.AUTO_INCREMENT,
t.TABLE_COMMENT,
t.CREATE_OPTIONS,
t.TABLE_COLLATION,
ccsa.CHARACTER_SET_NAME
FROM information_schema.TABLES t
INNER JOIN information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` ccsa
ON ccsa.COLLATION_NAME = t.TABLE_COLLATION
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = %s AND TABLE_NAME = %s
SQL
,
$this->getDatabaseNameSQL($database),
$this->quoteStringLiteral($table)
);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -890,16 +805,4 @@ public function supportsColumnLengthIndexes(): bool
{
return true;
}

/**
* Returns an SQL expression representing the given database name or current database name
*/
private function getDatabaseNameSQL(?string $databaseName): string
{
if ($databaseName === null) {
return $this->getCurrentDatabaseExpression();
}

return $this->quoteStringLiteral($databaseName);
}
}
34 changes: 0 additions & 34 deletions src/Platforms/AbstractPlatform.php
Expand Up @@ -1980,21 +1980,6 @@ public function getListSequencesSQL(string $database): string
throw NotSupported::new(__METHOD__);
}

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

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
abstract public function getListTableColumnsSQL(string $table, ?string $database = null): string;

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
Expand All @@ -2005,25 +1990,6 @@ abstract public function getListTablesSQL(): string;
*/
abstract public function getListViewsSQL(string $database): string;

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* Returns the list of indexes for the current database.
*
* The current database parameter is optional but will always be passed
* when using the SchemaManager API and is the database the given table is in.
*
* Attention: Some platforms only support currentDatabase when they
* are connected with that database. Cross-database information schema
* requests may be impossible.
*/
abstract public function getListTableIndexesSQL(string $table, ?string $database = null): string;

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
abstract public function getListTableForeignKeysSQL(string $table, ?string $database = null): string;

public function getCreateViewSQL(string $name, string $sql): string
{
return 'CREATE VIEW ' . $name . ' AS ' . $sql;
Expand Down
128 changes: 0 additions & 128 deletions src/Platforms/DB2Platform.php
Expand Up @@ -198,60 +198,6 @@ public function getSetTransactionIsolationSQL(int $level): string
throw NotSupported::new(__METHOD__);
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* This code fragment is originally from the Zend_Db_Adapter_Db2 class, but has been edited.
*/
public function getListTableColumnsSQL(string $table, ?string $database = null): string
{
$table = $this->quoteStringLiteral($table);

// We do the funky subquery and join syscat.columns.default this crazy way because
// as of db2 v10, the column is CLOB(64k) and the distinct operator won't allow a CLOB,
// it wants shorter stuff like a varchar.
return "
SELECT
cols.default,
subq.*
FROM (
SELECT DISTINCT
c.tabschema,
c.tabname,
c.colname,
c.colno,
c.typename,
c.codepage,
c.nulls,
c.length,
c.scale,
c.identity,
tc.type AS tabconsttype,
c.remarks AS comment,
k.colseq,
CASE
WHEN c.generated = 'D' THEN 1
ELSE 0
END AS autoincrement
FROM syscat.columns c
LEFT JOIN (syscat.keycoluse k JOIN syscat.tabconst tc
ON (k.tabschema = tc.tabschema
AND k.tabname = tc.tabname
AND tc.type = 'P'))
ON (c.tabschema = k.tabschema
AND c.tabname = k.tabname
AND c.colname = k.colname)
WHERE UPPER(c.tabname) = UPPER(" . $table . ')
ORDER BY c.colno
) subq
JOIN syscat.columns cols
ON subq.tabschema = cols.tabschema
AND subq.tabname = cols.tabname
AND subq.colno = cols.colno
ORDER BY subq.colno
';
}

public function getListTablesSQL(): string
{
return "SELECT NAME FROM SYSIBM.SYSTABLES WHERE TYPE = 'T'";
Expand All @@ -262,64 +208,6 @@ public function getListViewsSQL(string $database): string
return 'SELECT NAME, TEXT FROM SYSIBM.SYSVIEWS';
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
public function getListTableIndexesSQL(string $table, ?string $database = null): string
{
$table = $this->quoteStringLiteral($table);

return "SELECT idx.INDNAME AS key_name,
idxcol.COLNAME AS column_name,
CASE
WHEN idx.UNIQUERULE = 'P' THEN 1
ELSE 0
END AS primary,
CASE
WHEN idx.UNIQUERULE = 'D' THEN 1
ELSE 0
END AS non_unique
FROM SYSCAT.INDEXES AS idx
JOIN SYSCAT.INDEXCOLUSE AS idxcol
ON idx.INDSCHEMA = idxcol.INDSCHEMA AND idx.INDNAME = idxcol.INDNAME
WHERE idx.TABNAME = UPPER(" . $table . ')
ORDER BY idxcol.COLSEQ ASC';
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
public function getListTableForeignKeysSQL(string $table, ?string $database = null): string
{
$table = $this->quoteStringLiteral($table);

return "SELECT fkcol.COLNAME AS local_column,
fk.REFTABNAME AS foreign_table,
pkcol.COLNAME AS foreign_column,
fk.CONSTNAME AS index_name,
CASE
WHEN fk.UPDATERULE = 'R' THEN 'RESTRICT'
ELSE NULL
END AS on_update,
CASE
WHEN fk.DELETERULE = 'C' THEN 'CASCADE'
WHEN fk.DELETERULE = 'N' THEN 'SET NULL'
WHEN fk.DELETERULE = 'R' THEN 'RESTRICT'
ELSE NULL
END AS on_delete
FROM SYSCAT.REFERENCES AS fk
JOIN SYSCAT.KEYCOLUSE AS fkcol
ON fk.CONSTNAME = fkcol.CONSTNAME
AND fk.TABSCHEMA = fkcol.TABSCHEMA
AND fk.TABNAME = fkcol.TABNAME
JOIN SYSCAT.KEYCOLUSE AS pkcol
ON fk.REFKEYNAME = pkcol.CONSTNAME
AND fk.REFTABSCHEMA = pkcol.TABSCHEMA
AND fk.REFTABNAME = pkcol.TABNAME
WHERE fk.TABNAME = UPPER(" . $table . ')
ORDER BY fkcol.COLSEQ ASC';
}

public function supportsCreateDropDatabase(): bool
{
return false;
Expand Down Expand Up @@ -721,20 +609,4 @@ protected function createReservedKeywordsList(): KeywordList
{
return new DB2Keywords();
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
public function getListTableCommentsSQL(string $table): string
{
return sprintf(
<<<'SQL'
SELECT REMARKS
FROM SYSIBM.SYSTABLES
WHERE NAME = UPPER( %s )
SQL
,
$this->quoteStringLiteral($table)
);
}
}