DDC-2193: Named native query bug? #2760

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

Originally created by @doctrinebot on GitHub (Dec 11, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user dingdangjyz:

@NamedNativeQueries is a useful thing, but I have found some problems during my using.
1、Normal

 /****
 * @NamedNativeQueries({
 *      @NamedNativeQuery(
 *          name            = "fetchMultipleJoinsEntityResults",
 *          resultSetMapping= "mappingMultipleJoinsEntityResults",
 **          query            = "SELECT ** FROM test "
 *      )
 * })
 */

2、Error,cannot connect to the server

 /****
 * @NamedNativeQueries({
 *      @NamedNativeQuery(
 *          name            = "fetchMultipleJoinsEntityResults",
 *          resultSetMapping= "mappingMultipleJoinsEntityResults",
 **          query            = "SELECT ** 
            FROM test "
 *      )
 * })
 */

3、Cannot use alias.The same problem as the second one.

.......
 query            = "SELECT a as test FROM test "
Originally created by @doctrinebot on GitHub (Dec 11, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user dingdangjyz: @NamedNativeQueries is a useful thing, but I have found some problems during my using. 1、Normal ``` /**** * @NamedNativeQueries({ * @NamedNativeQuery( * name = "fetchMultipleJoinsEntityResults", * resultSetMapping= "mappingMultipleJoinsEntityResults", ** query = "SELECT ** FROM test " * ) * }) */ ``` 2、Error,cannot connect to the server ``` /**** * @NamedNativeQueries({ * @NamedNativeQuery( * name = "fetchMultipleJoinsEntityResults", * resultSetMapping= "mappingMultipleJoinsEntityResults", ** query = "SELECT ** FROM test " * ) * }) */ ``` 3、Cannot use alias.The same problem as the second one. ``` ....... query = "SELECT a as test FROM test " ```
admin added the Bug label 2026-01-22 14:02:38 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 12, 2012):

Comment created by @FabioBatSilva:

Hi

Doctrine does not change the native query at all
The problem seems related with database connection.

Could you provide more details please?

Cheers

@doctrinebot commented on GitHub (Dec 12, 2012): Comment created by @FabioBatSilva: Hi Doctrine does not change the native query at all The problem seems related with database connection. Could you provide more details please? Cheers
Author
Owner

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

Comment created by dingdangjyz:

Doctrine\Common\Lexer.php

Hello, after checking, I found the problem should be here. As long as SQL wrap, or fill in alias, it will be error. It seems to be the preg_split problem?

        $flags = PREG*SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET*CAPTURE;
        $matches = preg_split($regex, $input, -1, $flags);

        foreach ($matches as $match) {
            // Must remain before 'value' assignment since it can change content
            $type = $this->getType($match[0]);

            $this->tokens[] = array(
                'value' => $match[0],
                'type'  => $type,
                'position' => $match[1],
            );
@doctrinebot commented on GitHub (Dec 13, 2012): Comment created by dingdangjyz: Doctrine\Common\Lexer.php Hello, after checking, I found the problem should be here. As long as SQL wrap, or fill in alias, it will be error. It seems to be the preg_split problem? ``` $flags = PREG*SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET*CAPTURE; $matches = preg_split($regex, $input, -1, $flags); foreach ($matches as $match) { // Must remain before 'value' assignment since it can change content $type = $this->getType($match[0]); $this->tokens[] = array( 'value' => $match[0], 'type' => $type, 'position' => $match[1], ); ```
Author
Owner

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

Comment created by @FabioBatSilva:

Hi

Could you try to add a failing test case please ?

Cheers

@doctrinebot commented on GitHub (Dec 13, 2012): Comment created by @FabioBatSilva: Hi Could you try to add a failing test case please ? Cheers
Author
Owner

@doctrinebot commented on GitHub (Dec 14, 2012):

Comment created by dingdangjyz:

xp php5.3.8 Apache

<?php

namespace Models\Entities;

/****
 * @Entity
 * @Table
 *
 * @NamedNativeQueries({
 *      @NamedNativeQuery(
 *          name             = "find-hotel-item",
 *          resultSetMapping = "mapping-find-item",
 *          query            = "SELECT Top 1 VEI_SN AS SN 
            FROM tourmanager.dbo.VEndorInfo vi 
INNER JOIN tourmanager.dbo.VEndorInfo2 vi2 ON 
vi.VEI*SN = vi2.VEI2_VEI*SN LEFT OUTER JOIN tourmanager.dbo.HotelInfo hi 
ON hi.hotelid = vi2.VEI2*VEI*SN INNER JOIN tourmanager.dbo.HotelInfo2 
hi2 ON hi2.hotelid = vi2.VEI2*VEI*SN AND hi2.LGC = 1 "
 *      )
 * })
 *
 * @SqlResultSetMappings({
 *      @SqlResultSetMapping(
 *          name    = "mapping-find-item",
 *          entities= {
 *              @EntityResult(
 *                  entityClass = "HTHotelItem",
 *                  fields = {
 *                      @FieldResult(name = "id",   column="SN")
 *                  }
 *              )
 *          }
 *      )
 * })
 *
 */

class HTHotelItem{
    /*** @Id @Column(type="integer") @GeneratedValue **/
    protected $id;

    /*** @name **/
    protected $name;

    /*** @city **/
    protected $city;

    /*** @url **/
    protected $url;

    public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata){
        $metadata->addNamedNativeQuery(array(
            'name'              => 'find-hotel-item',
            'query'             => 'SELECT h FROM HTHotelItem h',
            'resultSetMapping'  => '\\Models\\Entities\\HTHotelItem'
        ));
    }

    function getId(){
        return $this->id;
    }

    function getName(){
        return $this->name;
    }

    function getCity(){
        return $this->city;
    }

    function getUrl(){
        return $this->url;
    }
}
@doctrinebot commented on GitHub (Dec 14, 2012): Comment created by dingdangjyz: xp php5.3.8 Apache ``` <?php namespace Models\Entities; /**** * @Entity * @Table * * @NamedNativeQueries({ * @NamedNativeQuery( * name = "find-hotel-item", * resultSetMapping = "mapping-find-item", * query = "SELECT Top 1 VEI_SN AS SN FROM tourmanager.dbo.VEndorInfo vi INNER JOIN tourmanager.dbo.VEndorInfo2 vi2 ON vi.VEI*SN = vi2.VEI2_VEI*SN LEFT OUTER JOIN tourmanager.dbo.HotelInfo hi ON hi.hotelid = vi2.VEI2*VEI*SN INNER JOIN tourmanager.dbo.HotelInfo2 hi2 ON hi2.hotelid = vi2.VEI2*VEI*SN AND hi2.LGC = 1 " * ) * }) * * @SqlResultSetMappings({ * @SqlResultSetMapping( * name = "mapping-find-item", * entities= { * @EntityResult( * entityClass = "HTHotelItem", * fields = { * @FieldResult(name = "id", column="SN") * } * ) * } * ) * }) * */ class HTHotelItem{ /*** @Id @Column(type="integer") @GeneratedValue **/ protected $id; /*** @name **/ protected $name; /*** @city **/ protected $city; /*** @url **/ protected $url; public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata){ $metadata->addNamedNativeQuery(array( 'name' => 'find-hotel-item', 'query' => 'SELECT h FROM HTHotelItem h', 'resultSetMapping' => '\\Models\\Entities\\HTHotelItem' )); } function getId(){ return $this->id; } function getName(){ return $this->name; } function getCity(){ return $this->city; } function getUrl(){ return $this->url; } } ```
Author
Owner

@doctrinebot commented on GitHub (Dec 14, 2012):

Comment created by dingdangjyz:

@NamedNativeQueries query

If we write the long SQL, it will be fault. NO error massage.
1251 charecter must be wrong.
I still insist it is the problem of preg_split in
Doctrine\Common\Lexer.php

@doctrinebot commented on GitHub (Dec 14, 2012): Comment created by dingdangjyz: @NamedNativeQueries query If we write the long SQL, it will be fault. NO error massage. 1251 charecter must be wrong. I still insist it is the problem of preg_split in Doctrine\Common\Lexer.php
Author
Owner

@doctrinebot commented on GitHub (Dec 16, 2012):

Comment created by @FabioBatSilva:

Can't reproduce,

Could you try to change the attached test case and make it fail.

Cheers

@doctrinebot commented on GitHub (Dec 16, 2012): Comment created by @FabioBatSilva: Can't reproduce, Could you try to change the attached test case and make it fail. Cheers
Author
Owner

@doctrinebot commented on GitHub (Dec 24, 2012):

Comment created by @beberlei:

The Doctrine\Common\Lexer is never used in combination with native queries, only with the Annotation Parser, so i cannot be the preg_split that causes your SQL to be broken. Or do you get annotation errors?

Also what database are you using? maybe its related to the DBAL sql parsing?

@doctrinebot commented on GitHub (Dec 24, 2012): Comment created by @beberlei: The Doctrine\Common\Lexer is never used in combination with native queries, only with the Annotation Parser, so i cannot be the preg_split that causes your SQL to be broken. Or do you get annotation errors? Also what database are you using? maybe its related to the DBAL sql parsing?
Author
Owner

@doctrinebot commented on GitHub (Dec 31, 2012):

Comment created by dingdangjyz:

I'm sorry my English is too bad.

I think it's Doctrine \ is \ Lexer. PHP preg_split the function of the problem in this file.
My system environment is xp/apache 5.3 + / php_pdo_sqlsrv_53 / mssql2000

@doctrinebot commented on GitHub (Dec 31, 2012): Comment created by dingdangjyz: I'm sorry my English is too bad. I think it's Doctrine \ is \ Lexer. PHP preg_split the function of the problem in this file. My system environment is xp/apache 5.3 + / php_pdo_sqlsrv_53 / mssql2000
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2760