Changeset 4794
- Timestamp:
- 08/23/08 11:20:10 (11 months ago)
- Location:
- branches/1.0
- Files:
-
- 4 modified
-
lib/Doctrine/Query.php (modified) (3 diffs)
-
lib/Doctrine/Query/Abstract.php (modified) (2 diffs)
-
tests/Query/CacheTestCase.php (modified) (1 diff)
-
tests/Query/LimitTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0/lib/Doctrine/Query.php
r4793 r4794 176 176 protected $_sql; 177 177 178 179 178 /** 180 179 * create … … 424 423 { 425 424 $tableAlias = $this->getTableAlias($componentAlias); 426 $table = $this->_queryComponents[$componentAlias]['table'];425 $table = $this->_queryComponents[$componentAlias]['table']; 427 426 428 427 if ( ! isset($this->_pendingFields[$componentAlias])) { … … 1069 1068 if ( ! empty($this->_sqlParts['limit']) && $this->_needsSubquery && 1070 1069 $table->getAttribute(Doctrine::ATTR_QUERY_LIMIT) == Doctrine::LIMIT_RECORDS) { 1071 $this->_isLimitSubqueryUsed = true; 1072 $needsSubQuery = true; 1070 // We do not need a limit-subquery if only fields from the root component are 1071 // selected and DISTINCT is used (i.e. DQL: SELECT DISTINCT u.id FROM User u LEFT JOIN u.phonenumbers LIMIT 5). 1072 if (count($this->_pendingFields) > 1 || ! isset($this->_pendingFields[$this->getRootAlias()]) 1073 || ! $this->_sqlParts['distinct']) { 1074 $this->_isLimitSubqueryUsed = true; 1075 $needsSubQuery = true; 1076 } 1073 1077 } 1074 1078 -
branches/1.0/lib/Doctrine/Query/Abstract.php
r4768 r4794 898 898 899 899 if ( ! $this->_view) { 900 if ($this->_queryCache || $this->_conn->getAttribute(Doctrine::ATTR_QUERY_CACHE)) {900 if ($this->_queryCache !== false && ($this->_queryCache || $this->_conn->getAttribute(Doctrine::ATTR_QUERY_CACHE))) { 901 901 $queryCacheDriver = $this->getQueryCacheDriver(); 902 902 // calculate hash for dql query … … 1651 1651 * @return Doctrine_Hydrate this object 1652 1652 */ 1653 public function useQueryCache(Doctrine_Cache_Interface $driver, $timeToLive = null) 1654 { 1653 public function useQueryCache($driver = true, $timeToLive = null) 1654 { 1655 if ($driver !== null && $driver !== true && $driver !== false && ! ($driver instanceOf Doctrine_Cache_Interface)) { 1656 $msg = 'First argument should be instance of Doctrine_Cache_Interface or null.'; 1657 throw new Doctrine_Query_Exception($msg); 1658 } 1655 1659 $this->_queryCache = $driver; 1660 1656 1661 return $this->setQueryCacheLifeSpan($timeToLive); 1657 1662 } -
branches/1.0/tests/Query/CacheTestCase.php
r4217 r4794 227 227 } 228 228 229 public function testQueryCacheCanBeDisabledForSingleQuery() 230 { 231 $cache = new Doctrine_Cache_Array(); 232 $q = new Doctrine_Query(); 233 $q->select('u.name')->from('User u')->leftJoin('u.Phonenumber p')->where('u.name = ?', 'walhala') 234 ->useQueryCache(false); 235 236 $coll = $q->execute(); 237 238 $this->assertEqual($cache->count(), 0); 239 $this->assertEqual(count($coll), 0); 240 241 $coll = $q->execute(); 242 243 $this->assertEqual($cache->count(), 0); 244 $this->assertEqual(count($coll), 0); 245 } 246 229 247 } -
branches/1.0/tests/Query/LimitTestCase.php
r4716 r4794 136 136 { 137 137 $q = new Doctrine_Query(); 138 $q->select('User.name')-> from('User')->where("User.Phonenumber.phonenumber LIKE '%123%'")->orderby('User.Email.address')->limit(5);138 $q->select('User.name')->distinct()->from('User')->where("User.Phonenumber.phonenumber LIKE '%123%'")->orderby('User.Email.address')->limit(5); 139 139 140 140 … … 302 302 $this->assertEqual($q->getSql(), "SELECT p.id AS p__id, p.name AS p__name, t.id AS t__id, t.tag AS t__tag FROM photo p LEFT JOIN phototag p2 ON p.id = p2.photo_id LEFT JOIN tag t ON t.id = p2.tag_id WHERE p.id IN (SELECT DISTINCT p3.id FROM photo p3 LEFT JOIN phototag p4 ON p3.id = p4.photo_id LEFT JOIN tag t2 ON t2.id = p4.tag_id ORDER BY t2.id DESC LIMIT 10) ORDER BY t.id DESC"); 303 303 } 304 305 public function testLimitSubqueryNotNeededIfSelectSingleFieldDistinct() 306 { 307 $q = new Doctrine_Query(); 308 $q->select('u.id')->distinct()->from('User u LEFT JOIN u.Phonenumber p'); 309 $q->where('u.name = ?'); 310 $q->limit(5); 311 312 $users = $q->execute(array('zYne')); 313 $this->assertEqual(1, $users->count()); 314 315 $this->assertEqual($q->getSql(), "SELECT DISTINCT e.id AS e__id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE e.name = ? AND (e.type = 0) LIMIT 5"); 316 } 304 317 }