DDC-3042: select issue field names with numbers #3779

Closed
opened 2026-01-22 14:27:52 +01:00 by admin · 9 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 21, 2014).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user rev83:

$qb = $this->_em->createQueryBuilder();
$qb->select('k.aktiv, k.id, k.firma, k.firma2, k.strasse, k.plz, k.ort, k.plzpostfach, k.postfach, k.bemerkung,
         k.uuid, k.telefon,k.telefonzentrale, k.istmutter, k.isttochter, k.email, k.internet, k.fax, l.id as land, m.id as mutter, m.firma as mutterv, t.id as tochter, t.firma as tochterv, kg.id as kundengruppe, s.id as sic, s.title as sicv,
         kg.title as kundengruppev,m.telefon as telefonmutter,t.telefon as telefontochter, k.id as kdnr')

will create this sql:

SELECT c0*.id AS id0, c0_.aktiv AS aktiv1, c0_.firma AS firma2, c0_.firma2 AS firma23, c0_.strasse AS strasse4, c0_.plz AS plz5, c0_.ort AS ort6, c0_.plzpostfach AS plzpostfach7, c0_.postfach AS postfach8, c0_.hotel AS hotel9, c0_.kuerzel AS kuerzel10, c0_.stornofrist AS stornofrist11, c0_.uuid AS uuid12, c0_.telefon AS telefon13, c0_.telefonzentrale AS telefonzentrale14, c0_.istmutter AS istmutter15, c0_.isttochter AS isttochter16, c0_.trainer AS trainer17, c0_.email AS email18, c0_.internet AS internet19, c0_.fax AS fax20, l6_.id AS id21, c3_.id AS id22, c3_.firma AS firma23, c3_.telefon AS telefon24, c0_.id AS id25, t1_.content AS anfahrt26, t2*.content AS beschreibung27 

as you see, it will create co.firma2 as firma23 and c3_.firma AS firma23,

now when you do:

$query = $qb->getQuery();
$result = $query->getArrayResult();
Array
(
    [0] => Array
        (
            [id] => 11
            [aktiv] => 1
            [firma] => Test GmbH
            [mutterv] => Mutter Test
            [strasse] => 
            [plz] => 
            [ort] => 
            [plzpostfach] => 
            [postfach] => 
            [hotel] => 
            [kuerzel] => 
            [stornofrist] => 0
            [uuid] => 524459b5-7f1c-442b-98dd-3d5cc0a81420
            [telefon] => 0211/415583810
            [telefonzentrale] => 
            [istmutter] => 
            [isttochter] => 
            [trainer] => 
            [email] => 
            [internet] => 
            [fax] => 
            [land] => 3
            [mutter] => 
            [telefonmutter] => 
            [kdnr] => 11
            [anfahrt] => 
            [beschreibung] => 
        )
)

when i change the order of the select , it will work

 $qb->select('k.id, k.aktiv, k.firma, k.strasse, k.plz, k.ort, k.plzpostfach, k.postfach, k.hotel, k.kuerzel, k.stornofrist,  k.firma2,
         k.uuid, k.telefon,k.telefonzentrale, k.istmutter, k.isttochter, k.trainer, k.email, k.internet, k.fax, l.id as land, m.id as mutter, m.firma as mutterv,
         m.telefon as telefonmutter, k.id as kdnr, k.anfahrt, k.beschreibung')
Originally created by @doctrinebot on GitHub (Mar 21, 2014). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user rev83: ``` $qb = $this->_em->createQueryBuilder(); $qb->select('k.aktiv, k.id, k.firma, k.firma2, k.strasse, k.plz, k.ort, k.plzpostfach, k.postfach, k.bemerkung, k.uuid, k.telefon,k.telefonzentrale, k.istmutter, k.isttochter, k.email, k.internet, k.fax, l.id as land, m.id as mutter, m.firma as mutterv, t.id as tochter, t.firma as tochterv, kg.id as kundengruppe, s.id as sic, s.title as sicv, kg.title as kundengruppev,m.telefon as telefonmutter,t.telefon as telefontochter, k.id as kdnr') ``` will create this sql: ``` SELECT c0*.id AS id0, c0_.aktiv AS aktiv1, c0_.firma AS firma2, c0_.firma2 AS firma23, c0_.strasse AS strasse4, c0_.plz AS plz5, c0_.ort AS ort6, c0_.plzpostfach AS plzpostfach7, c0_.postfach AS postfach8, c0_.hotel AS hotel9, c0_.kuerzel AS kuerzel10, c0_.stornofrist AS stornofrist11, c0_.uuid AS uuid12, c0_.telefon AS telefon13, c0_.telefonzentrale AS telefonzentrale14, c0_.istmutter AS istmutter15, c0_.isttochter AS isttochter16, c0_.trainer AS trainer17, c0_.email AS email18, c0_.internet AS internet19, c0_.fax AS fax20, l6_.id AS id21, c3_.id AS id22, c3_.firma AS firma23, c3_.telefon AS telefon24, c0_.id AS id25, t1_.content AS anfahrt26, t2*.content AS beschreibung27 ``` as you see, it will create co.firma2 as firma23 and c3_.firma AS firma23, now when you do: ``` $query = $qb->getQuery(); $result = $query->getArrayResult(); ``` ``` Array ( [0] => Array ( [id] => 11 [aktiv] => 1 [firma] => Test GmbH [mutterv] => Mutter Test [strasse] => [plz] => [ort] => [plzpostfach] => [postfach] => [hotel] => [kuerzel] => [stornofrist] => 0 [uuid] => 524459b5-7f1c-442b-98dd-3d5cc0a81420 [telefon] => 0211/415583810 [telefonzentrale] => [istmutter] => [isttochter] => [trainer] => [email] => [internet] => [fax] => [land] => 3 [mutter] => [telefonmutter] => [kdnr] => 11 [anfahrt] => [beschreibung] => ) ) ``` when i change the order of the select , it will work ``` $qb->select('k.id, k.aktiv, k.firma, k.strasse, k.plz, k.ort, k.plzpostfach, k.postfach, k.hotel, k.kuerzel, k.stornofrist, k.firma2, k.uuid, k.telefon,k.telefonzentrale, k.istmutter, k.isttochter, k.trainer, k.email, k.internet, k.fax, l.id as land, m.id as mutter, m.firma as mutterv, m.telefon as telefonmutter, k.id as kdnr, k.anfahrt, k.beschreibung') ```
admin added the Bug label 2026-01-22 14:27:52 +01:00
admin closed this issue 2026-01-22 14:27:53 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 21, 2014):

@doctrinebot commented on GitHub (Mar 21, 2014): - is duplicated by [DDC-3043: [GH-985] [WIP] [DDC-3042] SQL Alias collisions in DQL](http://www.doctrine-project.org/jira/browse/DDC-3043)
Author
Owner

@doctrinebot commented on GitHub (Mar 21, 2014):

Comment created by @ocramius:

[~rev83] can you reduce the example to only the fields that are affected? Does this affect also latest ORM?

@doctrinebot commented on GitHub (Mar 21, 2014): Comment created by @ocramius: [~rev83] can you reduce the example to only the fields that are affected? Does this affect also latest ORM?
Author
Owner

@doctrinebot commented on GitHub (Mar 21, 2014):

Comment created by rev83:

Marco, the Problem only exists when you select like my example

c0*.id AS id0, c0_.aktiv AS aktiv1, c0_.firma AS firma2, (...),  c0*.firma2 AS firma23, 

as you see "firma2" is on the fourth place so it´s selected as "firma23", "m.firma" is on place 24, so it´s also selected as "firma23" (m.firma as mutterv)

@doctrinebot commented on GitHub (Mar 21, 2014): Comment created by rev83: Marco, the Problem only exists when you select like my example ``` c0*.id AS id0, c0_.aktiv AS aktiv1, c0_.firma AS firma2, (...), c0*.firma2 AS firma23, ``` as you see "firma2" is on the fourth place so it´s selected as "firma23", "m.firma" is on place 24, so it´s also selected as "firma23" (m.firma as mutterv)
Author
Owner

@doctrinebot commented on GitHub (Mar 21, 2014):

Comment created by @ocramius:

[~rev83] ah, I see it now. This probably requires a change in how the DQL is generated by prefixing numerical indexes with something like an _.

@doctrinebot commented on GitHub (Mar 21, 2014): Comment created by @ocramius: [~rev83] ah, I see it now. This probably requires a change in how the DQL is generated by prefixing numerical indexes with something like an `_`.
Author
Owner

@doctrinebot commented on GitHub (Mar 21, 2014):

Comment created by @ocramius:

[~rev83] I provided a fix at https://github.com/doctrine/doctrine2/pull/985 - can you try it?

@doctrinebot commented on GitHub (Mar 21, 2014): Comment created by @ocramius: [~rev83] I provided a fix at https://github.com/doctrine/doctrine2/pull/985 - can you try it?
Author
Owner

@doctrinebot commented on GitHub (Mar 24, 2014):

Comment created by rev83:

Yeah, this works.

@doctrinebot commented on GitHub (Mar 24, 2014): Comment created by rev83: Yeah, this works.
Author
Owner

@doctrinebot commented on GitHub (Apr 4, 2014):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-985] was closed:
https://github.com/doctrine/doctrine2/pull/985

@doctrinebot commented on GitHub (Apr 4, 2014): Comment created by @doctrinebot: A related Github Pull-Request [GH-985] was closed: https://github.com/doctrine/doctrine2/pull/985
Author
Owner

@doctrinebot commented on GitHub (Apr 4, 2014):

Comment created by @ocramius:

Merged: bfb66f1d85

@doctrinebot commented on GitHub (Apr 4, 2014): Comment created by @ocramius: Merged: https://github.com/doctrine/doctrine2/commit/bfb66f1d85509db9e24ce33e30382c8cccaf2dd7
Author
Owner

@doctrinebot commented on GitHub (Apr 4, 2014):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Apr 4, 2014): 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#3779