Skip to content

Loading…

DDC-2193: Named native query bug? #2887

Open
doctrinebot opened this Issue · 8 comments

2 participants

@doctrinebot

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 "
@doctrinebot

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

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

Comment created by @FabioBatSilva:

Hi

Could you try to add a failing test case please ?

Cheers

@doctrinebot

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

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

Comment created by @FabioBatSilva:

Can't reproduce,

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

Cheers

@doctrinebot

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

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 + / phppdo_sqlsrv53 / mssql2000

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.