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

🐛 Oracle: fix comment retrieval on table with reserved keyword name #6765

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

Conversation

homersimpsons
Copy link

@homersimpsons homersimpsons commented Feb 3, 2025

Q A
Type bug
Fixed issues #6764

⚠️ This targets the 3.9.x branch as requested in #6765 (comment)

Summary

Use \Doctrine\DBAL\Schema\OracleSchemaManager::_getPortableTableDefinition in \Doctrine\DBAL\Schema\OracleSchemaManager::fetchTableOptionsByTable to be consistent with \Doctrine\DBAL\Schema\AbstractSchemaManager::fetchAllAssociativeGrouped which calls \Doctrine\DBAL\Schema\OracleSchemaManager::_getPortableTableDefinition

This also fixes an issue in SQLite due to the fact that the name passed to _getPortableTableColumnList was not always normalized.

@homersimpsons homersimpsons force-pushed the fix/oracle-table-comment-retrieval branch from e047825 to e0e54cf Compare February 3, 2025 17:38
@morozov
Copy link
Member

morozov commented Feb 3, 2025

This is likely going to be a breaking change since all identifiers will be now introspected as quoted. This is correct but may have an unexpected ripple effect on the downstream consumers. This is going to be addressed in 5.0. See #6732 for an example of introspecting foreign key constraints. In the coming few days, I'll make a similar change for table names. But this needs to apply to all object names (indexes, indexed column names, table column names and so on).

UPD: no, this looks safer than I thought. I'll leave a comment inline.

@homersimpsons homersimpsons force-pushed the fix/oracle-table-comment-retrieval branch from e0e54cf to d2452fa Compare February 4, 2025 11:45
@derrabus
Copy link
Member

derrabus commented Feb 4, 2025

Please target 3.9.x though.

@homersimpsons homersimpsons force-pushed the fix/oracle-table-comment-retrieval branch 2 times, most recently from 74e6478 to e6f5433 Compare February 4, 2025 14:12
@homersimpsons homersimpsons changed the base branch from 3.10.x to 3.9.x February 4, 2025 14:12
@homersimpsons homersimpsons force-pushed the fix/oracle-table-comment-retrieval branch 2 times, most recently from d0fb9ec to 3347eeb Compare February 4, 2025 16:04
@homersimpsons homersimpsons requested a review from morozov February 4, 2025 16:10
@@ -582,7 +582,7 @@ private function getCreateTableSQL(string $table): string
AND name = ?
SQL
,
[$table],
[trim($table, '"')], // Unquote the identifier
Copy link
Member

Choose a reason for hiding this comment

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

It probably should be done here:

return $this->_getPortableTableColumnList(
$table,
$database,
$this->selectTableColumns($database, $this->normalizeName($table))
->fetchAllAssociative(),
);

The name passed to selectTableColumns() is "normalized" but the one passed to _getPortableTableColumnList() is not.

Copy link
Author

@homersimpsons homersimpsons Feb 6, 2025

Choose a reason for hiding this comment

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

Thank you for the guidance, I updated the logic.

Is there any rule about where the name should be normalized and where it should be escaped?

Copy link
Member

@morozov morozov Feb 6, 2025

Choose a reason for hiding this comment

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

Is there any rule about where the name should be normalized and where it should be escaped?

The quoted name is what we receive from the user to allow them to declare that the original case of the name should be preserved (e.g. the lower-case users table should be introspected even though Oracle by default upper-cases all names). The normalized name is the result of "parsing" the user-supplied input and deriving the actual value from it.

Ideally, we want to normalize the name as soon as possible and use the normalized one downstream.

src/Schema/SqliteSchemaManager.php Outdated Show resolved Hide resolved
@homersimpsons homersimpsons force-pushed the fix/oracle-table-comment-retrieval branch from 3347eeb to c95de27 Compare February 6, 2025 09:38
@homersimpsons homersimpsons requested a review from morozov February 6, 2025 09:40
Fix SQLite comment retrieval when using quoted identifier as well
@homersimpsons homersimpsons force-pushed the fix/oracle-table-comment-retrieval branch from c95de27 to 31e1c67 Compare February 6, 2025 12:56
@@ -486,7 +487,7 @@ protected function doListTableDetails($name): Table
$this->listTableIndexes($name),
[],
$foreignKeys,
$tableOptionsByTable[$normalizedName] ?? [],
$tableOptionsByTable[$name] ?? [],
Copy link
Author

Choose a reason for hiding this comment

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

@morozov This change works for oracle but breaks for SQLite... I'm not sure of what approach should I take, but it looks like the mix between normalized / quoted names is the main issue here (and the various databases may not handle them the same).

Copy link
Member

@morozov morozov Feb 6, 2025

Choose a reason for hiding this comment

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

If you want, you can scope your pull request only to fixing the table comment, which is necessary only for Oracle (in my understanding).

If you want to fix it for SQLite / column comments as well, you can try referring to the 4.3.x branch. This code has been slightly cleaned up there, and I believe the normalized/quoted names are no longer mixed there. If that's the case, you can try to reconstruct the logic from 4.3.x here.

Copy link
Member

@morozov morozov Feb 6, 2025

Choose a reason for hiding this comment

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

This change works for oracle

I think options (and all other table objects) should be indexed by the normalized name. The quoted names are just form or user input, while the normalized ones are the actual values. E.g. on Oracle, the inputs 'users' and '"USERS"' will both be normalized to 'USERS'.

Copy link
Author

Choose a reason for hiding this comment

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

I believe the normalized/quoted names are no longer mixed there.

I did not check whether there were mixed or no, but I confirm it works for both Oracle and SQLite there.

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.

3 participants