Details

    • Type: Bug Bug
    • Status: Awaiting Feedback
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

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

        Activity

        Hide
        dingdangjyz added a comment -

        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

        Show
        dingdangjyz added a comment - 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
        Hide
        Benjamin Eberlei added a comment -

        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?

        Show
        Benjamin Eberlei added a comment - 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?
        Hide
        Fabio B. Silva added a comment -

        Can't reproduce,

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

        Cheers

        Show
        Fabio B. Silva added a comment - Can't reproduce, Could you try to change the attached test case and make it fail. Cheers
        Hide
        dingdangjyz added a comment -

        @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

        Show
        dingdangjyz added a comment - @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
        Hide
        dingdangjyz added a comment -

        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;
            }
        }
        
        Show
        dingdangjyz added a comment - 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; } }
        Hide
        Fabio B. Silva added a comment -

        Hi

        Could you try to add a failing test case please ?

        Cheers

        Show
        Fabio B. Silva added a comment - Hi Could you try to add a failing test case please ? Cheers
        Hide
        dingdangjyz added a comment -

        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],
                    );
        
        Show
        dingdangjyz added a comment - 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], );
        Hide
        Fabio B. Silva added a comment -

        Hi

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

        Could you provide more details please?

        Cheers

        Show
        Fabio B. Silva added a comment - Hi Doctrine does not change the native query at all The problem seems related with database connection. Could you provide more details please? Cheers

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            dingdangjyz
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: