Changeset 5327

Show
Ignore:
Timestamp:
12/31/08 20:29:51 (6 months ago)
Author:
guilhermeblanco
Message:

[1.1] fixes #1792. Fixed usage of relation aliases in BETWEEN queries. Thanks for the great patch/work!

Location:
branches/1.1
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • branches/1.1/lib/Doctrine/Query/Where.php

    r5265 r5327  
    8080 
    8181            $sql = $this->_buildSql($leftExpr, $operator, $rightExpr); 
     82             
    8283 
    8384            //echo '<pre>Built SQL: '.$sql.'</pre>'; 
     
    9293    protected function _buildSql($leftExpr, $operator, $rightExpr) 
    9394    { 
    94         // Left Expression 
     95         
    9596        $leftExpr = $this->query->parseClause($leftExpr); 
    96  
     97         
     98        // BETWEEN operation 
     99        if ('BETWEEN' == strtoupper(substr($operator, 0, 7))) { 
     100            $midExpr = trim(substr($operator, 7, -3)); 
     101            $operator = 'BETWEEN ' . $this->query->parseClause($midExpr) . ' AND'; 
     102        } 
     103      
    97104        $op = strtolower($operator); 
    98105 
  • branches/1.1/tests/models/QueryTest_User.php

    r4857 r5327  
    88                array('notnull')); 
    99        $this->hasColumn('visibleRankId', 'integer', 4); 
     10        $this->hasColumn('subscriptionId', 'integer', 4); 
    1011    } 
    1112 
     
    1819            'local' => 'visibleRankId', 'foreign' => 'id' 
    1920        )); 
     21         
     22        $this->hasOne('QueryTest_Subscription', array( 
     23            'local' => 'subscriptionId', 'foreign' => 'id' 
     24        )); 
    2025 
    2126        $this->hasMany('QueryTest_Rank as ranks', array( 
  • branches/1.1/tests/QueryTestCase.php

    r5014 r5327  
    3333class Doctrine_Query_TestCase extends Doctrine_UnitTestCase  
    3434{ 
    35  
     35     
    3636    public function testWhereInSupportInDql() 
    3737    { 
     
    301301        $q2->free(); 
    302302    } 
     303     
     304    public function testParseTableAliasesWithBetweenInWhereClause() 
     305    { 
     306         
     307        $q1 = Doctrine_Query::create() 
     308            ->select('u.id') 
     309            ->from('QueryTest_User u') 
     310            ->where("CURRENT_DATE() BETWEEN u.QueryTest_Subscription.begin AND u.QueryTest_Subscription.begin") 
     311            ->addWhere( 'u.id != 5' ) 
     312            ; 
     313             
     314        $expected = 'SELECT q.id AS q__id FROM query_test__user q LEFT JOIN query_test__subscription q2 ON q.subscriptionid = q2.id WHERE CURRENT_DATE() BETWEEN q2.begin AND q2.begin AND q.id != 5'; 
     315         
     316        $this->assertEqual( $q1->getSql(), $expected ); 
     317         
     318    }  
    303319} 
    304320