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

Update index name quoting in MySQL table creation #730

Merged
merged 4 commits into from
Dec 12, 2014

Conversation

garoevans
Copy link
Contributor

When creating a table that includes an index named with a reserved keyword the index name isn't quoted. When creating the index specifically the name is quote. This bring the table generation SQL inline with the index generation.

@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DBAL-1051

We use Jira to track the state of pull requests and the versions they got
included in.

}
}

// add all indexes
if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach ($options['indexes'] as $index => $definition) {
$queryFields .= ', ' . $this->getIndexDeclarationSQL($index, $definition);
$queryFields .= ', ' . $this->getIndexDeclarationSQL($definition->getQuotedName($this), $definition);
Copy link
Member

Choose a reason for hiding this comment

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

Is this only for the MySql platform? Can you check if other platforms have similar leaks?

@garoevans
Copy link
Contributor Author

@Ocramius MySQL seems to be the only engine that creates indexes inline with table creation. All the other platform need a different query to create the index that go through the getCreateIndexSQL() method that's already quoted.

I did however move the quoting to the abstract so that it brings it all to one location.

@Ocramius
Copy link
Member

Looking good. Assigning to @deeky666 for merge.

@deeky666
Copy link
Member

deeky666 commented Dec 2, 2014

hmm not sure if it is a good idea to totally ignore the $name parameters in those methods. That could break applications that rely on the $name parameter being used for the declaration SQL. Also the method documentation states that the $name parameter will be used as index name.
@Ocramius thoughts?

@deeky666
Copy link
Member

deeky666 commented Dec 2, 2014

Also maybe related? #723

@garoevans
Copy link
Contributor Author

I would argue that this PR is doing the same as #723 but I do see how quoting the index name earlier in the process maintains the documentation and interface around the getIndexDeclarationSQL() method.

Is #723 likely to get merged in any time soon, if so I am happy to close this one, or if any changes are needed I am happy to push them through.

I'm currently supporting a forked version of the code base to support my requirements, starting to generate our schema using the schema-tool. Unfortunately we already have an indexed names key!

@deeky666
Copy link
Member

deeky666 commented Dec 3, 2014

@garoevans I think that other PR is complementary. The idea behind your patch is not wrong as those methods are public API and can be used separately, it's just that I think the implementation is not correct. I would rather go for quoting the $name property instead of changing the behaviour to use the index name. Looks like those methods have been misdesigned in the past and we cannot change that by now.
You could do the following:

$name = new Identifier($name);
$name->getQuotedName($this);

This is a workaround we are already utilizing in several code paths.

@garoevans
Copy link
Contributor Author

@deeky666 that looks good to me. I'll try and make the change later today and then leave it in your capable hands!

@garoevans
Copy link
Contributor Author

@deeky666 does this need any more input from me now?

@@ -26,6 +26,20 @@ public function testGenerateMixedCaseTableCreate()
$this->assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql));
}

public function testReservedKeywordInIndexGeneratedTableSql()
Copy link
Member

Choose a reason for hiding this comment

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

Can you please move that test to AbstractPlatformTestCase to have all platforms execute that test? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#730 (comment) mentioned that MySQL is the only engine that creates engines along with a table create statement. I'm not sure the test would be relevant for other engines?

I did have the test higher up the abstraction at one point but it didn't seem right?

Copy link
Member

Choose a reason for hiding this comment

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

@garoevans the two methods you modified is public API! This means it can be used in any context and is not only trigger by getCreateTableSQL().
Creating indexes and unique constraints is supported by all of our platforms AFAIK. So putting the tests into AbstractPlatformTestCase makes perfect sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, my first iteration of code quoted the index name within the MySQL platform file. Now that it is in the 'AbstractPlatform' class you are quite right that the test should be updated to reflect this.

Bit slow there, will take a look when I get some time.

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

Successfully merging this pull request may close these issues.

4 participants