Skip to content

Fixes a bug caused by unquoted reserved table name being referenced during schema creation #166

Closed
wants to merge 2 commits into from

7 participants

@klaussilveira

When creating a schema with tables with reserved names and relationships between them, the schema creation tool failed to write valid SQL in MySQL due to unquoted table names. For example:

CREATE TABLE `Group` (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL DEFAULT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
CREATE TABLE User (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(255) NOT NULL PRIMARY KEY(id)) ENGINE = InnoDB;
CREATE TABLE UserHasGroup (user_id INT NOT NULL, group_id INT NOT NULL, INDEX IDX_617A865CA76ED395 (user_id), INDEX IDX_617A865CFE54D947 (group_id), PRIMARY KEY(user_id, group_id)) ENGINE = InnoDB;
ALTER TABLE UserHasGroup ADD CONSTRAINT FK_617A865CA76ED395 FOREIGN KEY (user_id) REFERENCES User (id);
ALTER TABLE UserHasGroup ADD CONSTRAINT FK_617A865CFE54D947 FOREIGN KEY (group_id) REFERENCES Group (id);

This fix creates a small function for creating quoted foreign key table names.

@travisbot

This pull request fails (merged fe9d93d into ab57a01).

@asm89
Doctrine member
asm89 commented Jul 7, 2012

Can you run the testsuite locally? Your PR breaks a lot.

@stof stof commented on the diff Jul 7, 2012
lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php
@@ -110,6 +110,24 @@ public function getForeignTableName()
}
/**
+ * Get the quoted representation of this asset but only if it was defined with one. Otherwise
+ * return the plain unquoted value as inserted.
+ *
+ * @param AbstractPlatform $platform
+ * @return string
+ */
+ public function getQuotedForeignTableName(AbstractPlatform $platform)
@stof
Doctrine member
stof added a note Jul 7, 2012

the use statement is missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@klaussilveira

Fixed the missing use statement. Everything should work fine now.

@travisbot

This pull request fails (merged 82af3c0 into ab57a01).

@klaussilveira

Since this was marked as not a bug, closing the request.

@beberlei
Doctrine member

The ticket was marked Awaiting Feedback, not closed. I applied this patch now, thank you very much!

@drgomesp
drgomesp commented Nov 7, 2013

Any updates on this?

@deeky666
Doctrine member
deeky666 commented Nov 7, 2013

@drgomesp What do you mean by "updates"? The PR has already been merged a long time ago.

@stof
Doctrine member
stof commented Nov 7, 2013

@drgomesp The patch was applied 1 year ago: 311bda5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.