DDC-3148: ResultSetMappingBuilder::generateSelectClause ignores quoted column names #3904

Open
opened 2026-01-22 14:31:10 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 2, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user c.ruhstaller:

If an entity has a quoted column (Magic Words etc.) and you want to use "generateSelectClause" for the specific entity it won't return the quoted name, just the plain name. If the name is a SQL Magic Word the corresponding SQL will fail.

Exp.: "profile.real" (wrong) instead of "profile.real".

File: Doctrine/ORM/Query/ResultSetMappingBuilder.php
Function: generateSelectClause

Line 445:
$sql .= " AS " . $columnName;

Example Entity:
...
class Profile
{
/****
* @ORM\Column(name="real", type="boolean")
*/
protected $real=false;
}

Originally created by @doctrinebot on GitHub (Jun 2, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user c.ruhstaller: If an entity has a quoted column (Magic Words etc.) and you want to use "generateSelectClause" for the specific entity it won't return the quoted name, just the plain name. If the name is a SQL Magic Word the corresponding SQL will fail. Exp.: "profile.real" (wrong) instead of "profile.`real`". File: Doctrine/ORM/Query/ResultSetMappingBuilder.php Function: generateSelectClause Line 445: $sql .= " AS " . $columnName; Example Entity: ... class Profile { /**** \* @ORM\Column(name="`real`", type="boolean") */ protected $real=false; }
admin added the BugMissing Tests labels 2026-01-22 14:31:10 +01:00
Author
Owner

@yurtesen commented on GitHub (Dec 5, 2017):

I have a similar problem with generateSelectClause() also. I am using creof/doctrine2-spatial and it uses ST_AsEWKT() function when fetching spatial data columns. However when I use generateSelectClause() it simply passes column name and this causes problems.

@yurtesen commented on GitHub (Dec 5, 2017): I have a similar problem with generateSelectClause() also. I am using `creof/doctrine2-spatial` and it uses ST_AsEWKT() function when fetching spatial data columns. However when I use generateSelectClause() it simply passes column name and this causes problems.
Author
Owner

@Ocramius commented on GitHub (Dec 5, 2017):

Requires a test case to be reproduced

@Ocramius commented on GitHub (Dec 5, 2017): Requires a test case to be reproduced
Author
Owner

@yurtesen commented on GitHub (Dec 5, 2017):

@Ocramius unfortunately I am not familiar enough with doctrine to create a minimal test and I dont have time right now. However I found that there is a test which uses a custom type . Perhaps if one makes a table which uses this type, and then try to call generateSelectClause() then one can see that it does not wrap the column with UPPER() function. I may come back to this later, but right now I have more pressing problems. Because I can work around this problem by not using the feature.

@yurtesen commented on GitHub (Dec 5, 2017): @Ocramius unfortunately I am not familiar enough with doctrine to create a minimal test and I dont have time right now. However I found that there is a test which uses [a custom type ](https://github.com/doctrine/doctrine2/blob/master/tests/Doctrine/Tests/DbalTypes/UpperCaseStringType.php). Perhaps if one makes a table which uses this type, and then try to call generateSelectClause() then one can see that it does not wrap the column with UPPER() function. I may come back to this later, but right now I have more pressing problems. Because I can work around this problem by not using the feature.
Author
Owner

@Ocramius commented on GitHub (Dec 5, 2017):

@yurtesen see f13f7ebe54/tests/Doctrine/Tests/ORM/Functional/Ticket for examples

@Ocramius commented on GitHub (Dec 5, 2017): @yurtesen see https://github.com/doctrine/doctrine2/tree/f13f7ebe54d95c041d583f493102c3ea323a919c/tests/Doctrine/Tests/ORM/Functional/Ticket for examples
Author
Owner

@smarcet commented on GitHub (Mar 3, 2021):

any news on this one ? basically method generateSelectClause ignores quoting metadata set on column at class mapping so its leads to invalid SQL if the column has a reserved word as name

@smarcet commented on GitHub (Mar 3, 2021): any news on this one ? basically method generateSelectClause ignores quoting metadata set on column at class mapping so its leads to invalid SQL if the column has a reserved word as name
Author
Owner

@smarcet commented on GitHub (Mar 3, 2021):

created pull request https://github.com/doctrine/orm/pull/8522

@smarcet commented on GitHub (Mar 3, 2021): created pull request https://github.com/doctrine/orm/pull/8522
Author
Owner

@alex-dev commented on GitHub (Aug 10, 2023):

Still an active bug.

@alex-dev commented on GitHub (Aug 10, 2023): Still an active bug.
Author
Owner

@alex-dev commented on GitHub (Aug 10, 2023):

<?php

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Query;

/**
 * @group DDC-3148
 */
class DDC3148Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
    public function setUp()
    {
        parent::setUp();
        $this->_schemaTool->createSchema([
            $this->_em->getClassMetadata(DDC3148_Entity::class),
        ]);
    }

    public function testIssue()
    {
        $rsm = new Query\ResultSetMappingBuilder($this->em);
        $rsm->addRootEntityFromClassMetadata($targetClass->name, 't');

        $this->assertEquals('t.`row`', $rsm->generateSelectClause());
    }
}

/**
 * @Entity
 * @Table(name="te1")
 */
class DDC3148_Entity
{
    /**
     * @Id
     * @Column(name="`row`")
     */
    public string $row;
}
@alex-dev commented on GitHub (Aug 10, 2023): ``` <?php namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\ORM\Query; /** * @group DDC-3148 */ class DDC3148Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function setUp() { parent::setUp(); $this->_schemaTool->createSchema([ $this->_em->getClassMetadata(DDC3148_Entity::class), ]); } public function testIssue() { $rsm = new Query\ResultSetMappingBuilder($this->em); $rsm->addRootEntityFromClassMetadata($targetClass->name, 't'); $this->assertEquals('t.`row`', $rsm->generateSelectClause()); } } /** * @Entity * @Table(name="te1") */ class DDC3148_Entity { /** * @Id * @Column(name="`row`") */ public string $row; } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3904