Ticket #1792: fix-parse-between.diff
| File fix-parse-between.diff, 3.5 KB (added by ajbrown, 14 months ago) |
|---|
|
-
tests/QueryTestCase.php
32 32 */ 33 33 class Doctrine_Query_TestCase extends Doctrine_UnitTestCase 34 34 { 35 35 36 36 public function testWhereInSupportInDql() 37 37 { 38 38 $q = Doctrine_Query::create() … … 300 300 $q1->free(); 301 301 $q2->free(); 302 302 } 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 } 303 319 } 304 320 305 321 -
tests/models/QueryTest_Subscription.php
1 <?php 2 class QueryTest_Subscription extends Doctrine_Record 3 { 4 public function setTableDefinition() 5 { $this->hasColumn('id', 'integer', 4, array('primary', 'autoincrement', 'notnull')); 6 $this->hasColumn('begin', 'date'); 7 $this->hasColumn('end', 'date'); 8 } 9 } -
tests/models/QueryTest_User.php
7 7 $this->hasColumn('username as username', 'string', 50, 8 8 array('notnull')); 9 9 $this->hasColumn('visibleRankId', 'integer', 4); 10 $this->hasColumn('subscriptionId', 'integer', 4); 10 11 } 11 12 12 13 /** … … 17 18 $this->hasOne('QueryTest_Rank as visibleRank', array( 18 19 'local' => 'visibleRankId', 'foreign' => 'id' 19 20 )); 21 22 $this->hasOne('QueryTest_Subscription', array( 23 'local' => 'subscriptionId', 'foreign' => 'id' 24 )); 20 25 21 26 $this->hasMany('QueryTest_Rank as ranks', array( 22 27 'local' => 'userId', 'foreign' => 'rankId', 'refClass' => 'QueryTest_UserRank' -
lib/Doctrine/Query/Where.php
79 79 } 80 80 81 81 $sql = $this->_buildSql($leftExpr, $operator, $rightExpr); 82 82 83 83 84 //echo '<pre>Built SQL: '.$sql.'</pre>'; 84 85 … … 91 92 92 93 protected function _buildSql($leftExpr, $operator, $rightExpr) 93 94 { 94 // Left Expression95 95 96 $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 97 104 $op = strtolower($operator); 98 105 99 106 // Right Expression