DDC-630: Column aliases are not properly quoted #779

Closed
opened 2026-01-22 12:50:08 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 9, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user wizardz:

Sandbox

xml

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Entities\User" table="users">
        <id name="id" type="integer">
            <generator strategy="AUTO"/>
        </id>
        <field name="name" type="string" length="50" column="`test-name`"/>
    </entity>
</doctrine-mapping>

code

$user = new User;
$user->setName("tester");
$em->persist($user);
$em->flush();
$user2 = $em->getRepository('Entities\User')->find(1);

Expectected to get valid user entity
Got

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-name1, t0.id AS id2 FROM users t0 WHERE t0.id = '1'' at line 1' in /Doctrine/DBAL/Connection.php:566
Stack trace:
#0 /lib/Doctrine/DBAL/Connection.php(566): PDOStatement->execute(Array)
#1 /lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(493): Doctrine\DBAL\Connection->executeQuery('SELECT t0.`test...', Array)
#2 /lib/Doctrine/ORM/EntityRepository.php(106): Doctrine\ORM\Persisters\BasicEntityPersister->load(Array)
#3 /index.php(61): Doctrine\ORM\EntityRepository->find(1)

Loks like the problem is in the BasicEntityPersister::_getSelectColumnSQL

Originally created by @doctrinebot on GitHub (Jun 9, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user wizardz: Sandbox xml ``` <?xml version="1.0" encoding="UTF-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Entities\User" table="users"> <id name="id" type="integer"> <generator strategy="AUTO"/> </id> <field name="name" type="string" length="50" column="`test-name`"/> </entity> </doctrine-mapping> ``` code ``` $user = new User; $user->setName("tester"); $em->persist($user); $em->flush(); $user2 = $em->getRepository('Entities\User')->find(1); ``` Expectected to get valid user entity Got ``` Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-name1, t0.id AS id2 FROM users t0 WHERE t0.id = '1'' at line 1' in /Doctrine/DBAL/Connection.php:566 Stack trace: #0 /lib/Doctrine/DBAL/Connection.php(566): PDOStatement->execute(Array) #1 /lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(493): Doctrine\DBAL\Connection->executeQuery('SELECT t0.`test...', Array) #2 /lib/Doctrine/ORM/EntityRepository.php(106): Doctrine\ORM\Persisters\BasicEntityPersister->load(Array) #3 /index.php(61): Doctrine\ORM\EntityRepository->find(1) ``` Loks like the problem is in the BasicEntityPersister::_getSelectColumnSQL
admin added the Bug label 2026-01-22 12:50:08 +01:00
admin closed this issue 2026-01-22 12:50:09 +01:00
Author
Owner

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

Comment created by romanb:

You mention BETA1 as the affected version. Can you confirm that this issue still exists in the BETA3 release and/or the master repository?

@doctrinebot commented on GitHub (Aug 8, 2010): Comment created by romanb: You mention BETA1 as the affected version. Can you confirm that this issue still exists in the BETA3 release and/or the master repository?
Author
Owner

@doctrinebot commented on GitHub (Aug 15, 2010):

Comment created by @beberlei:

Are dashes even allowed in column names? I dont think so.

@doctrinebot commented on GitHub (Aug 15, 2010): Comment created by @beberlei: Are dashes even allowed in column names? I dont think so.
Author
Owner

@doctrinebot commented on GitHub (Aug 19, 2010):

Comment created by shurakai:

I don't think so either. This seems to be a non-issue.

@doctrinebot commented on GitHub (Aug 19, 2010): Comment created by shurakai: I don't think so either. This seems to be a non-issue.
Author
Owner

@doctrinebot commented on GitHub (Aug 26, 2010):

Comment created by romanb:

Unscheduled until we get further feedback.

@doctrinebot commented on GitHub (Aug 26, 2010): Comment created by romanb: Unscheduled until we get further feedback.
Author
Owner

@doctrinebot commented on GitHub (Sep 16, 2010):

Comment created by wizardz:

Roman,
I do not have this setup anymore so I cannot check next beta releases

Benjamin,
dash it is an allowed character for MySQL at least.

I do not think it is a big issue, it's just mater of your preferences - do you want to allow using of dash in the field names or not. If not may be it's a good idea to mention this fact somewhere in documentation

@doctrinebot commented on GitHub (Sep 16, 2010): Comment created by wizardz: Roman, I do not have this setup anymore so I cannot check next beta releases Benjamin, dash it is an allowed character for MySQL at least. I do not think it is a big issue, it's just mater of your preferences - do you want to allow using of dash in the field names or not. If not may be it's a good idea to mention this fact somewhere in documentation
Author
Owner

@doctrinebot commented on GitHub (Sep 20, 2010):

Comment created by @beberlei:

According to the SQL Error messages dashes dont seem to be allowed. Its exactly that character that causes the error message or not?

Hm, but dash seems to work. So it must be something else

@doctrinebot commented on GitHub (Sep 20, 2010): Comment created by @beberlei: According to the SQL Error messages dashes dont seem to be allowed. Its exactly that character that causes the error message or not? Hm, but dash seems to work. So it must be something else
Author
Owner

@doctrinebot commented on GitHub (Sep 23, 2010):

Comment created by @beberlei:

This doesn't work because the persister uses the column-name for the AS part of the query. We won't fix this programatically, this is rather a restriction of Doctrine 2.

For this reason i have updated the documentation to state that non a-zA-Z0-9_ chars should not be used (even quoted) as columns.

@doctrinebot commented on GitHub (Sep 23, 2010): Comment created by @beberlei: This doesn't work because the persister uses the column-name for the AS part of the query. We won't fix this programatically, this is rather a restriction of Doctrine 2. For this reason i have updated the documentation to state that non a-zA-Z0-9_ chars should not be used (even quoted) as columns.
Author
Owner

@doctrinebot commented on GitHub (Sep 23, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Sep 23, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#779