Skip to content

Commit

Permalink
Deprecate and replace getColumnTypeSQLSnippets()
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Nov 5, 2023
1 parent b7017b1 commit 3a01396
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
9 changes: 0 additions & 9 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,5 @@ parameters:
# Ignore the possible false return value of db2_num_rows().
- '~^Method Doctrine\\DBAL\\Driver\\IBMDB2\\Connection\:\:exec\(\) should return int but returns int<0, max>\|false\.$~'
- '~^Method Doctrine\\DBAL\\Driver\\IBMDB2\\Result\:\:rowCount\(\) should return int but returns int<0, max>\|false\.$~'

# https://github.com/doctrine/dbal/pull/6202
# TODO: remove in 4.0.0
- '~^Method Doctrine\\DBAL\\Platforms\\AbstractMySQLPlatform\:\:getColumnTypeSQLSnippets\(\) invoked with 2 parameters, 0-1 required\.\z~'
-
message: '~^PHPDoc tag \@param references unknown parameter\: \$databaseName$~'
paths:
- src/Platforms/AbstractMySQLPlatform.php
- src/Platforms/MariaDb1043Platform.php
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
7 changes: 5 additions & 2 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@
-->
<referencedMethod name="Doctrine\DBAL\Connection::getEventManager"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::setEventManager"/>
<!--
See https://github.com/doctrine/dbal/pull/6202
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getColumnTypeSQLSnippets" />

<!-- TODO for PHPUnit 10 -->
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::withConsecutive"/>
Expand Down Expand Up @@ -791,8 +796,6 @@
<file name="src/Schema/SqliteSchemaManager.php"/>
<!-- See https://github.com/doctrine/dbal/pull/3498 -->
<file name="tests/Platforms/AbstractMySQLPlatformTestCase.php"/>
<!-- See https://github.com/doctrine/dbal/pull/6202 -->
<file name="src/Schema/MySQLSchemaManager.php"/>
</errorLevel>
</TooManyArguments>
<TypeDoesNotContainType>
Expand Down
25 changes: 21 additions & 4 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,34 @@ public function getListTableColumnsSQL($table, $database = null)
}

/**
* @deprecated Use {@see getColumnTypeSQLSnippet()} instead.
*
* The SQL snippets required to elucidate a column type
*
* Returns an array of the form [column type SELECT snippet, additional JOIN statement snippet]
*
* @param string|null $databaseName
*
* @return array{string, string}
*/
public function getColumnTypeSQLSnippets(string $tableAlias = 'c' /* , ?string $databaseName = null*/): array
public function getColumnTypeSQLSnippets(string $tableAlias = 'c'): array
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6202',
'AbstractMySQLPlatform::getColumnTypeSQLSnippets() is deprecated. '
. 'Use AbstractMySQLPlatform::getColumnTypeSQLSnippet() instead.',
);

return [$this->getColumnTypeSQLSnippet(...func_get_args()), ''];
}

/**
* The SQL snippet required to elucidate a column type
*
* Returns a column type SELECT snippet string
*/
public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $databaseName = null): string
{
return [$tableAlias . '.COLUMN_TYPE', ''];
return $tableAlias . '.COLUMN_TYPE';
}

/** @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon. */
Expand Down
15 changes: 4 additions & 11 deletions src/Platforms/MariaDb1043Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getJsonTypeDeclarationSQL(array $column): string
*/
public function getListTableColumnsSQL($table, $database = null): string
{
// @todo 4.0 - call getColumnTypeSQLSnippet() instead
[$columnTypeSQL, $joinCheckConstraintSQL] = $this->getColumnTypeSQLSnippets('c', $database);

return sprintf(
Expand Down Expand Up @@ -75,23 +76,17 @@ public function getListTableColumnsSQL($table, $database = null): string
* as JSON where it was originally specified as such instead of LONGTEXT.
*
* The CHECK constraints are stored in information_schema.CHECK_CONSTRAINTS so query that table.
*
* @param string|null $databaseName
*
* @return array{string, string}
*/
public function getColumnTypeSQLSnippets(string $tableAlias = 'c' /* , ?string $databaseName = null*/): array
public function getColumnTypeSQLSnippet(string $tableAlias = 'c', ?string $databaseName = null): string
{
$databaseName = func_num_args() > 1 ? func_get_arg(1) : null;

if ($this->getJsonTypeDeclarationSQL([]) !== 'JSON') {
return parent::getColumnTypeSQLSnippets($tableAlias, $databaseName);
return parent::getColumnTypeSQLSnippet($tableAlias, $databaseName);
}

$databaseName = $this->getDatabaseNameSQL($databaseName);

// The check for `CONSTRAINT_SCHEMA = $databaseName` is mandatory here to prevent performance issues
$columnTypeSQL = <<<SQL
return <<<SQL
IF(
$tableAlias.COLUMN_TYPE = 'longtext'
AND EXISTS(
Expand All @@ -108,8 +103,6 @@ public function getColumnTypeSQLSnippets(string $tableAlias = 'c' /* , ?string $
$tableAlias.COLUMN_TYPE
)
SQL;

return [$columnTypeSQL, ''];
}

/** {@inheritDoc} */
Expand Down
1 change: 1 addition & 0 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ protected function selectTableNames(string $databaseName): Result

protected function selectTableColumns(string $databaseName, ?string $tableName = null): Result
{
// @todo 4.0 - call getColumnTypeSQLSnippet() instead
[$columnTypeSQL, $joinCheckConstraintSQL] = $this->_platform->getColumnTypeSQLSnippets('c', $databaseName);

$sql = 'SELECT';
Expand Down

0 comments on commit 3a01396

Please sign in to comment.