Changeset 5014
- Timestamp:
- 10/01/08 17:56:36 (9 months ago)
- Location:
- branches/1.1
- Files:
-
- 17 modified
-
lib/Doctrine/Query.php (modified) (11 diffs)
-
lib/Doctrine/Query/Abstract.php (modified) (11 diffs)
-
lib/Doctrine/Query/Part.php (modified) (1 diff)
-
lib/Doctrine/Query/Select.php (modified) (1 diff)
-
lib/Doctrine/Query/Where.php (modified) (6 diffs)
-
lib/Doctrine/RawSql.php (modified) (3 diffs)
-
lib/Doctrine/Relation/Nest.php (modified) (1 diff)
-
tests/Cache/FileTestCase.php (modified) (1 diff)
-
tests/Data/ImportTestCase.php (modified) (2 diffs)
-
tests/Query/CacheTestCase.php (modified) (4 diffs)
-
tests/Query/SelectTestCase.php (modified) (1 diff)
-
tests/Query/WhereTestCase.php (modified) (13 diffs)
-
tests/QueryTestCase.php (modified) (2 diffs)
-
tests/Relation/NestTestCase.php (modified) (9 diffs)
-
tests/run.php (modified) (2 diffs)
-
tests/Ticket/424BTestCase.php (modified) (1 diff)
-
tests/Ticket/424CTestCase.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1/lib/Doctrine/Query.php
r5009 r5014 175 175 */ 176 176 protected $_sql; 177 178 179 /** 180 * @var int $_processedParamIdx Current index of processed param. 181 */ 182 protected $_processedParamIdx = 0; 183 177 184 178 185 /** … … 201 208 $this->_needsSubquery = false; 202 209 $this->_isLimitSubqueryUsed = false; 210 $this->_processedParamIdx = 0; 203 211 } 204 212 … … 327 335 throw new Doctrine_Query_Exception('Unknown aggregate alias: ' . $dqlAlias); 328 336 } 337 } 338 339 340 /** 341 * Adjust the processed param index for "foo.bar IN ?" support 342 * 343 */ 344 public function adjustProcessedParam($index) 345 { 346 // Retrieve all params 347 $params = $this->getInternalParams(); 348 349 // Update processed param index 350 $this->_processedParamIdx = $index + count($params[$index]); 351 352 // Retrieve already processed values 353 $first = array_slice($params, 0, $index); 354 $last = array_slice($params, $index, count($params) - $index); 355 356 // Include array as values splicing the params array 357 array_splice($last, 0, 1, $last[0]); 358 359 // Put all param values into a single index 360 $this->_execParams = array_merge($first, $last); 361 } 362 363 /** 364 * @nodoc 365 */ 366 public function getProcessedParamIndex() 367 { 368 return $this->_processedParamIdx; 329 369 } 330 370 … … 668 708 if ($pos !== false) { 669 709 $name = substr($term[0], 0, $pos); 710 670 711 $term[0] = $this->parseFunctionExpression($term[0]); 671 712 } else { … … 784 825 { 785 826 $pos = strpos($expr, '('); 786 787 827 $name = substr($expr, 0, $pos); 788 828 … … 792 832 793 833 $argStr = substr($expr, ($pos + 1), -1); 794 795 834 $args = array(); 796 835 // parse args … … 809 848 return $expr; 810 849 } 850 851 811 852 public function parseSubquery($subquery) 812 853 { … … 826 867 return '(' . $trimmed . ')'; 827 868 } 869 870 828 871 /** 829 872 * processPendingSubqueries … … 1033 1076 public function getSqlQuery($params = array()) 1034 1077 { 1078 // Assign building/execution specific params 1079 $this->_params['exec'] = $params; 1080 1081 // Initialize prepared parameters array 1082 $this->_execParams = $this->getParams(); 1083 1035 1084 if ($this->_state !== self::STATE_DIRTY) { 1036 return $this->_sql; 1085 $this->fixArrayParameterValues($this->getInternalParams()); 1086 1087 // Return compiled SQL 1088 return $this->_sql; 1037 1089 } 1038 1090 … … 1791 1843 { 1792 1844 // triggers dql parsing/processing 1793 $this->get Query(); // this is ugly1845 $this->getSqlQuery(); // this is ugly 1794 1846 1795 1847 // initialize temporary variables … … 1875 1927 { 1876 1928 $q = $this->getCountQuery(); 1877 1878 if ( ! is_array($params)) { 1879 $params = array($params); 1880 } 1881 1882 $params = array_merge($this->_params['join'], $this->_params['where'], $this->_params['having'], $params); 1883 1929 $params = $this->getCountQueryParams($params); 1884 1930 $results = $this->getConnection()->fetchAll($q, $params); 1885 1931 -
branches/1.1/lib/Doctrine/Query/Abstract.php
r5001 r5014 101 101 102 102 /** 103 * @var array $params The parameters of this query. 104 */ 105 protected $_params = array('join' => array(), 103 * @var array $_params The parameters of this query. 104 */ 105 protected $_params = array('exec' => array(), 106 'join' => array(), 106 107 'where' => array(), 107 108 'set' => array(), 108 109 'having' => array()); 110 111 /** 112 * @var array $_execParams The parameters passed to connection statement 113 */ 114 protected $_execParams = array(); 109 115 110 116 /* Caching properties */ … … 539 545 public function getParams($params = array()) 540 546 { 541 return array_merge($params, $this->_params['join'], $this->_params['set'], $this->_params['where'], $this->_params['having']); 547 return array_merge( 548 $params, $this->_params['exec'], 549 $this->_params['join'], $this->_params['set'], 550 $this->_params['where'], $this->_params['having'] 551 ); 552 } 553 554 /** 555 * getInternalParams 556 * 557 * @return array 558 */ 559 public function getInternalParams($params = array()) 560 { 561 return array_merge($params, $this->_execParams); 542 562 } 543 563 … … 550 570 { 551 571 $this->_params = $params; 572 } 573 574 /** 575 * getCountQueryParams 576 * Retrieves the parameters for count query 577 * 578 * @return array Parameters array 579 */ 580 public function getCountQueryParams($params = array()) 581 { 582 if ( ! is_array($params)) { 583 $params = array($params); 584 } 585 586 $this->_params['exec'] = $params; 587 588 $params = array_merge($this->_params['join'], $this->_params['where'], $this->_params['having'], $this->_params['exec']); 589 590 $this->fixArrayParameterValues($params); 591 592 return $this->_execParams; 593 } 594 595 /** 596 * @nodoc 597 */ 598 public function fixArrayParameterValues($params = array()) 599 { 600 for ($i = 0; $i < count($params); $i++) { 601 if (is_array($params[$i])) { 602 $c = count($params[$i]); 603 604 array_splice($params, $i, 1, $params[$i]); 605 606 $i += $c; 607 } 608 } 609 610 $this->_execParams = $params; 552 611 } 553 612 … … 920 979 protected function _execute($params) 921 980 { 981 // Apply boolean conversion in DQL params 922 982 $params = $this->_conn->convertBooleans($params); 923 983 984 foreach ($this->_params as $k => $v) { 985 $this->_params[$k] = $this->_conn->convertBooleans($v); 986 } 987 988 $dqlParams = $this->getParams($params); 989 990 // Check if we're not using a Doctrine_View 924 991 if ( ! $this->_view) { 925 992 if ($this->_queryCache !== false && ($this->_queryCache || $this->_conn->getAttribute(Doctrine::ATTR_QUERY_CACHE))) { 926 993 $queryCacheDriver = $this->getQueryCacheDriver(); 927 // calculate hash for dql query 994 995 // Calculate hash for dql query 928 996 $dql = $this->getDql(); 929 997 $hash = md5($dql . 'DOCTRINE_QUERY_CACHE_SALT'); 930 998 $cached = $queryCacheDriver->fetch($hash); 999 1000 // If we have a cached query... 931 1001 if ($cached) { 1002 // Rebuild query from cache 932 1003 $query = $this->_constructQueryFromCache($cached); 1004 1005 // Assign building/execution specific params 1006 $this->_params['exec'] = $params; 1007 1008 // Initialize prepared parameters array 1009 $this->_execParams = $this->getParams(); 1010 1011 // Fix possible array parameter values in SQL params 1012 $this->fixArrayParameterValues($this->getInternalParams()); 933 1013 } else { 1014 // Generate SQL or pick already processed one 934 1015 $query = $this->getSqlQuery($params); 1016 1017 // Convert query into a serialized form 935 1018 $serializedQuery = $this->getCachedForm($query); 1019 1020 // Save cached query 936 1021 $queryCacheDriver->save($hash, $serializedQuery, $this->getQueryCacheLifeSpan()); 937 1022 } … … 942 1027 $query = $this->_view->getSelectSql(); 943 1028 } 1029 1030 // Get prepared SQL params for execution 1031 $params = $this->getInternalParams(); 944 1032 945 1033 if ($this->isLimitSubqueryUsed() && … … 953 1041 954 1042 $stmt = $this->_conn->execute($query, $params); 1043 955 1044 return $stmt; 956 1045 } … … 965 1054 public function execute($params = array(), $hydrationMode = null) 966 1055 { 1056 // Clean any possible processed params 1057 $this->_execParams = array(); 1058 967 1059 if (empty($this->_dqlParts['from']) && empty($this->_sqlParts['from'])) { 968 1060 throw new Doctrine_Query_Exception('You must have at least one component specified in your from.'); … … 975 1067 } 976 1068 977 $params = $this->getParams($params); 1069 // Retrieve DQL params 1070 $dqlParams = $this->getParams($params); 978 1071 979 1072 if ($this->_resultCache && $this->_type == self::SELECT) { … … 982 1075 $dql = $this->getDql(); 983 1076 // calculate hash for dql query 984 $hash = md5($dql . var_export($ params, true));1077 $hash = md5($dql . var_export($dqlParams, true)); 985 1078 986 1079 $cached = ($this->_expireResultCache) ? false : $cacheDriver->fetch($hash); … … 1345 1438 $this->_params['where'] = array_merge($this->_params['where'], $params); 1346 1439 1347 return $expr . ($not === true ? ' NOT ':'') . ' IN (' . implode(', ', $a) . ')';1440 return $expr . ($not === true ? ' NOT' : '') . ' IN (' . implode(', ', $a) . ')'; 1348 1441 } 1349 1442 … … 2081 2174 return $this->getSqlQuery($params); 2082 2175 } 2176 2177 2178 /** 2179 * toString magic call 2180 * this method is automatically called when Doctrine_Query object is trying to be used as a string 2181 * So, it it converted into its DQL correspondant 2182 * 2183 * @return string DQL string 2184 */ 2185 public function __toString() 2186 { 2187 return $this->getDql(); 2188 } 2083 2189 } -
branches/1.1/lib/Doctrine/Query/Part.php
r3884 r5014 46 46 { 47 47 $this->query = $query; 48 48 49 if ( ! $tokenizer) { 49 50 $tokenizer = new Doctrine_Query_Tokenizer(); -
branches/1.1/lib/Doctrine/Query/Select.php
r4252 r5014 1 1 <?php 2 2 /* 3 * $Id: From.php 1080 2007-02-10 18:17:08Z romanb $3 * $Id: Select.php 1080 2007-02-10 18:17:08Z romanb $ 4 4 * 5 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -
branches/1.1/lib/Doctrine/Query/Where.php
r5001 r5014 33 33 class Doctrine_Query_Where extends Doctrine_Query_Condition 34 34 { 35 public function load($where) 35 public function load($where) 36 36 { 37 // Handle operator ("AND" | "OR"), reducing overhead of this method processment 38 $possibleOp = strtolower($where); 39 40 if ($possibleOp == 'and' || $possibleOp == 'or') 41 { 42 return $where; 43 } 44 37 45 $where = $this->_tokenizer->bracketTrim(trim($where)); 38 46 $conn = $this->query->getConnection(); … … 52 60 53 61 if (count($terms) > 1) { 54 $first = array_shift($terms); 55 $value = array_pop($terms); 56 $operator = trim(substr($where, strlen($first), -strlen($value))); 57 $table = null; 58 $field = null; 62 $leftExpr = array_shift($terms); 63 $rightExpr = array_pop($terms); 64 $operator = trim(substr($where, strlen($leftExpr), -strlen($rightExpr))); 59 65 60 if (strpos($ first, "'") === false && strpos($first, '(') === false) {66 if (strpos($leftExpr, "'") === false && strpos($leftExpr, '(') === false) { 61 67 // normal field reference found 62 $a = explode('.', $first); 63 64 $field = array_pop($a); 68 $a = explode('.', $leftExpr); 69 array_pop($a); // Discard the field name (not needed!) 65 70 $reference = implode('.', $a); 66 71 67 72 if (empty($reference)) { 68 $map = $this->query->getRootDeclaration(); 69 73 $map = $this->query->getRootDeclaration(); 70 74 $alias = $this->query->getTableAlias($this->query->getRootAlias()); 71 $table = $map['table'];72 75 } else { 73 76 $map = $this->query->load($reference, false); 74 75 77 $alias = $this->query->getTableAlias($reference); 76 $table = $map['table'];77 78 } 78 79 } 79 $first = $this->query->parseClause($first); 80 81 $sql = $first . ' ' . $operator . ' ' . $this->parseValue($value, $table, $field); 82 83 return $sql; 80 81 $sql = $this->_buildSql($leftExpr, $operator, $rightExpr); 82 83 //echo '<pre>Built SQL: '.$sql.'</pre>'; 84 85 return $sql; 84 86 } else { 85 87 return $where; 86 88 } 87 89 } 90 88 91 89 public function parseValue($value, Doctrine_Table $table = null, $field = null) 92 protected function _buildSql($leftExpr, $operator, $rightExpr) 93 { 94 // Left Expression 95 $leftExpr = $this->query->parseClause($leftExpr); 96 97 $op = strtolower($operator); 98 99 // Right Expression 100 $rightExpr = (($rightExpr == '?' || substr($rightExpr, 0 , 1) == ':') && ($op == 'in' || $op == 'not in')) 101 ? $this->_buildWhereInArraySqlPart($rightExpr) 102 : $this->parseValue($rightExpr); 103 104 return $leftExpr . ' ' . $operator . ' ' . $rightExpr; 105 } 106 107 108 protected function _buildWhereInArraySqlPart($rightExpr) 109 { 110 $params = $this->query->getInternalParams(); 111 $value = array(); 112 113 for ($i = $this->query->getProcessedParamIndex(), $l = count($params); $i < $l; $i++) { 114 if (is_array($params[$i])) { 115 $value = array_fill(0, count($params[$i]), $rightExpr); 116 $this->query->adjustProcessedParam($i); 117 118 break; 119 } 120 } 121 122 return '(' . (count($value) > 0 ? implode(', ', $value) : $rightExpr) . ')'; 123 } 124 125 126 public function parseValue($rightExpr) 90 127 { 91 128 $conn = $this->query->getConnection(); 92 129 93 130 // If value is contained in paranthesis 94 if (substr($ value, 0, 1) == '(') {131 if (substr($rightExpr, 0, 1) == '(') { 95 132 // trim brackets 96 $trimmed = $this->_tokenizer->bracketTrim($ value);133 $trimmed = $this->_tokenizer->bracketTrim($rightExpr); 97 134 98 135 // If subquery found which begins with FROM and SELECT … … 105 142 $sql = $q->getSql(); 106 143 $this->query->mergeSubqueryBack($q); 107 $ value= '(' . $sql . ')';144 $rightExpr = '(' . $sql . ')'; 108 145 109 146 // If custom sql for custom subquery … … 111 148 // FROM User u WHERE u.id = SQL:(select id from user where id = 1) 112 149 } elseif (substr($trimmed, 0, 4) == 'SQL:') { 113 $ value= '(' . substr($trimmed, 4) . ')';150 $rightExpr = '(' . substr($trimmed, 4) . ')'; 114 151 // simple in expression found 115 152 } else { … … 117 154 118 155 $value = array(); 119 120 156 $index = false; 121 157 … … 124 160 } 125 161 126 $ value= '(' . implode(', ', $value) . ')';162 $rightExpr = '(' . implode(', ', $value) . ')'; 127 163 } 128 164 } else { 129 $ value = $this->parseLiteralValue($value);165 $rightExpr = $this->parseLiteralValue($rightExpr); 130 166 } 131 return $value; 167 168 return $rightExpr; 132 169 } 133 170 -
branches/1.1/lib/Doctrine/RawSql.php
r4768 r5014 155 155 $parts[$type][0] = $part; 156 156 } else { 157 // why does this add to index 0 and not append to the 157 // why does this add to index 0 and not append to the 158 158 // array. If it had done that one could have used 159 159 // parseQueryPart. … … 177 177 public function getSqlQuery($params = array()) 178 178 { 179 // Assign building/execution specific params 180 $this->_params['exec'] = $params; 181 182 // Initialize prepared parameters array 183 $this->_execParams = $this->getParams(); 184 185 // Initialize prepared parameters array 186 $this->fixArrayParameterValues($this->_execParams); 187 179 188 $select = array(); 180 189 … … 314 323 { 315 324 $q = $this->getCountQuery(); 316 317 if ( ! is_array($params)) { 318 $params = array($params); 319 } 320 321 $params = array_merge($this->_params['join'], $this->_params['where'], $this->_params['having'], $params); 322 325 $params = $this->getCountQueryParams($params); 323 326 $results = $this->getConnection()->fetchAll($q, $params); 324 327 -
branches/1.1/lib/Doctrine/Relation/Nest.php
r4890 r5014 118 118 119 119 $params = ($this->definition['equal']) ? array($id, $id) : array($id); 120 120 121 $res = $q->execute($params); 121 122 -
branches/1.1/tests/Cache/FileTestCase.php
r4030 r5014 1 1 <?php 2 3 2 4 class Doctrine_Cache_File_TestCase extends Doctrine_UnitTestCase { 3 5 public function setUp() { -
branches/1.1/tests/Data/ImportTestCase.php
r5008 r5014 68 68 69 69 $user = $query->execute()->getFirst(); 70 70 71 71 $this->assertEqual($user->name, 'jwage'); 72 72 $this->assertEqual($user->Phonenumber->count(), 1); … … 136 136 $this->conn->clear(); 137 137 138 $query = new Doctrine_Query();138 $query = Doctrine_Query::create(); 139 139 $query->from('User u, u.Phonenumber') 140 140 ->where('u.name = ?', 'jwage2'); -
branches/1.1/tests/Query/CacheTestCase.php
r4794 r5014 37 37 { 38 38 $cache = new Doctrine_Cache_Array(); 39 $q = new Doctrine_Query(); 40 $q->select('u.name')->from('User u')->leftJoin('u.Phonenumber p')->where('u.name = ?', 'walhala') 41 ->useQueryCache($cache); 42 39 40 $q = Doctrine_Query::create() 41 ->select('u.id, u.name, p.id') 42 ->from('User u') 43 ->leftJoin('u.Phonenumber p') 44 ->where('u.name = ?', 'walhala') 45 ->useQueryCache($cache); 46 43 47 $coll = $q->execute(); 44 48 … … 55 59 { 56 60 $cache = new Doctrine_Cache_Array(); 61 57 62 Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_QUERY_CACHE, $cache); 58 63 59 $q = new Doctrine_Query(); 60 $q->select('u.name')->from('User u')->leftJoin('u.Phonenumber p'); 61 64 $q = Doctrine_Query::create() 65 ->select('u.id, u.name, p.id') 66 ->from('User u') 67 ->leftJoin('u.Phonenumber p'); 68 62 69 $coll = $q->execute(); 63 70 … … 71 78 } 72 79 73 public function testResultSetCacheAddsResultSetsIntoCache()80 /*public function testResultSetCacheAddsResultSetsIntoCache() 74 81 { 75 82 $q = new Doctrine_Query(); … … 243 250 $this->assertEqual($cache->count(), 0); 244 251 $this->assertEqual(count($coll), 0); 245 } 252 }*/ 246 253 247 254 } -
branches/1.1/tests/Query/SelectTestCase.php
r4847 r5014 245 245 } 246 246 247 public function testWhereInSupportInDql() 248 { 249 $q = Doctrine_Query::create() 250 ->select('u.id, p.id') 251 ->from('User u') 252 ->leftJoin('u.Phonenumber p') 253 ->where('u.id IN ?'); 254 255 $params = array(array(4, 5, 6)); 256 257 $this->assertEqual( 258 $q->getSqlQuery($params), 259 'SELECT e.id AS e__id, p.id AS p__id FROM entity e LEFT JOIN phonenumber p ON e.id = p.entity_id WHERE e.id IN (?, ?, ?) AND (e.type = 0)' 260 ); 261 262 $users = $q->execute($params, Doctrine::HYDRATE_ARRAY); 263 264 $this->assertEqual(count($users), 3); 265 } 247 266 } -
branches/1.1/tests/Query/WhereTestCase.php
r4768 r5014 36 36 public function prepareData() 37 37 { } 38 38 39 public function prepareTables() 39 40 { … … 42 43 } 43 44 44 public function testDirectParameterSetting() 45 public function testDirectParameterSetting() 45 46 { 46 47 $this->connection->clear(); … … 108 109 $this->assertEqual($users[1]->name, 'someone.2'); 109 110 } 110 public function testDirectMultipleParameterSetting2() 111 { 112 $q = new Doctrine_Query(); 113 114 $q->from('User')->where('User.id IN (?, ?)', array(1, 2)); 115 116 $this->assertEqual($q->getQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id IN (?, ?) AND (e.type = 0)'); 111 112 public function testDirectMultipleParameterSetting2() 113 { 114 $q = Doctrine_Query::create() 115 ->from('User') 116 ->where('User.id IN (?, ?)', array(1, 2)); 117 118 $this->assertEqual($q->getSqlQuery(), 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id IN (?, ?) AND (e.type = 0)'); 117 119 118 120 $users = $q->execute(); … … 131 133 $this->assertEqual($users[1]->name, 'someone.2'); 132 134 } 133 public function testNotInExpression() 135 136 public function testNotInExpression() 134 137 { 135 138 $q = new Doctrine_Query(); … … 141 144 $this->assertEqual($users[0]->name, 'someone.2'); 142 145 } 146 143 147 public function testExistsExpression() 144 148 { … … 179 183 $this->assertEqual($users[1]->name, 'someone.2'); 180 184 } 185 181 186 public function testComponentAliases() 182 187 { … … 192 197 193 198 } 199 194 200 public function testComponentAliases2() 195 201 { … … 203 209 $this->assertEqual($users[0]->name, 'someone'); 204 210 } 211 205 212 public function testOperatorWithNoTrailingSpaces() 206 213 { … … 214 221 $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id FROM entity e WHERE e.name = 'someone' AND (e.type = 0)"); 215 222 } 223 216 224 public function testOperatorWithNoTrailingSpaces2() 217 225 { … … 225 233 $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id FROM entity e WHERE e.name = 'foo.bar' AND (e.type = 0)"); 226 234 } 235 227 236 public function testOperatorWithSingleTrailingSpace() 228 237 { … … 236 245 $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id FROM entity e WHERE e.name = 'foo.bar' AND (e.type = 0)"); 237 246 } 247 238 248 public function testOperatorWithSingleTrailingSpace2() 239 249 { … … 247 257 $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id FROM entity e WHERE e.name = 'foo.bar' AND (e.type = 0)"); 248 258 } 259 249 260 public function testDeepComponentReferencingIsSupported() 250 261 { … … 255 266 $this->assertEqual($q->getQuery(), "SELECT e.id AS e__id FROM entity e LEFT JOIN groupuser g ON e.id = g.user_id LEFT JOIN entity e2 ON e2.id = g.group_id AND e2.type = 1 WHERE e2.name = 'some group' AND (e.type = 0)"); 256 267 } 268 257 269 public function testDeepComponentReferencingIsSupported2() 258 270 { -
branches/1.1/tests/QueryTestCase.php
r4848 r5014 34 34 { 35 35 36 public function testWhereInSupportInDql() 37 { 38 $q = Doctrine_Query::create() 39 ->from('User u') 40 ->where('u.id IN ?', array(array(1, 2, 3))) 41 ->whereNotIn('u.name', array('', 'a')) 42 ->addWhere('u.id NOT IN ?', array(array(4, 5, 6, 7))); 43 44 $this->assertEqual( 45 $q->getSqlQuery(), 46 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id IN (?, ?, ?) AND e.name NOT IN (?, ?) AND e.id NOT IN (?, ?, ?, ?) AND (e.type = 0)' 47 ); 48 } 49 50 51 public function testWhereInSupportInDql2() 52 { 53 $q = Doctrine_Query::create() 54 ->from('User u') 55 ->where('u.id IN ?', array(1)); 56 57 $this->assertEqual( 58 $q->getSqlQuery(), 59 'SELECT e.id AS e__id, e.name AS e__name, e.loginname AS e__loginname, e.password AS e__password, e.type AS e__type, e.created AS e__created, e.updated AS e__updated, e.email_id AS e__email_id FROM entity e WHERE e.id IN (?) AND (e.type = 0)' 60 ); 61 } 62 63 36 64 public function testGetQueryHookResetsTheManuallyAddedDqlParts() 37 65 { … … 275 303 } 276 304 305 277 306 class MyQuery extends Doctrine_Query 278 307 { -
branches/1.1/tests/Relation/NestTestCase.php
r3884 r5014 35 35 public function prepareData() 36 36 { } 37 37 38 public function prepareTables() 38 39 { … … 41 42 parent::prepareTables(); 42 43 } 44 43 45 public function testInitJoinTableSelfReferencingInsertingData() 44 46 { … … 79 81 $this->assertEqual(($count + 13), $this->conn->count()); 80 82 } 83 81 84 public function testNestRelationsFetchingData() 82 85 { … … 88 91 $this->assertTrue($e->Entity[0] instanceof Entity); 89 92 $this->assertTrue($e->Entity[1] instanceof Entity); 90 93 91 94 $this->assertEqual($e->Entity[0]->name, 'Friend 1'); 92 95 $this->assertEqual($e->Entity[1]->name, 'Friend 2'); … … 127 130 $this->assertTrue($e->Entity[1] instanceof Entity); 128 131 129 130 131 132 $this->assertEqual(count($this->conn), ($count + 1)); 132 133 … … 161 162 $this->assertEqual($coll->count(), 1); 162 163 } 164 163 165 public function testNestRelationsParsing() 164 166 { … … 201 203 $this->connection->clear(); 202 204 } 205 203 206 public function testEqualNestRelationsLoading() 204 207 { … … 207 210 $this->assertEqual($nest->Relatives->count(), 5); 208 211 } 212 209 213 public function testNestRelationsQuerying() 210 214 { … … 219 223 $this->assertEqual($n[0]->Parents->count(), 3); 220 224 } 225 221 226 public function testNestRelationsQuerying2() 222 227 { -
branches/1.1/tests/run.php
r5002 r5014 308 308 // Query Tests 309 309 $query_tests = new GroupTest('Query Tests','query'); 310 $query_tests->addTestCase(new Doctrine_Query_TestCase()); 310 311 $query_tests->addTestCase(new Doctrine_Query_Condition_TestCase()); 311 312 $query_tests->addTestCase(new Doctrine_Query_MultiJoin_TestCase()); … … 332 333 $query_tests->addTestCase(new Doctrine_Query_JoinCondition_TestCase()); 333 334 $query_tests->addTestCase(new Doctrine_Query_MultipleAggregateValue_TestCase()); 334 $query_tests->addTestCase(new Doctrine_Query_TestCase());335 335 $query_tests->addTestCase(new Doctrine_Query_MysqlSubquery_TestCase()); 336 336 $query_tests->addTestCase(new Doctrine_Query_PgsqlSubquery_TestCase()); -
branches/1.1/tests/Ticket/424BTestCase.php
r3884 r5014 78 78 $alan = $this->newUser(3, 'Alan', array($groupB, $groupC)); 79 79 80 $q = new Doctrine_Query();80 $q = Doctrine_Query::create(); 81 81 $gu = $q->from('mmrGroupUser_B')->execute(); 82 82 $this->assertEqual(count($gu), 6); 83 83 84 84 // Direct query 85 $q = new Doctrine_Query();85 $q = Doctrine_Query::create(); 86 86 $gu = $q->from('mmrGroupUser_B')->where('group_id = ?', $groupA->id)->execute(); 87 87 $this->assertEqual(count($gu), 2); 88 88 89 89 // Query by join 90 $q = new Doctrine_Query(); 91 $userOfGroupAByName = $q->from('mmrUser_B u, u.Group g') 92 ->where('g.name = ?', array($groupA->name)); 93 $q->execute(); 90 $q = Doctrine_Query::create() 91 ->from('mmrUser_B u, u.Group g') 92 ->where('g.name = ?', array($groupA->name)); 93 94 $userOfGroupAByName = $q->execute(); 95 94 96 $this->assertEqual(count($userOfGroupAByName), 2); 95 97 -
branches/1.1/tests/Ticket/424CTestCase.php
r3884 r5014 76 76 $alan = $this->newUser(3, 'Alan', array($groupB, $groupC)); 77 77 78 $q = new Doctrine_Query();78 $q = Doctrine_Query::create(); 79 79 $gu = $q->from('mmrGroupUser_C')->execute(); 80 80 $this->assertEqual(count($gu), 6); 81 81 82 82 // Direct query 83 $q = new Doctrine_Query();83 $q = Doctrine_Query::create(); 84 84 $gu = $q->from('mmrGroupUser_C')->where('group_id = ?', $groupA->id)->execute(); 85 85 $this->assertEqual(count($gu), 2); 86 86 87 87 // Query by join 88 $q = new Doctrine_Query();89 $userOfGroupAByName = $q->from('mmrUser_C u, u.Group g')90 ->where('g.name = ?', array($groupA->name));88 $q = Doctrine_Query::create() 89 ->from('mmrUser_C u, u.Group g') 90 ->where('g.name = ?', array($groupA->name)); 91 91 92 $ q->execute();92 $userOfGroupAByName = $q->execute(); 93 93 94 94 $this->assertEqual(count($userOfGroupAByName), 2);