-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: 3.9.x
Are you sure you want to change the base?
🐛 Oracle: fix comment retrieval on table with reserved keyword name #6765
Conversation
e047825
to
e0e54cf
Compare
UPD: no, this looks safer than I thought. I'll leave a comment inline. |
e0e54cf
to
d2452fa
Compare
Please target 3.9.x though. |
74e6478
to
e6f5433
Compare
d0fb9ec
to
3347eeb
Compare
src/Schema/SqliteSchemaManager.php
Outdated
@@ -582,7 +582,7 @@ private function getCreateTableSQL(string $table): string | |||
AND name = ? | |||
SQL | |||
, | |||
[$table], | |||
[trim($table, '"')], // Unquote the identifier |
There was a problem hiding this comment.
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:
dbal/src/Schema/AbstractSchemaManager.php
Lines 252 to 257 in 8ce05ed
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
3347eeb
to
c95de27
Compare
Fix SQLite comment retrieval when using quoted identifier as well
c95de27
to
31e1c67
Compare
@@ -486,7 +487,7 @@ protected function doListTableDetails($name): Table | |||
$this->listTableIndexes($name), | |||
[], | |||
$foreignKeys, | |||
$tableOptionsByTable[$normalizedName] ?? [], | |||
$tableOptionsByTable[$name] ?? [], |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'
.
There was a problem hiding this comment.
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.
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.