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

fix: quote namespace names #6652

Open
wants to merge 1 commit into
base: 4.2.x
Choose a base branch
from

Conversation

nikophil
Copy link
Contributor

@nikophil nikophil commented Dec 18, 2024

Follow up of this discussion

ping @morozov

Comment on lines 1170 to 1172
if (preg_match('/^\d/', $schemaName)) {
return 'CREATE SCHEMA ' . $this->quoteIdentifier($schemaName);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

at first, I was thinking of create an asset Doctrine\DBAL\Schema\Namespace but namespace are handled in a different way than other assets, and it seemed easier to do it like this, but I still can create the new class

@nikophil nikophil force-pushed the fix/quote-namespace-name branch 2 times, most recently from 9c540bc to eaa408a Compare December 18, 2024 14:57
@nikophil nikophil force-pushed the fix/quote-namespace-name branch from eaa408a to f8a686d Compare December 18, 2024 15:04
@nikophil nikophil marked this pull request as ready for review December 18, 2024 15:21
@@ -1162,6 +1167,10 @@ public function getCreateSchemaSQL(string $schemaName): string
throw NotSupported::new(__METHOD__);
}

if (preg_match('/^\d/', $schemaName) > 0) {
Copy link
Member

@morozov morozov Dec 26, 2024

Choose a reason for hiding this comment

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

Even though it's not consistently documented, all get[...]SQL() methods of this class accept SQL fragments as string parameters and just concatenate them with other fragments of SQL. Treating the schema name as a literal is against this implied contract. It's the caller of the method who should quote the names that need to be quoted.

Depending on how you manage your schema via DBAL, you may try explicitly quoting names in the schema definition similar to this:

public function testQuotedTableNameRemainsQuotedInSchema(): void
{
$table = new Table('"tester"');
$table->addColumn('"id"', Types::INTEGER);
$table->addColumn('"name"', Types::STRING, ['length' => 32]);

This won't be necessary in DBAL 5.0 (see #6589).

Copy link
Member

@morozov morozov Dec 26, 2024

Choose a reason for hiding this comment

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

Within the current API, a proper solution would be to assume all object names obtained by introspecting the database quoted, but schema names are returned as strings, so there's no way to indicate that besides wrapping all names in quotes. Doing that will fix this bug but will be a breaking change, so we can do that only in a major release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants