Doctrine Project

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Doctrine 2 - ORM
  • Doctrine 2 - ORM
  • DDC-2193

Named native query bug?

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Awaiting Feedback 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 "
  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. File
    DDC2193Test.php
    16/Dec/12 8:48 PM
    2 kB
    Fabio B. Silva

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • History
  • Activity
  • Source
Fabio B. Silva made changes - 12/Dec/12 1:49 PM
Field Original Value New Value
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 "
@NamedNativeQueries is a useful thing, but I have found some problems during my using.
1、Normal
{code}
 /**
 * @NamedNativeQueries({
 * @NamedNativeQuery(
 * name = "fetchMultipleJoinsEntityResults",
 * resultSetMapping= "mappingMultipleJoinsEntityResults",
 * query = "SELECT * FROM test "
 * )
 * })
 */
{code}
2、Error,cannot connect to the server
{code}
 /**
 * @NamedNativeQueries({
 * @NamedNativeQuery(
 * name = "fetchMultipleJoinsEntityResults",
 * resultSetMapping= "mappingMultipleJoinsEntityResults",
 * query = "SELECT *
            FROM test "
 * )
 * })
 */
{code}
3、Cannot use alias.The same problem as the second one.
{code}
.......
 query = "SELECT a as test FROM test "
{code}
Hide
Permalink
Fabio B. Silva added a comment - 12/Dec/12 1:56 PM

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 - 12/Dec/12 1:56 PM Hi Doctrine does not change the native query at all The problem seems related with database connection. Could you provide more details please? Cheers
Hide
Permalink
dingdangjyz added a comment - 13/Dec/12 1:12 AM

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 - 13/Dec/12 1:12 AM 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
Permalink
Fabio B. Silva added a comment - 13/Dec/12 10:59 AM

Hi

Could you try to add a failing test case please ?

Cheers

Show
Fabio B. Silva added a comment - 13/Dec/12 10:59 AM Hi Could you try to add a failing test case please ? Cheers
Hide
Permalink
dingdangjyz added a comment - 14/Dec/12 2:06 AM

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 - 14/Dec/12 2:06 AM 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
Permalink
dingdangjyz added a comment - 14/Dec/12 7:59 AM

@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 - 14/Dec/12 7:59 AM @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
Fabio B. Silva made changes - 16/Dec/12 8:48 PM
Attachment DDC2193Test.php [ 11363 ]
Hide
Permalink
Fabio B. Silva added a comment - 16/Dec/12 8:50 PM

Can't reproduce,

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

Cheers

Show
Fabio B. Silva added a comment - 16/Dec/12 8:50 PM Can't reproduce, Could you try to change the attached test case and make it fail. Cheers
Hide
Permalink
Benjamin Eberlei added a comment - 24/Dec/12 9:22 AM

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 - 24/Dec/12 9:22 AM 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?
Fabio B. Silva made changes - 26/Dec/12 8:37 PM
Status Open [ 1 ] Awaiting Feedback [ 10000 ]
Hide
Permalink
dingdangjyz added a comment - 31/Dec/12 4:02 AM

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 - 31/Dec/12 4:02 AM 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
This list may be incomplete, as errors occurred whilst retrieving source from linked applications:
  • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2193, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

People

  • Assignee:
    Benjamin Eberlei
    Reporter:
    dingdangjyz
Vote (0)
Watch (3)

Dates

  • Created:
    11/Dec/12 1:43 AM
    Updated:
    31/Dec/12 4:02 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Doctrine Project. Try JIRA - bug tracking software for your team.