-
-
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
MySQL getListTableForeignKeysSQL: use current database if null passed #856
MySQL getListTableForeignKeysSQL: use current database if null passed #856
Conversation
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DBAL-1232 We use Jira to track the state of pull requests and the versions they got |
@deeky666 This is a serious bug, because its very hard to find when it occurs to you. |
@naderman is it possible to add a functional test to avoid regressions in the future or do you think this is too much effort in this case? |
@deeky666 Just haven't looked at doctrine's test set up at all so far, so no idea how much work this would be. Basically just need to create two databases with the same table with a foreign key each with different names and see if a select returns only the one on the right database. |
The tests still passing is a good indicator that it still works as expected in the scenario we care about ( |
@@ -191,6 +191,8 @@ public function getListTableForeignKeysSQL($table, $database = null) | |||
|
|||
if ($database) { | |||
$sql .= " AND k.table_schema = '$database' /*!50116 AND c.constraint_schema = '$database' */"; | |||
} else { | |||
$sql .= " AND k.table_schema = DATABASE() /*!50116 AND c.constraint_schema = DATABASE() */"; |
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.
Can we try to avoid SQL duplication here by doing something like this:
$database = null === $database ? 'DATABASE()' : "'$database'";
@zeroedin-bill as we discussed on IRC this is rather hard to test in the current setup as it requires an additional database to be set up. |
Did make the change @deeky666 suggested, so this should be mergable? |
Test failure is a network issue on the travis box, you can restart those 2 failed builds and it should be fine. |
MySQL getListTableForeignKeysSQL: use current database if null passed
@naderman backport has been forgotten. Will tag this for 2.5.5 then. |
Thanks @deeky666 ! |
In line with the behavior of
getListTableIndexesSQL()
the foreign key function should select only foreign keys from the current database if no database name is specified. Otherwise it returns foreign keys of all tables in any database with the given name. This can especially lead to issues if you install different versions of the same schema into multiple databases on the same server.This function is always called with
$database = null
in the following chain, which leads to SQL errors when trying to setup/delete a schema in tests on a mysql server that contains another copy of the schema in another database:I think the
$database
parameter would ideally be required, and an exception should be thrown if it is null. The AbstractSchemaManager should be modified to consistently pass the database name to the platform in all its calls. But for now this workaround corrects the issue for foreign keys.