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

Address quoteIdentifier() deprecation #11811

Merged
merged 1 commit into from
Jan 28, 2025
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
14 changes: 7 additions & 7 deletions src/Mapping/DefaultQuoteStrategy.php
Copy link
Member Author

@greg0ire greg0ire Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests pass, but I'm not sure if e.g. $tableName really is always going to be a single identifier here, and what to do if it isn't. That being said, if quoted is set, then… maybe we should treat everything as a single identifier?

Copy link
Member

@morozov morozov Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To preserve the existing behavior, table names should be split into schema name and unqualified name and quoted individually (basically, what quoteIdentifier() would do). Even if the identifier is quoted (e.g. "inventory.products"), AbstractAsset::_setName() in DBAL 4 would parse it and consider inventory to be the schema name.

I guess it's better to add or find an existing test that covers this case (e.g. create a schema in Postgres and and use a qualified table name on an entity).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After attempting what you suggested, I now believe that name will never contain the schema part, which means such a test cannot be written.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came to the opposite conclusion in #11812 (comment). But maybe we're talking about the same thing.

My understanding is that if the name contains a dot, the part before the dot will be considered the schema name.

In any event, quoting all values as "single identifier" looks right to me.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DefaultQuoteStrategy implements QuoteStrategy
public function getColumnName(string $fieldName, ClassMetadata $class, AbstractPlatform $platform): string
{
return isset($class->fieldMappings[$fieldName]->quoted)
? $platform->quoteIdentifier($class->fieldMappings[$fieldName]->columnName)
? $platform->quoteSingleIdentifier($class->fieldMappings[$fieldName]->columnName)
: $class->fieldMappings[$fieldName]->columnName;
}

Expand All @@ -42,7 +42,7 @@ public function getTableName(ClassMetadata $class, AbstractPlatform $platform):
}

return isset($class->table['quoted'])
? $platform->quoteIdentifier($tableName)
? $platform->quoteSingleIdentifier($tableName)
: $tableName;
}

Expand All @@ -52,14 +52,14 @@ public function getTableName(ClassMetadata $class, AbstractPlatform $platform):
public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform): string
{
return isset($definition['quoted'])
? $platform->quoteIdentifier($definition['sequenceName'])
? $platform->quoteSingleIdentifier($definition['sequenceName'])
: $definition['sequenceName'];
}

public function getJoinColumnName(JoinColumnMapping $joinColumn, ClassMetadata $class, AbstractPlatform $platform): string
{
return isset($joinColumn->quoted)
? $platform->quoteIdentifier($joinColumn->name)
? $platform->quoteSingleIdentifier($joinColumn->name)
: $joinColumn->name;
}

Expand All @@ -69,7 +69,7 @@ public function getReferencedJoinColumnName(
AbstractPlatform $platform,
): string {
return isset($joinColumn->quoted)
? $platform->quoteIdentifier($joinColumn->referencedColumnName)
? $platform->quoteSingleIdentifier($joinColumn->referencedColumnName)
: $joinColumn->referencedColumnName;
}

Expand All @@ -87,7 +87,7 @@ public function getJoinTableName(
$tableName = $association->joinTable->name;

if (isset($association->joinTable->quoted)) {
$tableName = $platform->quoteIdentifier($tableName);
$tableName = $platform->quoteSingleIdentifier($tableName);
}

return $schema . $tableName;
Expand All @@ -113,7 +113,7 @@ public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform
$joinColumns = $assoc->joinColumns;
$assocQuotedColumnNames = array_map(
static fn (JoinColumnMapping $joinColumn) => isset($joinColumn->quoted)
? $platform->quoteIdentifier($joinColumn->name)
? $platform->quoteSingleIdentifier($joinColumn->name)
: $joinColumn->name,
$joinColumns,
);
Expand Down
10 changes: 5 additions & 5 deletions tests/Tests/ORM/Functional/Ticket/DDC832Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public function tearDown(): void
$platform = $this->_em->getConnection()->getDatabasePlatform();

$sm = $this->createSchemaManager();
$sm->dropTable($platform->quoteIdentifier('TREE_INDEX'));
$sm->dropTable($platform->quoteIdentifier('INDEX'));
$sm->dropTable($platform->quoteIdentifier('LIKE'));
$sm->dropTable($platform->quoteSingleIdentifier('TREE_INDEX'));
$sm->dropTable($platform->quoteSingleIdentifier('INDEX'));
$sm->dropTable($platform->quoteSingleIdentifier('LIKE'));

// DBAL 3
if ($platform instanceof PostgreSQLPlatform && method_exists($platform, 'getIdentitySequenceName')) {
$sm->dropSequence($platform->quoteIdentifier('INDEX_id_seq'));
$sm->dropSequence($platform->quoteIdentifier('LIKE_id_seq'));
$sm->dropSequence($platform->quoteSingleIdentifier('INDEX_id_seq'));
$sm->dropSequence($platform->quoteSingleIdentifier('LIKE_id_seq'));
}
}

Expand Down
18 changes: 9 additions & 9 deletions tests/Tests/OrmFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ protected function tearDown(): void
}

if (isset($this->_usedModelSets['directorytree'])) {
$conn->executeStatement('DELETE FROM ' . $platform->quoteIdentifier('file'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteSingleIdentifier('file'));
// MySQL doesn't know deferred deletions therefore only executing the second query gives errors.
$conn->executeStatement('DELETE FROM Directory WHERE parentDirectory_id IS NOT NULL');
$conn->executeStatement('DELETE FROM Directory');
Expand Down Expand Up @@ -707,17 +707,17 @@ protected function tearDown(): void
$conn->executeStatement(
sprintf(
'UPDATE %s SET %s = NULL',
$platform->quoteIdentifier('quote-address'),
$platform->quoteIdentifier('user-id'),
$platform->quoteSingleIdentifier('quote-address'),
$platform->quoteSingleIdentifier('user-id'),
),
);

$conn->executeStatement('DELETE FROM ' . $platform->quoteIdentifier('quote-users-groups'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteIdentifier('quote-group'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteIdentifier('quote-phone'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteIdentifier('quote-user'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteIdentifier('quote-address'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteIdentifier('quote-city'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteSingleIdentifier('quote-users-groups'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteSingleIdentifier('quote-group'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteSingleIdentifier('quote-phone'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteSingleIdentifier('quote-user'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteSingleIdentifier('quote-address'));
$conn->executeStatement('DELETE FROM ' . $platform->quoteSingleIdentifier('quote-city'));
}

if (isset($this->_usedModelSets['vct_onetoone'])) {
Expand Down