DDC-481: Incorrect table aliasing when using quoting on table names #601

Closed
opened 2026-01-22 12:43:57 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 29, 2010).

Jira issue originally created by user mluiten:

I need to quote several table names (because of reserved words within MySQL) like so:

/****
 * @Entity
 * @Table(name="`Column`")
 */
class Column extends OptionAbstract

Another entity Question is related one-to-many to these entities, however, when trying to fetch the relation I get SQL errors because it seems to use the backtick as the table alias, which is illegal. An example of the query it's generating:

SELECT `0.id AS id1, `0.name AS name2, `0.sequence AS sequence3, `0.question*id AS question_id4 FROM `Column` `0 WHERE question*id = ?
Originally created by @doctrinebot on GitHub (Mar 29, 2010). Jira issue originally created by user mluiten: I need to quote several table names (because of reserved words within MySQL) like so: ``` /**** * @Entity * @Table(name="`Column`") */ class Column extends OptionAbstract ``` Another entity Question is related one-to-many to these entities, however, when trying to fetch the relation I get SQL errors because it seems to use the backtick as the table alias, which is illegal. An example of the query it's generating: ``` SELECT `0.id AS id1, `0.name AS name2, `0.sequence AS sequence3, `0.question*id AS question_id4 FROM `Column` `0 WHERE question*id = ? ```
admin added the Bug label 2026-01-22 12:43:57 +01:00
admin closed this issue 2026-01-22 12:43:57 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 29, 2010):

Comment created by mluiten:

Here's a patch that works for me; looping through the table name until there is a character in the range a-z (case insensitive) to use as an alias.

Might need some more error-reporting and endless loop protection etc.

@doctrinebot commented on GitHub (Mar 29, 2010): Comment created by mluiten: Here's a patch that works for me; looping through the table name until there is a character in the range a-z (case insensitive) to use as an alias. Might need some more error-reporting and endless loop protection etc.
Author
Owner

@doctrinebot commented on GitHub (Mar 29, 2010):

Comment created by romanb:

Thanks but the problem is elsewhere. The table name should not have the quote characters. The quote characters should be stripped during metadata parsing and instead a flag quoted => true set for the table in ClassMetadata::$table. Its not hard to fix, we will look into it soon.

@doctrinebot commented on GitHub (Mar 29, 2010): Comment created by romanb: Thanks but the problem is elsewhere. The table name should not have the quote characters. The quote characters should be stripped during metadata parsing and instead a flag quoted => true set for the table in ClassMetadata::$table. Its not hard to fix, we will look into it soon.
Author
Owner

@doctrinebot commented on GitHub (May 8, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (May 8, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/b10c16f18d33a285a18d

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/b10c16f18d33a285a18d - [10525_DDC-481.patch](https://gist.github.com/b10c16f18d33a285a18d#file-10525_DDC-481-patch)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#601