Total Complexity | 192 |
Total Lines | 2310 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Complex classes like SelectSqlGenerationTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SelectSqlGenerationTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class SelectSqlGenerationTest extends OrmTestCase |
||
26 | { |
||
27 | private $_em; |
||
28 | |||
29 | protected function setUp() |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Assert a valid SQL generation. |
||
36 | * |
||
37 | * @param string $dqlToBeTested |
||
38 | * @param string $sqlToBeConfirmed |
||
39 | * @param array $queryHints |
||
40 | * @param array $queryParams |
||
41 | */ |
||
42 | public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $queryHints = [], array $queryParams = []) |
||
43 | { |
||
44 | try { |
||
45 | $query = $this->_em->createQuery($dqlToBeTested); |
||
46 | |||
47 | foreach ($queryParams AS $name => $value) { |
||
48 | $query->setParameter($name, $value); |
||
49 | } |
||
50 | |||
51 | $query->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true) |
||
52 | ->useQueryCache(false); |
||
53 | |||
54 | foreach ($queryHints AS $name => $value) { |
||
55 | $query->setHint($name, $value); |
||
56 | } |
||
57 | |||
58 | $sqlGenerated = $query->getSQL(); |
||
59 | |||
60 | parent::assertEquals( |
||
61 | $sqlToBeConfirmed, |
||
62 | $sqlGenerated, |
||
63 | sprintf('"%s" is not equal of "%s"', $sqlGenerated, $sqlToBeConfirmed) |
||
64 | ); |
||
65 | |||
66 | $query->free(); |
||
67 | } catch (\Exception $e) { |
||
68 | $this->fail($e->getMessage() ."\n".$e->getTraceAsString()); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Asser an invalid SQL generation. |
||
74 | * |
||
75 | * @param string $dqlToBeTested |
||
76 | * @param string $expectedException |
||
77 | * @param array $queryHints |
||
78 | * @param array $queryParams |
||
79 | */ |
||
80 | public function assertInvalidSqlGeneration($dqlToBeTested, $expectedException, array $queryHints = [], array $queryParams = []) |
||
81 | { |
||
82 | $this->expectException($expectedException); |
||
83 | |||
84 | $query = $this->_em->createQuery($dqlToBeTested); |
||
85 | |||
86 | foreach ($queryParams AS $name => $value) { |
||
87 | $query->setParameter($name, $value); |
||
88 | } |
||
89 | |||
90 | $query->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true) |
||
91 | ->useQueryCache(false); |
||
92 | |||
93 | foreach ($queryHints AS $name => $value) { |
||
94 | $query->setHint($name, $value); |
||
95 | } |
||
96 | |||
97 | $sql = $query->getSql(); |
||
98 | $query->free(); |
||
99 | |||
100 | // If we reached here, test failed |
||
101 | $this->fail($sql); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @group DDC-3697 |
||
106 | */ |
||
107 | public function testJoinWithRangeVariablePutsConditionIntoSqlWhereClause() |
||
108 | { |
||
109 | $this->assertSqlGeneration( |
||
110 | 'SELECT c.id FROM Doctrine\Tests\Models\Company\CompanyPerson c JOIN Doctrine\Tests\Models\Company\CompanyPerson r WHERE c.spouse = r AND r.id = 42', |
||
111 | 'SELECT c0_.id AS id_0 FROM company_persons c0_ INNER JOIN company_persons c1_ WHERE c0_.spouse_id = c1_.id AND c1_.id = 42', |
||
112 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] |
||
113 | ); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @group DDC-3697 |
||
118 | */ |
||
119 | public function testJoinWithRangeVariableAndInheritancePutsConditionIntoSqlWhereClause() |
||
120 | { |
||
121 | /* |
||
122 | * Basically like the previous test, but this time load data for the inherited objects as well. |
||
123 | * The important thing is that the ON clauses in LEFT JOINs only contain the conditions necessary to join the appropriate inheritance table |
||
124 | * whereas the filtering condition must remain in the SQL WHERE clause. |
||
125 | */ |
||
126 | $this->assertSqlGeneration( |
||
127 | 'SELECT c.id FROM Doctrine\Tests\Models\Company\CompanyPerson c JOIN Doctrine\Tests\Models\Company\CompanyPerson r WHERE c.spouse = r AND r.id = 42', |
||
128 | 'SELECT c0_.id AS id_0 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id INNER JOIN company_persons c3_ LEFT JOIN company_managers c4_ ON c3_.id = c4_.id LEFT JOIN company_employees c5_ ON c3_.id = c5_.id WHERE c0_.spouse_id = c3_.id AND c3_.id = 42', |
||
129 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] |
||
130 | ); |
||
131 | } |
||
132 | |||
133 | public function testSupportsSelectForAllFields() |
||
134 | { |
||
135 | $this->assertSqlGeneration( |
||
136 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
137 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_' |
||
138 | ); |
||
139 | } |
||
140 | |||
141 | public function testSupportsSelectForOneField() |
||
142 | { |
||
143 | $this->assertSqlGeneration( |
||
144 | 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
145 | 'SELECT c0_.id AS id_0 FROM cms_users c0_' |
||
146 | ); |
||
147 | } |
||
148 | |||
149 | public function testSupportsSelectForOneNestedField() |
||
150 | { |
||
151 | $this->assertSqlGeneration( |
||
152 | 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsArticle a JOIN a.user u', |
||
153 | 'SELECT c0_.id AS id_0 FROM cms_articles c1_ INNER JOIN cms_users c0_ ON c1_.user_id = c0_.id' |
||
154 | ); |
||
155 | } |
||
156 | |||
157 | public function testSupportsSelectForAllNestedField() |
||
158 | { |
||
159 | $this->assertSqlGeneration( |
||
160 | 'SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a JOIN a.user u ORDER BY u.name ASC', |
||
161 | 'SELECT c0_.id AS id_0, c0_.topic AS topic_1, c0_.text AS text_2, c0_.version AS version_3 FROM cms_articles c0_ INNER JOIN cms_users c1_ ON c0_.user_id = c1_.id ORDER BY c1_.name ASC' |
||
162 | ); |
||
163 | } |
||
164 | |||
165 | public function testNotExistsExpression() |
||
166 | { |
||
167 | $this->assertSqlGeneration( |
||
168 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT EXISTS (SELECT p.phonenumber FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.phonenumber = 1234)', |
||
169 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE NOT EXISTS (SELECT c1_.phonenumber FROM cms_phonenumbers c1_ WHERE c1_.phonenumber = 1234)' |
||
170 | ); |
||
171 | } |
||
172 | |||
173 | public function testSupportsSelectForMultipleColumnsOfASingleComponent() |
||
174 | { |
||
175 | $this->assertSqlGeneration( |
||
176 | 'SELECT u.username, u.name FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
177 | 'SELECT c0_.username AS username_0, c0_.name AS name_1 FROM cms_users c0_' |
||
178 | ); |
||
179 | } |
||
180 | |||
181 | public function testSupportsSelectUsingMultipleFromComponents() |
||
182 | { |
||
183 | $this->assertSqlGeneration( |
||
184 | 'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE u = p.user', |
||
185 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c1_.phonenumber AS phonenumber_4 FROM cms_users c0_, cms_phonenumbers c1_ WHERE c0_.id = c1_.user_id' |
||
186 | ); |
||
187 | } |
||
188 | |||
189 | public function testSupportsJoinOnMultipleComponents() |
||
190 | { |
||
191 | $this->assertSqlGeneration( |
||
192 | 'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN Doctrine\Tests\Models\CMS\CmsPhonenumber p WITH u = p.user', |
||
193 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c1_.phonenumber AS phonenumber_4 FROM cms_users c0_ INNER JOIN cms_phonenumbers c1_ ON (c0_.id = c1_.user_id)' |
||
194 | ); |
||
195 | } |
||
196 | |||
197 | public function testSupportsJoinOnMultipleComponentsWithJoinedInheritanceType() |
||
198 | { |
||
199 | $this->assertSqlGeneration( |
||
200 | 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e JOIN Doctrine\Tests\Models\Company\CompanyManager m WITH e.id = m.id', |
||
201 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id INNER JOIN (company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id) ON (c0_.id = c3_.id)' |
||
202 | ); |
||
203 | |||
204 | $this->assertSqlGeneration( |
||
205 | 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e LEFT JOIN Doctrine\Tests\Models\Company\CompanyManager m WITH e.id = m.id', |
||
206 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN (company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id) ON (c0_.id = c3_.id)' |
||
207 | ); |
||
208 | |||
209 | $this->assertSqlGeneration( |
||
210 | 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c JOIN c.salesPerson s LEFT JOIN Doctrine\Tests\Models\Company\CompanyEvent e WITH s.id = e.id', |
||
211 | 'SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_contracts c0_ INNER JOIN company_employees c1_ ON c0_.salesPerson_id = c1_.id LEFT JOIN company_persons c2_ ON c1_.id = c2_.id LEFT JOIN company_events c3_ ON (c2_.id = c3_.id) WHERE c0_.discr IN (\'fix\', \'flexible\', \'flexultra\')' |
||
212 | ); |
||
213 | } |
||
214 | |||
215 | public function testSupportsSelectWithCollectionAssociationJoin() |
||
216 | { |
||
217 | $this->assertSqlGeneration( |
||
218 | 'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p', |
||
219 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c1_.phonenumber AS phonenumber_4 FROM cms_users c0_ INNER JOIN cms_phonenumbers c1_ ON c0_.id = c1_.user_id' |
||
220 | ); |
||
221 | } |
||
222 | |||
223 | public function testSupportsSelectWithSingleValuedAssociationJoin() |
||
224 | { |
||
225 | $this->assertSqlGeneration( |
||
226 | 'SELECT u, a FROM Doctrine\Tests\Models\Forum\ForumUser u JOIN u.avatar a', |
||
227 | 'SELECT f0_.id AS id_0, f0_.username AS username_1, f1_.id AS id_2 FROM forum_users f0_ INNER JOIN forum_avatars f1_ ON f0_.avatar_id = f1_.id' |
||
228 | ); |
||
229 | } |
||
230 | |||
231 | public function testSelectCorrelatedSubqueryComplexMathematicalExpression() |
||
232 | { |
||
233 | $this->assertSqlGeneration( |
||
234 | 'SELECT (SELECT (count(p.phonenumber)+5)*10 FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p JOIN p.user ui WHERE ui.id = u.id) AS c FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
235 | 'SELECT (SELECT (count(c0_.phonenumber) + 5) * 10 AS sclr_1 FROM cms_phonenumbers c0_ INNER JOIN cms_users c1_ ON c0_.user_id = c1_.id WHERE c1_.id = c2_.id) AS sclr_0 FROM cms_users c2_' |
||
236 | ); |
||
237 | } |
||
238 | |||
239 | public function testSelectComplexMathematicalExpression() |
||
240 | { |
||
241 | $this->assertSqlGeneration( |
||
242 | 'SELECT (count(p.phonenumber)+5)*10 FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p JOIN p.user ui WHERE ui.id = ?1', |
||
243 | 'SELECT (count(c0_.phonenumber) + 5) * 10 AS sclr_0 FROM cms_phonenumbers c0_ INNER JOIN cms_users c1_ ON c0_.user_id = c1_.id WHERE c1_.id = ?' |
||
244 | ); |
||
245 | } |
||
246 | |||
247 | /* NOT (YET?) SUPPORTED. |
||
248 | Can be supported if SimpleSelectExpression supports SingleValuedPathExpression instead of StateFieldPathExpression. |
||
249 | |||
250 | public function testSingleAssociationPathExpressionInSubselect() |
||
251 | { |
||
252 | $this->assertSqlGeneration( |
||
253 | 'SELECT (SELECT p.user FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.user = u) user_id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1', |
||
254 | 'SELECT (SELECT c0_.user_id FROM cms_phonenumbers c0_ WHERE c0_.user_id = c1_.id) AS sclr_0 FROM cms_users c1_ WHERE c1_.id = ?' |
||
255 | ); |
||
256 | }*/ |
||
257 | |||
258 | /** |
||
259 | * @group DDC-1077 |
||
260 | */ |
||
261 | public function testConstantValueInSelect() |
||
262 | { |
||
263 | $this->assertSqlGeneration( |
||
264 | "SELECT u.name, 'foo' AS bar FROM Doctrine\Tests\Models\CMS\CmsUser u", |
||
265 | "SELECT c0_.name AS name_0, 'foo' AS sclr_1 FROM cms_users c0_" |
||
266 | ); |
||
267 | } |
||
268 | |||
269 | public function testSupportsOrderByWithAscAsDefault() |
||
270 | { |
||
271 | $this->assertSqlGeneration( |
||
272 | 'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u ORDER BY u.id', |
||
273 | 'SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ ORDER BY f0_.id ASC' |
||
274 | ); |
||
275 | } |
||
276 | |||
277 | public function testSupportsOrderByAsc() |
||
278 | { |
||
279 | $this->assertSqlGeneration( |
||
280 | 'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u ORDER BY u.id asc', |
||
281 | 'SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ ORDER BY f0_.id ASC' |
||
282 | ); |
||
283 | } |
||
284 | public function testSupportsOrderByDesc() |
||
285 | { |
||
286 | $this->assertSqlGeneration( |
||
287 | 'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u ORDER BY u.id desc', |
||
288 | 'SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ ORDER BY f0_.id DESC' |
||
289 | ); |
||
290 | } |
||
291 | |||
292 | public function testSupportsSelectDistinct() |
||
293 | { |
||
294 | $this->assertSqlGeneration( |
||
295 | 'SELECT DISTINCT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
296 | 'SELECT DISTINCT c0_.name AS name_0 FROM cms_users c0_' |
||
297 | ); |
||
298 | } |
||
299 | |||
300 | public function testSupportsAggregateFunctionInSelectedFields() |
||
301 | { |
||
302 | $this->assertSqlGeneration( |
||
303 | 'SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id', |
||
304 | 'SELECT COUNT(c0_.id) AS sclr_0 FROM cms_users c0_ GROUP BY c0_.id' |
||
305 | ); |
||
306 | } |
||
307 | |||
308 | public function testSupportsAggregateFunctionWithSimpleArithmetic() |
||
309 | { |
||
310 | $this->assertSqlGeneration( |
||
311 | 'SELECT MAX(u.id + 4) * 2 FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
312 | 'SELECT MAX(c0_.id + 4) * 2 AS sclr_0 FROM cms_users c0_' |
||
313 | ); |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * @group DDC-3276 |
||
318 | */ |
||
319 | public function testSupportsAggregateCountFunctionWithSimpleArithmetic() |
||
320 | { |
||
321 | $connMock = $this->_em->getConnection(); |
||
322 | $orgPlatform = $connMock->getDatabasePlatform(); |
||
323 | |||
324 | $connMock->setDatabasePlatform(new MySqlPlatform()); |
||
325 | |||
326 | $this->assertSqlGeneration( |
||
327 | 'SELECT COUNT(CONCAT(u.id, u.name)) FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id', |
||
328 | 'SELECT COUNT(CONCAT(c0_.id, c0_.name)) AS sclr_0 FROM cms_users c0_ GROUP BY c0_.id' |
||
329 | ); |
||
330 | |||
331 | $connMock->setDatabasePlatform($orgPlatform); |
||
332 | } |
||
333 | |||
334 | public function testSupportsWhereClauseWithPositionalParameter() |
||
335 | { |
||
336 | $this->assertSqlGeneration( |
||
337 | 'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.id = ?1', |
||
338 | 'SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ WHERE f0_.id = ?' |
||
339 | ); |
||
340 | } |
||
341 | |||
342 | public function testSupportsWhereClauseWithNamedParameter() |
||
343 | { |
||
344 | $this->assertSqlGeneration( |
||
345 | 'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name', |
||
346 | 'SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ WHERE f0_.username = ?' |
||
347 | ); |
||
348 | } |
||
349 | |||
350 | public function testSupportsWhereAndClauseWithNamedParameters() |
||
351 | { |
||
352 | $this->assertSqlGeneration( |
||
353 | 'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name and u.username = :name2', |
||
354 | 'SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ WHERE f0_.username = ? AND f0_.username = ?' |
||
355 | ); |
||
356 | } |
||
357 | |||
358 | public function testSupportsCombinedWhereClauseWithNamedParameter() |
||
359 | { |
||
360 | $this->assertSqlGeneration( |
||
361 | 'select u from Doctrine\Tests\Models\Forum\ForumUser u where (u.username = :name OR u.username = :name2) AND u.id = :id', |
||
362 | 'SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ WHERE (f0_.username = ? OR f0_.username = ?) AND f0_.id = ?' |
||
363 | ); |
||
364 | } |
||
365 | |||
366 | public function testSupportsAggregateFunctionInASelectDistinct() |
||
367 | { |
||
368 | $this->assertSqlGeneration( |
||
369 | 'SELECT COUNT(DISTINCT u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
370 | 'SELECT COUNT(DISTINCT c0_.name) AS sclr_0 FROM cms_users c0_' |
||
371 | ); |
||
372 | } |
||
373 | |||
374 | // Ticket #668 |
||
375 | public function testSupportsASqlKeywordInAStringLiteralParam() |
||
376 | { |
||
377 | $this->assertSqlGeneration( |
||
378 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name LIKE '%foo OR bar%'", |
||
379 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE c0_.name LIKE '%foo OR bar%'" |
||
380 | ); |
||
381 | } |
||
382 | |||
383 | public function testSupportsArithmeticExpressionsInWherePart() |
||
384 | { |
||
385 | $this->assertSqlGeneration( |
||
386 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((u.id + 5000) * u.id + 3) < 10000000', |
||
387 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE ((c0_.id + 5000) * c0_.id + 3) < 10000000' |
||
388 | ); |
||
389 | } |
||
390 | |||
391 | public function testSupportsMultipleEntitiesInFromClause() |
||
392 | { |
||
393 | $this->assertSqlGeneration( |
||
394 | 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsArticle a JOIN a.user u2 WHERE u.id = u2.id', |
||
395 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c1_.id AS id_4, c1_.topic AS topic_5, c1_.text AS text_6, c1_.version AS version_7 FROM cms_users c0_, cms_articles c1_ INNER JOIN cms_users c2_ ON c1_.user_id = c2_.id WHERE c0_.id = c2_.id' |
||
396 | ); |
||
397 | } |
||
398 | |||
399 | public function testSupportsMultipleEntitiesInFromClauseUsingPathExpression() |
||
400 | { |
||
401 | $this->assertSqlGeneration( |
||
402 | 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsArticle a WHERE u.id = a.user', |
||
403 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c1_.id AS id_4, c1_.topic AS topic_5, c1_.text AS text_6, c1_.version AS version_7 FROM cms_users c0_, cms_articles c1_ WHERE c0_.id = c1_.user_id' |
||
404 | ); |
||
405 | } |
||
406 | |||
407 | public function testSupportsPlainJoinWithoutClause() |
||
408 | { |
||
409 | $this->assertSqlGeneration( |
||
410 | 'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a', |
||
411 | 'SELECT c0_.id AS id_0, c1_.id AS id_1 FROM cms_users c0_ LEFT JOIN cms_articles c1_ ON c0_.id = c1_.user_id' |
||
412 | ); |
||
413 | $this->assertSqlGeneration( |
||
414 | 'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a', |
||
415 | 'SELECT c0_.id AS id_0, c1_.id AS id_1 FROM cms_users c0_ INNER JOIN cms_articles c1_ ON c0_.id = c1_.user_id' |
||
416 | ); |
||
417 | } |
||
418 | |||
419 | /** |
||
420 | * @group DDC-135 |
||
421 | */ |
||
422 | public function testSupportsJoinAndWithClauseRestriction() |
||
423 | { |
||
424 | $this->assertSqlGeneration( |
||
425 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a WITH a.topic LIKE '%foo%'", |
||
426 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ LEFT JOIN cms_articles c1_ ON c0_.id = c1_.user_id AND (c1_.topic LIKE '%foo%')" |
||
427 | ); |
||
428 | $this->assertSqlGeneration( |
||
429 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a WITH a.topic LIKE '%foo%'", |
||
430 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ INNER JOIN cms_articles c1_ ON c0_.id = c1_.user_id AND (c1_.topic LIKE '%foo%')" |
||
431 | ); |
||
432 | } |
||
433 | |||
434 | /** |
||
435 | * @group DDC-135 |
||
436 | * @group DDC-177 |
||
437 | */ |
||
438 | public function testJoinOnClause_NotYetSupported_ThrowsException() |
||
439 | { |
||
440 | $this->expectException(QueryException::class); |
||
441 | |||
442 | $sql = $this->_em->createQuery( |
||
|
|||
443 | "SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a ON a.topic LIKE '%foo%'" |
||
444 | )->getSql(); |
||
445 | } |
||
446 | |||
447 | public function testSupportsMultipleJoins() |
||
448 | { |
||
449 | $this->assertSqlGeneration( |
||
450 | 'SELECT u.id, a.id, p.phonenumber, c.id from Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a JOIN u.phonenumbers p JOIN a.comments c', |
||
451 | 'SELECT c0_.id AS id_0, c1_.id AS id_1, c2_.phonenumber AS phonenumber_2, c3_.id AS id_3 FROM cms_users c0_ INNER JOIN cms_articles c1_ ON c0_.id = c1_.user_id INNER JOIN cms_phonenumbers c2_ ON c0_.id = c2_.user_id INNER JOIN cms_comments c3_ ON c1_.id = c3_.article_id' |
||
452 | ); |
||
453 | } |
||
454 | |||
455 | public function testSupportsTrimFunction() |
||
456 | { |
||
457 | $this->assertSqlGeneration( |
||
458 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE TRIM(TRAILING ' ' FROM u.name) = 'someone'", |
||
459 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE TRIM(TRAILING ' ' FROM c0_.name) = 'someone'" |
||
460 | ); |
||
461 | } |
||
462 | |||
463 | /** |
||
464 | * @group DDC-2668 |
||
465 | */ |
||
466 | public function testSupportsTrimLeadingZeroString() |
||
467 | { |
||
468 | $this->assertSqlGeneration( |
||
469 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE TRIM(TRAILING '0' FROM u.name) != ''", |
||
470 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE TRIM(TRAILING '0' FROM c0_.name) <> ''" |
||
471 | ); |
||
472 | } |
||
473 | |||
474 | // Ticket 894 |
||
475 | public function testSupportsBetweenClauseWithPositionalParameters() |
||
476 | { |
||
477 | $this->assertSqlGeneration( |
||
478 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id BETWEEN ?1 AND ?2", |
||
479 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE c0_.id BETWEEN ? AND ?" |
||
480 | ); |
||
481 | } |
||
482 | |||
483 | /** |
||
484 | * @group DDC-1802 |
||
485 | */ |
||
486 | public function testSupportsNotBetweenForSizeFunction() |
||
487 | { |
||
488 | $this->assertSqlGeneration( |
||
489 | "SELECT m.name FROM Doctrine\Tests\Models\StockExchange\Market m WHERE SIZE(m.stocks) NOT BETWEEN ?1 AND ?2", |
||
490 | "SELECT e0_.name AS name_0 FROM exchange_markets e0_ WHERE (SELECT COUNT(*) FROM exchange_stocks e1_ WHERE e1_.market_id = e0_.id) NOT BETWEEN ? AND ?" |
||
491 | ); |
||
492 | } |
||
493 | |||
494 | public function testSupportsFunctionalExpressionsInWherePart() |
||
495 | { |
||
496 | $this->assertSqlGeneration( |
||
497 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE TRIM(u.name) = 'someone'", |
||
498 | // String quoting in the SQL usually depends on the database platform. |
||
499 | // This test works with a mock connection which uses ' for string quoting. |
||
500 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE TRIM(c0_.name) = 'someone'" |
||
501 | ); |
||
502 | } |
||
503 | |||
504 | public function testSupportsInstanceOfExpressionsInWherePart() |
||
505 | { |
||
506 | $this->assertSqlGeneration( |
||
507 | "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee", |
||
508 | "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('manager', 'employee')" |
||
509 | ); |
||
510 | } |
||
511 | |||
512 | public function testSupportsInstanceOfExpressionInWherePartWithMultipleValues() |
||
513 | { |
||
514 | // This also uses FQCNs starting with or without a backslash in the INSTANCE OF parameter |
||
515 | $this->assertSqlGeneration( |
||
516 | "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF (Doctrine\Tests\Models\Company\CompanyEmployee, \Doctrine\Tests\Models\Company\CompanyManager)", |
||
517 | "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('manager', 'employee')" |
||
518 | ); |
||
519 | } |
||
520 | |||
521 | /** |
||
522 | * @group DDC-1194 |
||
523 | */ |
||
524 | public function testSupportsInstanceOfExpressionsInWherePartPrefixedSlash() |
||
525 | { |
||
526 | $this->assertSqlGeneration( |
||
527 | "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF \Doctrine\Tests\Models\Company\CompanyEmployee", |
||
528 | "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN ('manager', 'employee')" |
||
529 | ); |
||
530 | } |
||
531 | |||
532 | /** |
||
533 | * @group DDC-1194 |
||
534 | */ |
||
535 | public function testSupportsInstanceOfExpressionsInWherePartWithUnrelatedClass() |
||
536 | { |
||
537 | $this->assertInvalidSqlGeneration( |
||
538 | "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF \Doctrine\Tests\Models\CMS\CmsUser", |
||
539 | QueryException::class |
||
540 | ); |
||
541 | } |
||
542 | |||
543 | public function testSupportsInstanceOfExpressionsInWherePartInDeeperLevel() |
||
544 | { |
||
545 | $this->assertSqlGeneration( |
||
546 | "SELECT u FROM Doctrine\Tests\Models\Company\CompanyEmployee u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyManager", |
||
547 | "SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id WHERE c0_.discr IN ('manager')" |
||
548 | ); |
||
549 | } |
||
550 | |||
551 | public function testSupportsInstanceOfExpressionsInWherePartInDeepestLevel() |
||
552 | { |
||
553 | $this->assertSqlGeneration( |
||
554 | "SELECT u FROM Doctrine\Tests\Models\Company\CompanyManager u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyManager", |
||
555 | "SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c2_.title AS title_5, c0_.discr AS discr_6 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id WHERE c0_.discr IN ('manager')" |
||
556 | ); |
||
557 | } |
||
558 | |||
559 | public function testSupportsInstanceOfExpressionsUsingInputParameterInWherePart() |
||
560 | { |
||
561 | $this->assertSqlGeneration( |
||
562 | "SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF ?1", |
||
563 | "SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_ WHERE c0_.discr IN (?)", |
||
564 | [], [1 => $this->_em->getClassMetadata(CompanyEmployee::class)] |
||
565 | ); |
||
566 | } |
||
567 | |||
568 | // Ticket #973 |
||
569 | public function testSupportsSingleValuedInExpressionWithoutSpacesInWherePart() |
||
570 | { |
||
571 | $this->assertSqlGeneration( |
||
572 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE IDENTITY(u.email) IN(46)", |
||
573 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE c0_.email_id IN (46)" |
||
574 | ); |
||
575 | } |
||
576 | |||
577 | public function testSupportsMultipleValuedInExpressionInWherePart() |
||
578 | { |
||
579 | $this->assertSqlGeneration( |
||
580 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN (1, 2)', |
||
581 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE c0_.id IN (1, 2)' |
||
582 | ); |
||
583 | } |
||
584 | |||
585 | public function testSupportsNotInExpressionInWherePart() |
||
586 | { |
||
587 | $this->assertSqlGeneration( |
||
588 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :id NOT IN (1)', |
||
589 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE ? NOT IN (1)' |
||
590 | ); |
||
591 | } |
||
592 | |||
593 | /** |
||
594 | * @group DDC-1802 |
||
595 | */ |
||
596 | public function testSupportsNotInExpressionForModFunction() |
||
597 | { |
||
598 | $this->assertSqlGeneration( |
||
599 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE MOD(u.id, 5) NOT IN(1,3,4)", |
||
600 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE MOD(c0_.id, 5) NOT IN (1, 3, 4)" |
||
601 | ); |
||
602 | } |
||
603 | |||
604 | public function testInExpressionWithSingleValuedAssociationPathExpressionInWherePart() |
||
605 | { |
||
606 | $this->assertSqlGeneration( |
||
607 | 'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u WHERE u.avatar IN (?1, ?2)', |
||
608 | 'SELECT f0_.id AS id_0, f0_.username AS username_1 FROM forum_users f0_ WHERE f0_.avatar_id IN (?, ?)' |
||
609 | ); |
||
610 | } |
||
611 | |||
612 | public function testInvalidInExpressionWithSingleValuedAssociationPathExpressionOnInverseSide() |
||
613 | { |
||
614 | // We do not support SingleValuedAssociationPathExpression on inverse side |
||
615 | $this->assertInvalidSqlGeneration( |
||
616 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.address IN (?1, ?2)", |
||
617 | QueryException::class |
||
618 | ); |
||
619 | } |
||
620 | |||
621 | public function testSupportsConcatFunctionForMysqlAndPostgresql() |
||
622 | { |
||
623 | $connMock = $this->_em->getConnection(); |
||
624 | $orgPlatform = $connMock->getDatabasePlatform(); |
||
625 | |||
626 | $connMock->setDatabasePlatform(new MySqlPlatform()); |
||
627 | $this->assertSqlGeneration( |
||
628 | "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, 's') = ?1", |
||
629 | "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE CONCAT(c0_.name, 's') = ?" |
||
630 | ); |
||
631 | $this->assertSqlGeneration( |
||
632 | "SELECT CONCAT(u.id, u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1", |
||
633 | "SELECT CONCAT(c0_.id, c0_.name) AS sclr_0 FROM cms_users c0_ WHERE c0_.id = ?" |
||
634 | ); |
||
635 | |||
636 | $connMock->setDatabasePlatform(new PostgreSqlPlatform()); |
||
637 | $this->assertSqlGeneration( |
||
638 | "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, 's') = ?1", |
||
639 | "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE c0_.name || 's' = ?" |
||
640 | ); |
||
641 | $this->assertSqlGeneration( |
||
642 | "SELECT CONCAT(u.id, u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1", |
||
643 | "SELECT c0_.id || c0_.name AS sclr_0 FROM cms_users c0_ WHERE c0_.id = ?" |
||
644 | ); |
||
645 | |||
646 | $connMock->setDatabasePlatform($orgPlatform); |
||
647 | } |
||
648 | |||
649 | public function testSupportsExistsExpressionInWherePartWithCorrelatedSubquery() |
||
650 | { |
||
651 | $this->assertSqlGeneration( |
||
652 | 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE EXISTS (SELECT p.phonenumber FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.phonenumber = u.id)', |
||
653 | 'SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE EXISTS (SELECT c1_.phonenumber FROM cms_phonenumbers c1_ WHERE c1_.phonenumber = c0_.id)' |
||
654 | ); |
||
655 | } |
||
656 | |||
657 | /** |
||
658 | * @group DDC-593 |
||
659 | */ |
||
660 | public function testSubqueriesInComparisonExpression() |
||
661 | { |
||
662 | $this->assertSqlGeneration( |
||
663 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id >= (SELECT u2.id FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE u2.name = :name)) AND (u.id <= (SELECT u3.id FROM Doctrine\Tests\Models\CMS\CmsUser u3 WHERE u3.name = :name))', |
||
664 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE (c0_.id >= (SELECT c1_.id FROM cms_users c1_ WHERE c1_.name = ?)) AND (c0_.id <= (SELECT c2_.id FROM cms_users c2_ WHERE c2_.name = ?))' |
||
665 | ); |
||
666 | } |
||
667 | |||
668 | public function testSupportsMemberOfExpressionOneToMany() |
||
669 | { |
||
670 | // "Get all users who have $phone as a phonenumber." (*cough* doesnt really make sense...) |
||
671 | $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.phonenumbers'); |
||
672 | $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); |
||
673 | |||
674 | $phone = new CmsPhonenumber(); |
||
675 | $phone->phonenumber = 101; |
||
676 | $q->setParameter('param', $phone); |
||
677 | |||
678 | $this->assertEquals( |
||
679 | 'SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_phonenumbers c1_ WHERE c0_.id = c1_.user_id AND c1_.phonenumber = ?)', |
||
680 | $q->getSql() |
||
681 | ); |
||
682 | } |
||
683 | |||
684 | public function testSupportsMemberOfExpressionManyToMany() |
||
685 | { |
||
686 | // "Get all users who are members of $group." |
||
687 | $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.groups'); |
||
688 | $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); |
||
689 | |||
690 | $group = new CmsGroup(); |
||
691 | $group->id = 101; |
||
692 | $q->setParameter('param', $group); |
||
693 | |||
694 | $this->assertEquals( |
||
695 | 'SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_users_groups c1_ INNER JOIN cms_groups c2_ ON c1_.group_id = c2_.id WHERE c1_.user_id = c0_.id AND c2_.id IN (?))', |
||
696 | $q->getSql() |
||
697 | ); |
||
698 | } |
||
699 | |||
700 | public function testSupportsMemberOfExpressionManyToManyParameterArray() |
||
701 | { |
||
702 | $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.groups'); |
||
703 | $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); |
||
704 | |||
705 | $group = new CmsGroup(); |
||
706 | $group->id = 101; |
||
707 | $group2 = new CmsGroup(); |
||
708 | $group2->id = 105; |
||
709 | $q->setParameter('param', [$group, $group2]); |
||
710 | |||
711 | $this->assertEquals( |
||
712 | 'SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_users_groups c1_ INNER JOIN cms_groups c2_ ON c1_.group_id = c2_.id WHERE c1_.user_id = c0_.id AND c2_.id IN (?))', |
||
713 | $q->getSql() |
||
714 | ); |
||
715 | } |
||
716 | |||
717 | public function testSupportsMemberOfExpressionSelfReferencing() |
||
718 | { |
||
719 | // "Get all persons who have $person as a friend." |
||
720 | // Tough one: Many-many self-referencing ("friends") with class table inheritance |
||
721 | $q = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p WHERE :param MEMBER OF p.friends'); |
||
722 | $person = new CompanyPerson(); |
||
723 | $this->_em->getClassMetadata(get_class($person))->setIdentifierValues($person, ['id' => 101]); |
||
724 | $q->setParameter('param', $person); |
||
725 | $this->assertEquals( |
||
726 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.title AS title_2, c2_.salary AS salary_3, c2_.department AS department_4, c2_.startDate AS startDate_5, c0_.discr AS discr_6, c0_.spouse_id AS spouse_id_7, c1_.car_id AS car_id_8 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id WHERE EXISTS (SELECT 1 FROM company_persons_friends c3_ INNER JOIN company_persons c4_ ON c3_.friend_id = c4_.id WHERE c3_.person_id = c0_.id AND c4_.id IN (?))', |
||
727 | $q->getSql() |
||
728 | ); |
||
729 | } |
||
730 | |||
731 | public function testSupportsMemberOfWithSingleValuedAssociation() |
||
732 | { |
||
733 | // Impossible example, but it illustrates the purpose |
||
734 | $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.email MEMBER OF u.groups'); |
||
735 | |||
736 | $this->assertEquals( |
||
737 | 'SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_users_groups c1_ INNER JOIN cms_groups c2_ ON c1_.group_id = c2_.id WHERE c1_.user_id = c0_.id AND c2_.id IN (c0_.email_id))', |
||
738 | $q->getSql() |
||
739 | ); |
||
740 | } |
||
741 | |||
742 | public function testSupportsMemberOfWithIdentificationVariable() |
||
743 | { |
||
744 | // Impossible example, but it illustrates the purpose |
||
745 | $q = $this->_em->createQuery('SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u MEMBER OF u.groups'); |
||
746 | |||
747 | $this->assertEquals( |
||
748 | 'SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_users_groups c1_ INNER JOIN cms_groups c2_ ON c1_.group_id = c2_.id WHERE c1_.user_id = c0_.id AND c2_.id IN (c0_.id))', |
||
749 | $q->getSql() |
||
750 | ); |
||
751 | } |
||
752 | |||
753 | public function testSupportsCurrentDateFunction() |
||
754 | { |
||
755 | $q = $this->_em->createQuery('SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime > current_date()'); |
||
756 | $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); |
||
757 | $this->assertEquals('SELECT d0_.id AS id_0 FROM date_time_model d0_ WHERE d0_.col_datetime > CURRENT_DATE', $q->getSql()); |
||
758 | } |
||
759 | |||
760 | public function testSupportsCurrentTimeFunction() |
||
761 | { |
||
762 | $q = $this->_em->createQuery('SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.time > current_time()'); |
||
763 | $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); |
||
764 | $this->assertEquals('SELECT d0_.id AS id_0 FROM date_time_model d0_ WHERE d0_.col_time > CURRENT_TIME', $q->getSql()); |
||
765 | } |
||
766 | |||
767 | public function testSupportsCurrentTimestampFunction() |
||
768 | { |
||
769 | $q = $this->_em->createQuery('SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime > current_timestamp()'); |
||
770 | $q->setHint(ORMQuery::HINT_FORCE_PARTIAL_LOAD, true); |
||
771 | $this->assertEquals('SELECT d0_.id AS id_0 FROM date_time_model d0_ WHERE d0_.col_datetime > CURRENT_TIMESTAMP', $q->getSql()); |
||
772 | } |
||
773 | |||
774 | public function testExistsExpressionInWhereCorrelatedSubqueryAssocCondition() |
||
775 | { |
||
776 | $this->assertSqlGeneration( |
||
777 | // DQL |
||
778 | // The result of this query consists of all employees whose spouses are also employees. |
||
779 | 'SELECT DISTINCT emp FROM Doctrine\Tests\Models\CMS\CmsEmployee emp |
||
780 | WHERE EXISTS ( |
||
781 | SELECT spouseEmp |
||
782 | FROM Doctrine\Tests\Models\CMS\CmsEmployee spouseEmp |
||
783 | WHERE spouseEmp = emp.spouse)', |
||
784 | // SQL |
||
785 | 'SELECT DISTINCT c0_.id AS id_0, c0_.name AS name_1 FROM cms_employees c0_' |
||
786 | . ' WHERE EXISTS (' |
||
787 | . 'SELECT c1_.id FROM cms_employees c1_ WHERE c1_.id = c0_.spouse_id' |
||
788 | . ')' |
||
789 | ); |
||
790 | } |
||
791 | |||
792 | public function testExistsExpressionWithSimpleSelectReturningScalar() |
||
793 | { |
||
794 | $this->assertSqlGeneration( |
||
795 | // DQL |
||
796 | // The result of this query consists of all employees whose spouses are also employees. |
||
797 | 'SELECT DISTINCT emp FROM Doctrine\Tests\Models\CMS\CmsEmployee emp |
||
798 | WHERE EXISTS ( |
||
799 | SELECT 1 |
||
800 | FROM Doctrine\Tests\Models\CMS\CmsEmployee spouseEmp |
||
801 | WHERE spouseEmp = emp.spouse)', |
||
802 | // SQL |
||
803 | 'SELECT DISTINCT c0_.id AS id_0, c0_.name AS name_1 FROM cms_employees c0_' |
||
804 | . ' WHERE EXISTS (' |
||
805 | . 'SELECT 1 AS sclr_2 FROM cms_employees c1_ WHERE c1_.id = c0_.spouse_id' |
||
806 | . ')' |
||
807 | ); |
||
808 | } |
||
809 | |||
810 | public function testLimitFromQueryClass() |
||
811 | { |
||
812 | $q = $this->_em |
||
813 | ->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u') |
||
814 | ->setMaxResults(10); |
||
815 | |||
816 | $this->assertEquals('SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ LIMIT 10', $q->getSql()); |
||
817 | } |
||
818 | |||
819 | public function testLimitAndOffsetFromQueryClass() |
||
820 | { |
||
821 | $q = $this->_em |
||
822 | ->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u') |
||
823 | ->setMaxResults(10) |
||
824 | ->setFirstResult(0); |
||
825 | |||
826 | // DBAL 2.8+ doesn't add OFFSET part when offset is 0 |
||
827 | self::assertThat( |
||
828 | $q->getSql(), |
||
829 | self::logicalOr( |
||
830 | self::identicalTo('SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ LIMIT 10'), |
||
831 | self::identicalTo('SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ LIMIT 10 OFFSET 0') |
||
832 | ) |
||
833 | ); |
||
834 | } |
||
835 | |||
836 | public function testSizeFunction() |
||
837 | { |
||
838 | $this->assertSqlGeneration( |
||
839 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.phonenumbers) > 1", |
||
840 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE (SELECT COUNT(*) FROM cms_phonenumbers c1_ WHERE c1_.user_id = c0_.id) > 1" |
||
841 | ); |
||
842 | } |
||
843 | |||
844 | public function testSizeFunctionSupportsManyToMany() |
||
845 | { |
||
846 | $this->assertSqlGeneration( |
||
847 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.groups) > 1", |
||
848 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE (SELECT COUNT(*) FROM cms_users_groups c1_ WHERE c1_.user_id = c0_.id) > 1" |
||
849 | ); |
||
850 | } |
||
851 | |||
852 | public function testEmptyCollectionComparisonExpression() |
||
853 | { |
||
854 | $this->assertSqlGeneration( |
||
855 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.phonenumbers IS EMPTY", |
||
856 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE (SELECT COUNT(*) FROM cms_phonenumbers c1_ WHERE c1_.user_id = c0_.id) = 0" |
||
857 | ); |
||
858 | $this->assertSqlGeneration( |
||
859 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.phonenumbers IS NOT EMPTY", |
||
860 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE (SELECT COUNT(*) FROM cms_phonenumbers c1_ WHERE c1_.user_id = c0_.id) > 0" |
||
861 | ); |
||
862 | } |
||
863 | |||
864 | public function testNestedExpressions() |
||
865 | { |
||
866 | $this->assertSqlGeneration( |
||
867 | "select u from Doctrine\Tests\Models\CMS\CmsUser u where u.id > 10 and u.id < 42 and ((u.id * 2) > 5)", |
||
868 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE c0_.id > 10 AND c0_.id < 42 AND ((c0_.id * 2) > 5)" |
||
869 | ); |
||
870 | } |
||
871 | |||
872 | public function testNestedExpressions2() |
||
873 | { |
||
874 | $this->assertSqlGeneration( |
||
875 | "select u from Doctrine\Tests\Models\CMS\CmsUser u where (u.id > 10) and (u.id < 42 and ((u.id * 2) > 5)) or u.id <> 42", |
||
876 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE (c0_.id > 10) AND (c0_.id < 42 AND ((c0_.id * 2) > 5)) OR c0_.id <> 42" |
||
877 | ); |
||
878 | } |
||
879 | |||
880 | public function testNestedExpressions3() |
||
881 | { |
||
882 | $this->assertSqlGeneration( |
||
883 | "select u from Doctrine\Tests\Models\CMS\CmsUser u where (u.id > 10) and (u.id between 1 and 10 or u.id in (1, 2, 3, 4, 5))", |
||
884 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE (c0_.id > 10) AND (c0_.id BETWEEN 1 AND 10 OR c0_.id IN (1, 2, 3, 4, 5))" |
||
885 | ); |
||
886 | } |
||
887 | |||
888 | public function testOrderByCollectionAssociationSize() |
||
889 | { |
||
890 | $this->assertSqlGeneration( |
||
891 | "select u, size(u.articles) as numArticles from Doctrine\Tests\Models\CMS\CmsUser u order by numArticles", |
||
892 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, (SELECT COUNT(*) FROM cms_articles c1_ WHERE c1_.user_id = c0_.id) AS sclr_4 FROM cms_users c0_ ORDER BY sclr_4 ASC" |
||
893 | ); |
||
894 | } |
||
895 | |||
896 | public function testOrderBySupportsSingleValuedPathExpressionOwningSide() |
||
897 | { |
||
898 | $this->assertSqlGeneration( |
||
899 | "select a from Doctrine\Tests\Models\CMS\CmsArticle a order by a.user", |
||
900 | "SELECT c0_.id AS id_0, c0_.topic AS topic_1, c0_.text AS text_2, c0_.version AS version_3 FROM cms_articles c0_ ORDER BY c0_.user_id ASC" |
||
901 | ); |
||
902 | } |
||
903 | |||
904 | /** |
||
905 | * @expectedException \Doctrine\ORM\Query\QueryException |
||
906 | */ |
||
907 | public function testOrderBySupportsSingleValuedPathExpressionInverseSide() |
||
908 | { |
||
909 | $q = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u order by u.address"); |
||
910 | $q->getSQL(); |
||
911 | } |
||
912 | |||
913 | public function testBooleanLiteralInWhereOnSqlite() |
||
914 | { |
||
915 | $oldPlat = $this->_em->getConnection()->getDatabasePlatform(); |
||
916 | $this->_em->getConnection()->setDatabasePlatform(new SqlitePlatform()); |
||
917 | |||
918 | $this->assertSqlGeneration( |
||
919 | "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true", |
||
920 | "SELECT b0_.id AS id_0, b0_.booleanField AS booleanField_1 FROM boolean_model b0_ WHERE b0_.booleanField = 1" |
||
921 | ); |
||
922 | |||
923 | $this->assertSqlGeneration( |
||
924 | "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = false", |
||
925 | "SELECT b0_.id AS id_0, b0_.booleanField AS booleanField_1 FROM boolean_model b0_ WHERE b0_.booleanField = 0" |
||
926 | ); |
||
927 | |||
928 | $this->_em->getConnection()->setDatabasePlatform($oldPlat); |
||
929 | } |
||
930 | |||
931 | public function testBooleanLiteralInWhereOnPostgres() |
||
932 | { |
||
933 | $oldPlat = $this->_em->getConnection()->getDatabasePlatform(); |
||
934 | $this->_em->getConnection()->setDatabasePlatform(new PostgreSqlPlatform()); |
||
935 | |||
936 | $this->assertSqlGeneration( |
||
937 | "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true", |
||
938 | "SELECT b0_.id AS id_0, b0_.booleanField AS booleanfield_1 FROM boolean_model b0_ WHERE b0_.booleanField = true" |
||
939 | ); |
||
940 | |||
941 | $this->assertSqlGeneration( |
||
942 | "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = false", |
||
943 | "SELECT b0_.id AS id_0, b0_.booleanField AS booleanfield_1 FROM boolean_model b0_ WHERE b0_.booleanField = false" |
||
944 | ); |
||
945 | |||
946 | $this->_em->getConnection()->setDatabasePlatform($oldPlat); |
||
947 | } |
||
948 | |||
949 | public function testSingleValuedAssociationFieldInWhere() |
||
950 | { |
||
951 | $this->assertSqlGeneration( |
||
952 | "SELECT p FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.user = ?1", |
||
953 | "SELECT c0_.phonenumber AS phonenumber_0 FROM cms_phonenumbers c0_ WHERE c0_.user_id = ?" |
||
954 | ); |
||
955 | } |
||
956 | |||
957 | public function testSingleValuedAssociationNullCheckOnOwningSide() |
||
958 | { |
||
959 | $this->assertSqlGeneration( |
||
960 | "SELECT a FROM Doctrine\Tests\Models\CMS\CmsAddress a WHERE a.user IS NULL", |
||
961 | "SELECT c0_.id AS id_0, c0_.country AS country_1, c0_.zip AS zip_2, c0_.city AS city_3 FROM cms_addresses c0_ WHERE c0_.user_id IS NULL" |
||
962 | ); |
||
963 | } |
||
964 | |||
965 | // Null check on inverse side has to happen through explicit JOIN. |
||
966 | // "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.address IS NULL" |
||
967 | // where the CmsUser is the inverse side is not supported. |
||
968 | public function testSingleValuedAssociationNullCheckOnInverseSide() |
||
969 | { |
||
970 | $this->assertSqlGeneration( |
||
971 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.address a WHERE a.id IS NULL", |
||
972 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ LEFT JOIN cms_addresses c1_ ON c0_.id = c1_.user_id WHERE c1_.id IS NULL" |
||
973 | ); |
||
974 | } |
||
975 | |||
976 | /** |
||
977 | * @group DDC-339 |
||
978 | * @group DDC-1572 |
||
979 | */ |
||
980 | public function testStringFunctionLikeExpression() |
||
981 | { |
||
982 | $this->assertSqlGeneration( |
||
983 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE LOWER(u.name) LIKE '%foo OR bar%'", |
||
984 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE LOWER(c0_.name) LIKE '%foo OR bar%'" |
||
985 | ); |
||
986 | $this->assertSqlGeneration( |
||
987 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE LOWER(u.name) LIKE :str", |
||
988 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE LOWER(c0_.name) LIKE ?" |
||
989 | ); |
||
990 | $this->assertSqlGeneration( |
||
991 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(UPPER(u.name), '_moo') LIKE :str", |
||
992 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE UPPER(c0_.name) || '_moo' LIKE ?" |
||
993 | ); |
||
994 | |||
995 | // DDC-1572 |
||
996 | $this->assertSqlGeneration( |
||
997 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE UPPER(u.name) LIKE UPPER(:str)", |
||
998 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE UPPER(c0_.name) LIKE UPPER(?)" |
||
999 | ); |
||
1000 | $this->assertSqlGeneration( |
||
1001 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE UPPER(LOWER(u.name)) LIKE UPPER(LOWER(:str))", |
||
1002 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE UPPER(LOWER(c0_.name)) LIKE UPPER(LOWER(?))" |
||
1003 | ); |
||
1004 | $this->assertSqlGeneration( |
||
1005 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a WITH a.topic LIKE u.name", |
||
1006 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ LEFT JOIN cms_articles c1_ ON c0_.id = c1_.user_id AND (c1_.topic LIKE c0_.name)" |
||
1007 | ); |
||
1008 | } |
||
1009 | |||
1010 | /** |
||
1011 | * @group DDC-1802 |
||
1012 | */ |
||
1013 | public function testStringFunctionNotLikeExpression() |
||
1014 | { |
||
1015 | $this->assertSqlGeneration( |
||
1016 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE LOWER(u.name) NOT LIKE '%foo OR bar%'", |
||
1017 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE LOWER(c0_.name) NOT LIKE '%foo OR bar%'" |
||
1018 | ); |
||
1019 | |||
1020 | $this->assertSqlGeneration( |
||
1021 | "SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE UPPER(LOWER(u.name)) NOT LIKE UPPER(LOWER(:str))", |
||
1022 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE UPPER(LOWER(c0_.name)) NOT LIKE UPPER(LOWER(?))" |
||
1023 | ); |
||
1024 | $this->assertSqlGeneration( |
||
1025 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a WITH a.topic NOT LIKE u.name", |
||
1026 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ LEFT JOIN cms_articles c1_ ON c0_.id = c1_.user_id AND (c1_.topic NOT LIKE c0_.name)" |
||
1027 | ); |
||
1028 | } |
||
1029 | |||
1030 | /** |
||
1031 | * @group DDC-338 |
||
1032 | */ |
||
1033 | public function testOrderedCollectionFetchJoined() |
||
1034 | { |
||
1035 | $this->assertSqlGeneration( |
||
1036 | "SELECT r, l FROM Doctrine\Tests\Models\Routing\RoutingRoute r JOIN r.legs l", |
||
1037 | "SELECT r0_.id AS id_0, r1_.id AS id_1, r1_.departureDate AS departureDate_2, r1_.arrivalDate AS arrivalDate_3 FROM RoutingRoute r0_ INNER JOIN RoutingRouteLegs r2_ ON r0_.id = r2_.route_id INNER JOIN RoutingLeg r1_ ON r1_.id = r2_.leg_id ". |
||
1038 | "ORDER BY r1_.departureDate ASC" |
||
1039 | ); |
||
1040 | } |
||
1041 | |||
1042 | public function testSubselectInSelect() |
||
1043 | { |
||
1044 | $this->assertSqlGeneration( |
||
1045 | "SELECT u.name, (SELECT COUNT(p.phonenumber) FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE p.phonenumber = 1234) pcount FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = 'jon'", |
||
1046 | "SELECT c0_.name AS name_0, (SELECT COUNT(c1_.phonenumber) AS sclr_2 FROM cms_phonenumbers c1_ WHERE c1_.phonenumber = 1234) AS sclr_1 FROM cms_users c0_ WHERE c0_.name = 'jon'" |
||
1047 | ); |
||
1048 | } |
||
1049 | |||
1050 | /** |
||
1051 | * @group locking |
||
1052 | * @group DDC-178 |
||
1053 | */ |
||
1054 | public function testPessimisticWriteLockQueryHint() |
||
1055 | { |
||
1056 | if ($this->_em->getConnection()->getDatabasePlatform() instanceof SqlitePlatform) { |
||
1057 | $this->markTestSkipped('SqLite does not support Row locking at all.'); |
||
1058 | } |
||
1059 | |||
1060 | $this->assertSqlGeneration( |
||
1061 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", |
||
1062 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 ". |
||
1063 | "FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR UPDATE", |
||
1064 | [ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_WRITE] |
||
1065 | ); |
||
1066 | } |
||
1067 | |||
1068 | /** |
||
1069 | * @group locking |
||
1070 | * @group DDC-178 |
||
1071 | */ |
||
1072 | public function testPessimisticReadLockQueryHintPostgreSql() |
||
1073 | { |
||
1074 | $this->_em->getConnection()->setDatabasePlatform(new PostgreSqlPlatform()); |
||
1075 | |||
1076 | $this->assertSqlGeneration( |
||
1077 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", |
||
1078 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 ". |
||
1079 | "FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR SHARE", |
||
1080 | [ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ] |
||
1081 | ); |
||
1082 | } |
||
1083 | |||
1084 | /** |
||
1085 | * @group DDC-1693 |
||
1086 | * @group locking |
||
1087 | */ |
||
1088 | public function testLockModeNoneQueryHint() |
||
1089 | { |
||
1090 | $this->assertSqlGeneration( |
||
1091 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", |
||
1092 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 ". |
||
1093 | "FROM cms_users c0_ WHERE c0_.username = 'gblanco'", |
||
1094 | [ORMQuery::HINT_LOCK_MODE => LockMode::NONE] |
||
1095 | ); |
||
1096 | } |
||
1097 | |||
1098 | /** |
||
1099 | * @group DDC-430 |
||
1100 | */ |
||
1101 | public function testSupportSelectWithMoreThan10InputParameters() |
||
1102 | { |
||
1103 | $this->assertSqlGeneration( |
||
1104 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1 OR u.id = ?2 OR u.id = ?3 OR u.id = ?4 OR u.id = ?5 OR u.id = ?6 OR u.id = ?7 OR u.id = ?8 OR u.id = ?9 OR u.id = ?10 OR u.id = ?11", |
||
1105 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE c0_.id = ? OR c0_.id = ? OR c0_.id = ? OR c0_.id = ? OR c0_.id = ? OR c0_.id = ? OR c0_.id = ? OR c0_.id = ? OR c0_.id = ? OR c0_.id = ? OR c0_.id = ?" |
||
1106 | ); |
||
1107 | } |
||
1108 | |||
1109 | /** |
||
1110 | * @group locking |
||
1111 | * @group DDC-178 |
||
1112 | */ |
||
1113 | public function testPessimisticReadLockQueryHintMySql() |
||
1114 | { |
||
1115 | $this->_em->getConnection()->setDatabasePlatform(new MySqlPlatform()); |
||
1116 | |||
1117 | $this->assertSqlGeneration( |
||
1118 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", |
||
1119 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 ". |
||
1120 | "FROM cms_users c0_ WHERE c0_.username = 'gblanco' LOCK IN SHARE MODE", |
||
1121 | [ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ] |
||
1122 | ); |
||
1123 | } |
||
1124 | |||
1125 | /** |
||
1126 | * @group locking |
||
1127 | * @group DDC-178 |
||
1128 | */ |
||
1129 | public function testPessimisticReadLockQueryHintOracle() |
||
1130 | { |
||
1131 | $this->_em->getConnection()->setDatabasePlatform(new OraclePlatform()); |
||
1132 | |||
1133 | $this->assertSqlGeneration( |
||
1134 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", |
||
1135 | "SELECT c0_.id AS ID_0, c0_.status AS STATUS_1, c0_.username AS USERNAME_2, c0_.name AS NAME_3 ". |
||
1136 | "FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR UPDATE", |
||
1137 | [ORMQuery::HINT_LOCK_MODE => LockMode::PESSIMISTIC_READ] |
||
1138 | ); |
||
1139 | } |
||
1140 | |||
1141 | /** |
||
1142 | * @group DDC-431 |
||
1143 | */ |
||
1144 | public function testSupportToCustomDQLFunctions() |
||
1145 | { |
||
1146 | $config = $this->_em->getConfiguration(); |
||
1147 | $config->addCustomNumericFunction('MYABS', MyAbsFunction::class); |
||
1148 | |||
1149 | $this->assertSqlGeneration( |
||
1150 | 'SELECT MYABS(p.phonenumber) FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p', |
||
1151 | 'SELECT ABS(c0_.phonenumber) AS sclr_0 FROM cms_phonenumbers c0_' |
||
1152 | ); |
||
1153 | |||
1154 | $config->setCustomNumericFunctions([]); |
||
1155 | } |
||
1156 | |||
1157 | /** |
||
1158 | * @group DDC-826 |
||
1159 | */ |
||
1160 | public function testMappedSuperclassAssociationJoin() |
||
1161 | { |
||
1162 | $this->assertSqlGeneration( |
||
1163 | 'SELECT f FROM Doctrine\Tests\Models\DirectoryTree\File f JOIN f.parentDirectory d WHERE f.id = ?1', |
||
1164 | 'SELECT f0_.id AS id_0, f0_.extension AS extension_1, f0_.name AS name_2 FROM "file" f0_ INNER JOIN Directory d1_ ON f0_.parentDirectory_id = d1_.id WHERE f0_.id = ?' |
||
1165 | ); |
||
1166 | } |
||
1167 | |||
1168 | /** |
||
1169 | * @group DDC-1053 |
||
1170 | */ |
||
1171 | public function testGroupBy() |
||
1172 | { |
||
1173 | $this->assertSqlGeneration( |
||
1174 | 'SELECT g.id, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g.id', |
||
1175 | 'SELECT c0_.id AS id_0, count(c1_.id) AS sclr_1 FROM cms_groups c0_ INNER JOIN cms_users_groups c2_ ON c0_.id = c2_.group_id INNER JOIN cms_users c1_ ON c1_.id = c2_.user_id GROUP BY c0_.id' |
||
1176 | ); |
||
1177 | } |
||
1178 | |||
1179 | /** |
||
1180 | * @group DDC-1053 |
||
1181 | */ |
||
1182 | public function testGroupByIdentificationVariable() |
||
1183 | { |
||
1184 | $this->assertSqlGeneration( |
||
1185 | 'SELECT g, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g', |
||
1186 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, count(c1_.id) AS sclr_2 FROM cms_groups c0_ INNER JOIN cms_users_groups c2_ ON c0_.id = c2_.group_id INNER JOIN cms_users c1_ ON c1_.id = c2_.user_id GROUP BY c0_.id, c0_.name' |
||
1187 | ); |
||
1188 | } |
||
1189 | |||
1190 | public function testCaseContainingNullIf() |
||
1191 | { |
||
1192 | $this->assertSqlGeneration( |
||
1193 | "SELECT NULLIF(g.id, g.name) AS NullIfEqual FROM Doctrine\Tests\Models\CMS\CmsGroup g", |
||
1194 | 'SELECT NULLIF(c0_.id, c0_.name) AS sclr_0 FROM cms_groups c0_' |
||
1195 | ); |
||
1196 | } |
||
1197 | |||
1198 | public function testCaseContainingCoalesce() |
||
1199 | { |
||
1200 | $this->assertSqlGeneration( |
||
1201 | "SELECT COALESCE(NULLIF(u.name, ''), u.username) as Display FROM Doctrine\Tests\Models\CMS\CmsUser u", |
||
1202 | "SELECT COALESCE(NULLIF(c0_.name, ''), c0_.username) AS sclr_0 FROM cms_users c0_" |
||
1203 | ); |
||
1204 | } |
||
1205 | |||
1206 | /** |
||
1207 | * Test that the right discriminator data is inserted in a subquery. |
||
1208 | */ |
||
1209 | public function testSubSelectDiscriminator() |
||
1210 | { |
||
1211 | $this->assertSqlGeneration( |
||
1212 | "SELECT u.name, (SELECT COUNT(cfc.id) total FROM Doctrine\Tests\Models\Company\CompanyFixContract cfc) as cfc_count FROM Doctrine\Tests\Models\CMS\CmsUser u", |
||
1213 | "SELECT c0_.name AS name_0, (SELECT COUNT(c1_.id) AS sclr_2 FROM company_contracts c1_ WHERE c1_.discr IN ('fix')) AS sclr_1 FROM cms_users c0_" |
||
1214 | ); |
||
1215 | } |
||
1216 | |||
1217 | public function testIdVariableResultVariableReuse() |
||
1218 | { |
||
1219 | $exceptionThrown = false; |
||
1220 | try { |
||
1221 | $query = $this->_em->createQuery("SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IN (SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u)"); |
||
1222 | |||
1223 | $query->getSql(); |
||
1224 | $query->free(); |
||
1225 | } catch (\Exception $e) { |
||
1226 | $exceptionThrown = true; |
||
1227 | } |
||
1228 | |||
1229 | $this->assertTrue($exceptionThrown); |
||
1230 | |||
1231 | } |
||
1232 | |||
1233 | public function testSubSelectAliasesFromOuterQuery() |
||
1234 | { |
||
1235 | $this->assertSqlGeneration( |
||
1236 | "SELECT uo, (SELECT ui.name FROM Doctrine\Tests\Models\CMS\CmsUser ui WHERE ui.id = uo.id) AS bar FROM Doctrine\Tests\Models\CMS\CmsUser uo", |
||
1237 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, (SELECT c1_.name FROM cms_users c1_ WHERE c1_.id = c0_.id) AS sclr_4 FROM cms_users c0_" |
||
1238 | ); |
||
1239 | } |
||
1240 | |||
1241 | public function testSubSelectAliasesFromOuterQueryWithSubquery() |
||
1242 | { |
||
1243 | $this->assertSqlGeneration( |
||
1244 | "SELECT uo, (SELECT ui.name FROM Doctrine\Tests\Models\CMS\CmsUser ui WHERE ui.id = uo.id AND ui.name IN (SELECT uii.name FROM Doctrine\Tests\Models\CMS\CmsUser uii)) AS bar FROM Doctrine\Tests\Models\CMS\CmsUser uo", |
||
1245 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, (SELECT c1_.name FROM cms_users c1_ WHERE c1_.id = c0_.id AND c1_.name IN (SELECT c2_.name FROM cms_users c2_)) AS sclr_4 FROM cms_users c0_" |
||
1246 | ); |
||
1247 | } |
||
1248 | |||
1249 | public function testSubSelectAliasesFromOuterQueryReuseInWhereClause() |
||
1250 | { |
||
1251 | $this->assertSqlGeneration( |
||
1252 | "SELECT uo, (SELECT ui.name FROM Doctrine\Tests\Models\CMS\CmsUser ui WHERE ui.id = uo.id) AS bar FROM Doctrine\Tests\Models\CMS\CmsUser uo WHERE bar = ?0", |
||
1253 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, (SELECT c1_.name FROM cms_users c1_ WHERE c1_.id = c0_.id) AS sclr_4 FROM cms_users c0_ WHERE sclr_4 = ?" |
||
1254 | ); |
||
1255 | } |
||
1256 | |||
1257 | /** |
||
1258 | * @group DDC-1298 |
||
1259 | */ |
||
1260 | public function testSelectForeignKeyPKWithoutFields() |
||
1261 | { |
||
1262 | $this->assertSqlGeneration( |
||
1263 | "SELECT t, s, l FROM Doctrine\Tests\Models\DDC117\DDC117Link l INNER JOIN l.target t INNER JOIN l.source s", |
||
1264 | "SELECT d0_.article_id AS article_id_0, d0_.title AS title_1, d1_.article_id AS article_id_2, d1_.title AS title_3, d2_.source_id AS source_id_4, d2_.target_id AS target_id_5 FROM DDC117Link d2_ INNER JOIN DDC117Article d0_ ON d2_.target_id = d0_.article_id INNER JOIN DDC117Article d1_ ON d2_.source_id = d1_.article_id" |
||
1265 | ); |
||
1266 | } |
||
1267 | |||
1268 | public function testGeneralCaseWithSingleWhenClause() |
||
1269 | { |
||
1270 | $this->assertSqlGeneration( |
||
1271 | "SELECT g.id, CASE WHEN ((g.id / 2) > 18) THEN 1 ELSE 0 END AS test FROM Doctrine\Tests\Models\CMS\CmsGroup g", |
||
1272 | "SELECT c0_.id AS id_0, CASE WHEN ((c0_.id / 2) > 18) THEN 1 ELSE 0 END AS sclr_1 FROM cms_groups c0_" |
||
1273 | ); |
||
1274 | } |
||
1275 | |||
1276 | public function testGeneralCaseWithMultipleWhenClause() |
||
1277 | { |
||
1278 | $this->assertSqlGeneration( |
||
1279 | "SELECT g.id, CASE WHEN (g.id / 2 < 10) THEN 2 WHEN ((g.id / 2) > 20) THEN 1 ELSE 0 END AS test FROM Doctrine\Tests\Models\CMS\CmsGroup g", |
||
1280 | "SELECT c0_.id AS id_0, CASE WHEN (c0_.id / 2 < 10) THEN 2 WHEN ((c0_.id / 2) > 20) THEN 1 ELSE 0 END AS sclr_1 FROM cms_groups c0_" |
||
1281 | ); |
||
1282 | } |
||
1283 | |||
1284 | public function testSimpleCaseWithSingleWhenClause() |
||
1285 | { |
||
1286 | $this->assertSqlGeneration( |
||
1287 | "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id = CASE g.name WHEN 'admin' THEN 1 ELSE 2 END", |
||
1288 | "SELECT c0_.id AS id_0, c0_.name AS name_1 FROM cms_groups c0_ WHERE c0_.id = CASE c0_.name WHEN 'admin' THEN 1 ELSE 2 END" |
||
1289 | ); |
||
1290 | } |
||
1291 | |||
1292 | public function testSimpleCaseWithMultipleWhenClause() |
||
1293 | { |
||
1294 | $this->assertSqlGeneration( |
||
1295 | "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id = (CASE g.name WHEN 'admin' THEN 1 WHEN 'moderator' THEN 2 ELSE 3 END)", |
||
1296 | "SELECT c0_.id AS id_0, c0_.name AS name_1 FROM cms_groups c0_ WHERE c0_.id = (CASE c0_.name WHEN 'admin' THEN 1 WHEN 'moderator' THEN 2 ELSE 3 END)" |
||
1297 | ); |
||
1298 | } |
||
1299 | |||
1300 | public function testGeneralCaseWithSingleWhenClauseInSubselect() |
||
1305 | ); |
||
1306 | } |
||
1307 | |||
1308 | public function testGeneralCaseWithMultipleWhenClauseInSubselect() |
||
1309 | { |
||
1310 | $this->assertSqlGeneration( |
||
1311 | "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE WHEN (g.id / 2 < 10) THEN 3 WHEN ((g.id / 2) > 20) THEN 2 ELSE 1 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)", |
||
1312 | "SELECT c0_.id AS id_0, c0_.name AS name_1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE WHEN (c0_.id / 2 < 10) THEN 3 WHEN ((c0_.id / 2) > 20) THEN 2 ELSE 1 END AS sclr_2 FROM cms_groups c1_)" |
||
1313 | ); |
||
1314 | } |
||
1315 | |||
1316 | public function testSimpleCaseWithSingleWhenClauseInSubselect() |
||
1317 | { |
||
1318 | $this->assertSqlGeneration( |
||
1319 | "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE g2.name WHEN 'admin' THEN 1 ELSE 2 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)", |
||
1320 | "SELECT c0_.id AS id_0, c0_.name AS name_1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE c1_.name WHEN 'admin' THEN 1 ELSE 2 END AS sclr_2 FROM cms_groups c1_)" |
||
1321 | ); |
||
1322 | } |
||
1323 | |||
1324 | public function testSimpleCaseWithMultipleWhenClauseInSubselect() |
||
1325 | { |
||
1326 | $this->assertSqlGeneration( |
||
1327 | "SELECT g FROM Doctrine\Tests\Models\CMS\CmsGroup g WHERE g.id IN (SELECT CASE g2.name WHEN 'admin' THEN 1 WHEN 'moderator' THEN 2 ELSE 3 END FROM Doctrine\Tests\Models\CMS\CmsGroup g2)", |
||
1328 | "SELECT c0_.id AS id_0, c0_.name AS name_1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE c1_.name WHEN 'admin' THEN 1 WHEN 'moderator' THEN 2 ELSE 3 END AS sclr_2 FROM cms_groups c1_)" |
||
1329 | ); |
||
1330 | } |
||
1331 | |||
1332 | /** |
||
1333 | * @group DDC-1696 |
||
1334 | */ |
||
1335 | public function testSimpleCaseWithStringPrimary() |
||
1336 | { |
||
1337 | $this->assertSqlGeneration( |
||
1338 | "SELECT g.id, CASE WHEN ((g.id / 2) > 18) THEN 'Foo' ELSE 'Bar' END AS test FROM Doctrine\Tests\Models\CMS\CmsGroup g", |
||
1339 | "SELECT c0_.id AS id_0, CASE WHEN ((c0_.id / 2) > 18) THEN 'Foo' ELSE 'Bar' END AS sclr_1 FROM cms_groups c0_" |
||
1340 | ); |
||
1341 | } |
||
1342 | |||
1343 | /** |
||
1344 | * @group DDC-2205 |
||
1345 | */ |
||
1346 | public function testCaseNegativeValuesInThenExpression() |
||
1347 | { |
||
1348 | $this->assertSqlGeneration( |
||
1349 | "SELECT CASE g.name WHEN 'admin' THEN - 1 ELSE - 2 END FROM Doctrine\Tests\Models\CMS\CmsGroup g", |
||
1350 | "SELECT CASE c0_.name WHEN 'admin' THEN -1 ELSE -2 END AS sclr_0 FROM cms_groups c0_" |
||
1351 | ); |
||
1352 | |||
1353 | $this->assertSqlGeneration( |
||
1354 | "SELECT CASE g.name WHEN 'admin' THEN - 2 WHEN 'guest' THEN - 1 ELSE 0 END FROM Doctrine\Tests\Models\CMS\CmsGroup g", |
||
1355 | "SELECT CASE c0_.name WHEN 'admin' THEN -2 WHEN 'guest' THEN -1 ELSE 0 END AS sclr_0 FROM cms_groups c0_" |
||
1356 | ); |
||
1357 | |||
1358 | $this->assertSqlGeneration( |
||
1359 | "SELECT CASE g.name WHEN 'admin' THEN (- 1) ELSE (- 2) END FROM Doctrine\Tests\Models\CMS\CmsGroup g", |
||
1360 | "SELECT CASE c0_.name WHEN 'admin' THEN (-1) ELSE (-2) END AS sclr_0 FROM cms_groups c0_" |
||
1361 | ); |
||
1362 | |||
1363 | $this->assertSqlGeneration( |
||
1364 | "SELECT CASE g.name WHEN 'admin' THEN ( - :value) ELSE ( + :value) END FROM Doctrine\Tests\Models\CMS\CmsGroup g", |
||
1365 | "SELECT CASE c0_.name WHEN 'admin' THEN (-?) ELSE (+?) END AS sclr_0 FROM cms_groups c0_" |
||
1366 | ); |
||
1367 | |||
1368 | $this->assertSqlGeneration( |
||
1369 | "SELECT CASE g.name WHEN 'admin' THEN ( - g.id) ELSE ( + g.id) END FROM Doctrine\Tests\Models\CMS\CmsGroup g", |
||
1370 | "SELECT CASE c0_.name WHEN 'admin' THEN (-c0_.id) ELSE (+c0_.id) END AS sclr_0 FROM cms_groups c0_" |
||
1371 | ); |
||
1372 | } |
||
1373 | |||
1374 | public function testIdentityFunctionWithCompositePrimaryKey() |
||
1375 | { |
||
1376 | $this->assertSqlGeneration( |
||
1377 | "SELECT IDENTITY(p.poi, 'long') AS long FROM Doctrine\Tests\Models\Navigation\NavPhotos p", |
||
1378 | "SELECT n0_.poi_long AS sclr_0 FROM navigation_photos n0_" |
||
1379 | ); |
||
1380 | |||
1381 | $this->assertSqlGeneration( |
||
1382 | "SELECT IDENTITY(p.poi, 'lat') AS lat FROM Doctrine\Tests\Models\Navigation\NavPhotos p", |
||
1383 | "SELECT n0_.poi_lat AS sclr_0 FROM navigation_photos n0_" |
||
1384 | ); |
||
1385 | |||
1386 | $this->assertSqlGeneration( |
||
1387 | "SELECT IDENTITY(p.poi, 'long') AS long, IDENTITY(p.poi, 'lat') AS lat FROM Doctrine\Tests\Models\Navigation\NavPhotos p", |
||
1388 | "SELECT n0_.poi_long AS sclr_0, n0_.poi_lat AS sclr_1 FROM navigation_photos n0_" |
||
1389 | ); |
||
1390 | |||
1391 | $this->assertInvalidSqlGeneration( |
||
1392 | "SELECT IDENTITY(p.poi, 'invalid') AS invalid FROM Doctrine\Tests\Models\Navigation\NavPhotos p", |
||
1393 | QueryException::class |
||
1394 | ); |
||
1395 | } |
||
1396 | |||
1397 | /** |
||
1398 | * @group DDC-2519 |
||
1399 | */ |
||
1400 | public function testPartialWithAssociationIdentifier() |
||
1401 | { |
||
1402 | $this->assertSqlGeneration( |
||
1403 | "SELECT PARTIAL l.{_source, _target} FROM Doctrine\Tests\Models\Legacy\LegacyUserReference l", |
||
1404 | 'SELECT l0_.iUserIdSource AS iUserIdSource_0, l0_.iUserIdTarget AS iUserIdTarget_1 FROM legacy_users_reference l0_' |
||
1405 | ); |
||
1406 | |||
1407 | $this->assertSqlGeneration( |
||
1408 | "SELECT PARTIAL l.{_description, _source, _target} FROM Doctrine\Tests\Models\Legacy\LegacyUserReference l", |
||
1409 | 'SELECT l0_.description AS description_0, l0_.iUserIdSource AS iUserIdSource_1, l0_.iUserIdTarget AS iUserIdTarget_2 FROM legacy_users_reference l0_' |
||
1410 | ); |
||
1411 | } |
||
1412 | |||
1413 | /** |
||
1414 | * @group DDC-1339 |
||
1415 | */ |
||
1416 | public function testIdentityFunctionInSelectClause() |
||
1417 | { |
||
1418 | $this->assertSqlGeneration( |
||
1419 | "SELECT IDENTITY(u.email) as email_id FROM Doctrine\Tests\Models\CMS\CmsUser u", |
||
1420 | "SELECT c0_.email_id AS sclr_0 FROM cms_users c0_" |
||
1421 | ); |
||
1422 | } |
||
1423 | |||
1424 | public function testIdentityFunctionInJoinedSubclass() |
||
1425 | { |
||
1426 | //relation is in the subclass (CompanyManager) we are querying |
||
1427 | $this->assertSqlGeneration( |
||
1428 | 'SELECT m, IDENTITY(m.car) as car_id FROM Doctrine\Tests\Models\Company\CompanyManager m', |
||
1429 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c2_.title AS title_5, c2_.car_id AS sclr_6, c0_.discr AS discr_7 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id' |
||
1430 | ); |
||
1431 | |||
1432 | //relation is in the base class (CompanyPerson). |
||
1433 | $this->assertSqlGeneration( |
||
1434 | 'SELECT m, IDENTITY(m.spouse) as spouse_id FROM Doctrine\Tests\Models\Company\CompanyManager m', |
||
1435 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c2_.title AS title_5, c0_.spouse_id AS sclr_6, c0_.discr AS discr_7 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id' |
||
1436 | ); |
||
1437 | } |
||
1438 | |||
1439 | /** |
||
1440 | * @group DDC-1339 |
||
1441 | */ |
||
1442 | public function testIdentityFunctionDoesNotAcceptStateField() |
||
1443 | { |
||
1444 | $this->assertInvalidSqlGeneration( |
||
1445 | "SELECT IDENTITY(u.name) as name FROM Doctrine\Tests\Models\CMS\CmsUser u", |
||
1446 | QueryException::class |
||
1447 | ); |
||
1448 | } |
||
1449 | |||
1450 | /** |
||
1451 | * @group DDC-1389 |
||
1452 | */ |
||
1453 | public function testInheritanceTypeJoinInRootClassWithDisabledForcePartialLoad() |
||
1454 | { |
||
1455 | $this->assertSqlGeneration( |
||
1456 | 'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p', |
||
1457 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.title AS title_2, c2_.salary AS salary_3, c2_.department AS department_4, c2_.startDate AS startDate_5, c0_.discr AS discr_6, c0_.spouse_id AS spouse_id_7, c1_.car_id AS car_id_8 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id', |
||
1458 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] |
||
1459 | ); |
||
1460 | } |
||
1461 | |||
1462 | /** |
||
1463 | * @group DDC-1389 |
||
1464 | */ |
||
1465 | public function testInheritanceTypeJoinInRootClassWithEnabledForcePartialLoad() |
||
1466 | { |
||
1467 | $this->assertSqlGeneration( |
||
1468 | 'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p', |
||
1469 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, c0_.discr AS discr_2 FROM company_persons c0_', |
||
1470 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] |
||
1471 | ); |
||
1472 | } |
||
1473 | |||
1474 | /** |
||
1475 | * @group DDC-1389 |
||
1476 | */ |
||
1477 | public function testInheritanceTypeJoinInChildClassWithDisabledForcePartialLoad() |
||
1478 | { |
||
1479 | $this->assertSqlGeneration( |
||
1480 | 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e', |
||
1481 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c2_.title AS title_5, c0_.discr AS discr_6, c0_.spouse_id AS spouse_id_7, c2_.car_id AS car_id_8 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN company_managers c2_ ON c1_.id = c2_.id', |
||
1482 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] |
||
1483 | ); |
||
1484 | } |
||
1485 | |||
1486 | /** |
||
1487 | * @group DDC-1389 |
||
1488 | */ |
||
1489 | public function testInheritanceTypeJoinInChildClassWithEnabledForcePartialLoad() |
||
1490 | { |
||
1491 | $this->assertSqlGeneration( |
||
1492 | 'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e', |
||
1493 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id', |
||
1494 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] |
||
1495 | ); |
||
1496 | } |
||
1497 | |||
1498 | /** |
||
1499 | * @group DDC-1389 |
||
1500 | */ |
||
1501 | public function testInheritanceTypeJoinInLeafClassWithDisabledForcePartialLoad() |
||
1502 | { |
||
1503 | $this->assertSqlGeneration( |
||
1504 | 'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m', |
||
1505 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c2_.title AS title_5, c0_.discr AS discr_6, c0_.spouse_id AS spouse_id_7, c2_.car_id AS car_id_8 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id', |
||
1506 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] |
||
1507 | ); |
||
1508 | } |
||
1509 | |||
1510 | /** |
||
1511 | * @group DDC-1389 |
||
1512 | */ |
||
1513 | public function testInheritanceTypeJoinInLeafClassWithEnabledForcePartialLoad() |
||
1514 | { |
||
1515 | $this->assertSqlGeneration( |
||
1516 | 'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m', |
||
1517 | 'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c2_.title AS title_5, c0_.discr AS discr_6 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id', |
||
1518 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] |
||
1519 | ); |
||
1520 | } |
||
1521 | |||
1522 | /** |
||
1523 | * @group DDC-1389 |
||
1524 | */ |
||
1525 | public function testInheritanceTypeSingleTableInRootClassWithDisabledForcePartialLoad() |
||
1526 | { |
||
1527 | $this->assertSqlGeneration( |
||
1528 | 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c', |
||
1529 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6, c0_.salesPerson_id AS salesPerson_id_7 FROM company_contracts c0_ WHERE c0_.discr IN ('fix', 'flexible', 'flexultra')", |
||
1530 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] |
||
1531 | ); |
||
1532 | } |
||
1533 | |||
1534 | /** |
||
1535 | * @group DDC-1389 |
||
1536 | */ |
||
1537 | public function testInheritanceTypeSingleTableInRootClassWithEnabledForcePartialLoad() |
||
1538 | { |
||
1539 | $this->assertSqlGeneration( |
||
1540 | 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c', |
||
1541 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_contracts c0_ WHERE c0_.discr IN ('fix', 'flexible', 'flexultra')", |
||
1542 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] |
||
1543 | ); |
||
1544 | } |
||
1545 | |||
1546 | /** |
||
1547 | * @group DDC-1389 |
||
1548 | */ |
||
1549 | public function testInheritanceTypeSingleTableInChildClassWithDisabledForcePartialLoad() |
||
1550 | { |
||
1551 | $this->assertSqlGeneration( |
||
1552 | 'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc', |
||
1553 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.hoursWorked AS hoursWorked_2, c0_.pricePerHour AS pricePerHour_3, c0_.maxPrice AS maxPrice_4, c0_.discr AS discr_5, c0_.salesPerson_id AS salesPerson_id_6 FROM company_contracts c0_ WHERE c0_.discr IN ('flexible', 'flexultra')", |
||
1554 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] |
||
1555 | ); |
||
1556 | } |
||
1557 | |||
1558 | /** |
||
1559 | * @group DDC-1389 |
||
1560 | */ |
||
1561 | public function testInheritanceTypeSingleTableInChildClassWithEnabledForcePartialLoad() |
||
1562 | { |
||
1563 | $this->assertSqlGeneration( |
||
1564 | 'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc', |
||
1565 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.hoursWorked AS hoursWorked_2, c0_.pricePerHour AS pricePerHour_3, c0_.maxPrice AS maxPrice_4, c0_.discr AS discr_5 FROM company_contracts c0_ WHERE c0_.discr IN ('flexible', 'flexultra')", |
||
1566 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] |
||
1567 | ); |
||
1568 | } |
||
1569 | |||
1570 | /** |
||
1571 | * @group DDC-1389 |
||
1572 | */ |
||
1573 | public function testInheritanceTypeSingleTableInLeafClassWithDisabledForcePartialLoad() |
||
1574 | { |
||
1575 | $this->assertSqlGeneration( |
||
1576 | 'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc', |
||
1577 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.hoursWorked AS hoursWorked_2, c0_.pricePerHour AS pricePerHour_3, c0_.maxPrice AS maxPrice_4, c0_.discr AS discr_5, c0_.salesPerson_id AS salesPerson_id_6 FROM company_contracts c0_ WHERE c0_.discr IN ('flexultra')", |
||
1578 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] |
||
1579 | ); |
||
1580 | } |
||
1581 | |||
1582 | /** |
||
1583 | * @group DDC-1389 |
||
1584 | */ |
||
1585 | public function testInheritanceTypeSingleTableInLeafClassWithEnabledForcePartialLoad() |
||
1586 | { |
||
1587 | $this->assertSqlGeneration( |
||
1588 | 'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc', |
||
1589 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.hoursWorked AS hoursWorked_2, c0_.pricePerHour AS pricePerHour_3, c0_.maxPrice AS maxPrice_4, c0_.discr AS discr_5 FROM company_contracts c0_ WHERE c0_.discr IN ('flexultra')", |
||
1590 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => true] |
||
1591 | ); |
||
1592 | } |
||
1593 | |||
1594 | /** |
||
1595 | * @group DDC-1161 |
||
1596 | */ |
||
1597 | public function testSelfReferenceWithOneToOneDoesNotDuplicateAlias() |
||
1598 | { |
||
1599 | $this->assertSqlGeneration( |
||
1600 | 'SELECT p, pp FROM Doctrine\Tests\Models\Company\CompanyPerson p JOIN p.spouse pp', |
||
1601 | "SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.title AS title_2, c2_.salary AS salary_3, c2_.department AS department_4, c2_.startDate AS startDate_5, c3_.id AS id_6, c3_.name AS name_7, c4_.title AS title_8, c5_.salary AS salary_9, c5_.department AS department_10, c5_.startDate AS startDate_11, c0_.discr AS discr_12, c0_.spouse_id AS spouse_id_13, c1_.car_id AS car_id_14, c3_.discr AS discr_15, c3_.spouse_id AS spouse_id_16, c4_.car_id AS car_id_17 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id INNER JOIN company_persons c3_ ON c0_.spouse_id = c3_.id LEFT JOIN company_managers c4_ ON c3_.id = c4_.id LEFT JOIN company_employees c5_ ON c3_.id = c5_.id", |
||
1602 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] |
||
1603 | ); |
||
1604 | } |
||
1605 | |||
1606 | /** |
||
1607 | * @group DDC-1384 |
||
1608 | */ |
||
1609 | public function testAliasDoesNotExceedPlatformDefinedLength() |
||
1610 | { |
||
1611 | $this->assertSqlGeneration( |
||
1612 | 'SELECT m FROM ' . __NAMESPACE__ . '\\DDC1384Model m', |
||
1613 | "SELECT d0_.aVeryLongIdentifierThatShouldBeShortenedByTheSQLWalker_fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo AS ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo_0 FROM DDC1384Model d0_" |
||
1614 | ); |
||
1615 | } |
||
1616 | |||
1617 | /** |
||
1618 | * @group DDC-331 |
||
1619 | * @group DDC-1384 |
||
1620 | */ |
||
1621 | public function testIssue331() |
||
1622 | { |
||
1623 | $this->assertSqlGeneration( |
||
1624 | 'SELECT e.name FROM Doctrine\Tests\Models\Company\CompanyEmployee e', |
||
1625 | 'SELECT c0_.name AS name_0 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id' |
||
1626 | ); |
||
1627 | } |
||
1628 | /** |
||
1629 | * @group DDC-1435 |
||
1630 | */ |
||
1631 | public function testForeignKeyAsPrimaryKeySubselect() |
||
1632 | { |
||
1633 | $this->assertSqlGeneration( |
||
1634 | "SELECT s FROM Doctrine\Tests\Models\DDC117\DDC117Article s WHERE EXISTS (SELECT r FROM Doctrine\Tests\Models\DDC117\DDC117Reference r WHERE r.source = s)", |
||
1635 | "SELECT d0_.article_id AS article_id_0, d0_.title AS title_1 FROM DDC117Article d0_ WHERE EXISTS (SELECT d1_.source_id, d1_.target_id FROM DDC117Reference d1_ WHERE d1_.source_id = d0_.article_id)" |
||
1636 | ); |
||
1637 | } |
||
1638 | |||
1639 | /** |
||
1640 | * @group DDC-1474 |
||
1641 | */ |
||
1642 | public function testSelectWithArithmeticExpressionBeforeField() |
||
1643 | { |
||
1644 | $this->assertSqlGeneration( |
||
1645 | 'SELECT - e.value AS value, e.id FROM ' . __NAMESPACE__ . '\DDC1474Entity e', |
||
1646 | 'SELECT -d0_.value AS sclr_0, d0_.id AS id_1 FROM DDC1474Entity d0_' |
||
1647 | ); |
||
1648 | |||
1649 | $this->assertSqlGeneration( |
||
1650 | 'SELECT e.id, + e.value AS value FROM ' . __NAMESPACE__ . '\DDC1474Entity e', |
||
1651 | 'SELECT d0_.id AS id_0, +d0_.value AS sclr_1 FROM DDC1474Entity d0_' |
||
1652 | ); |
||
1653 | } |
||
1654 | |||
1655 | /** |
||
1656 | * @group DDC-1430 |
||
1657 | */ |
||
1658 | public function testGroupByAllFieldsWhenObjectHasForeignKeys() |
||
1659 | { |
||
1660 | $this->assertSqlGeneration( |
||
1661 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u', |
||
1662 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ GROUP BY c0_.id, c0_.status, c0_.username, c0_.name, c0_.email_id' |
||
1663 | ); |
||
1664 | |||
1665 | $this->assertSqlGeneration( |
||
1666 | 'SELECT e FROM Doctrine\Tests\Models\CMS\CmsEmployee e GROUP BY e', |
||
1667 | 'SELECT c0_.id AS id_0, c0_.name AS name_1 FROM cms_employees c0_ GROUP BY c0_.id, c0_.name, c0_.spouse_id' |
||
1668 | ); |
||
1669 | } |
||
1670 | |||
1671 | /** |
||
1672 | * @group DDC-1236 |
||
1673 | */ |
||
1674 | public function testGroupBySupportsResultVariable() |
||
1675 | { |
||
1676 | $this->assertSqlGeneration( |
||
1677 | 'SELECT u, u.status AS st FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY st', |
||
1678 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.status AS status_4 FROM cms_users c0_ GROUP BY c0_.status' |
||
1679 | ); |
||
1680 | } |
||
1681 | |||
1682 | /** |
||
1683 | * @group DDC-1236 |
||
1684 | */ |
||
1685 | public function testGroupBySupportsIdentificationVariable() |
||
1686 | { |
||
1687 | $this->assertSqlGeneration( |
||
1688 | 'SELECT u AS user FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY user', |
||
1689 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ GROUP BY id_0, status_1, username_2, name_3' |
||
1690 | ); |
||
1691 | } |
||
1692 | |||
1693 | /** |
||
1694 | * @group DDC-1213 |
||
1695 | */ |
||
1696 | public function testSupportsBitComparison() |
||
1697 | { |
||
1698 | $this->assertSqlGeneration( |
||
1699 | 'SELECT BIT_OR(4,2), BIT_AND(4,2), u FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
1700 | 'SELECT (4 | 2) AS sclr_0, (4 & 2) AS sclr_1, c0_.id AS id_2, c0_.status AS status_3, c0_.username AS username_4, c0_.name AS name_5 FROM cms_users c0_' |
||
1701 | ); |
||
1702 | $this->assertSqlGeneration( |
||
1703 | 'SELECT BIT_OR(u.id,2), BIT_AND(u.id,2) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE BIT_OR(u.id,2) > 0', |
||
1704 | 'SELECT (c0_.id | 2) AS sclr_0, (c0_.id & 2) AS sclr_1 FROM cms_users c0_ WHERE (c0_.id | 2) > 0' |
||
1705 | ); |
||
1706 | $this->assertSqlGeneration( |
||
1707 | 'SELECT BIT_OR(u.id,2), BIT_AND(u.id,2) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE BIT_AND(u.id , 4) > 0', |
||
1708 | 'SELECT (c0_.id | 2) AS sclr_0, (c0_.id & 2) AS sclr_1 FROM cms_users c0_ WHERE (c0_.id & 4) > 0' |
||
1709 | ); |
||
1710 | $this->assertSqlGeneration( |
||
1711 | 'SELECT BIT_OR(u.id,2), BIT_AND(u.id,2) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE BIT_OR(u.id , 2) > 0 OR BIT_AND(u.id , 4) > 0', |
||
1712 | 'SELECT (c0_.id | 2) AS sclr_0, (c0_.id & 2) AS sclr_1 FROM cms_users c0_ WHERE (c0_.id | 2) > 0 OR (c0_.id & 4) > 0' |
||
1713 | ); |
||
1714 | } |
||
1715 | |||
1716 | /** |
||
1717 | * @group DDC-1539 |
||
1718 | */ |
||
1719 | public function testParenthesesOnTheLeftHandOfComparison() |
||
1720 | { |
||
1721 | $this->assertSqlGeneration( |
||
1722 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u where ( (u.id + u.id) * u.id ) > 100', |
||
1723 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE ((c0_.id + c0_.id) * c0_.id) > 100' |
||
1724 | ); |
||
1725 | $this->assertSqlGeneration( |
||
1726 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u where (u.id + u.id) * u.id > 100', |
||
1727 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE (c0_.id + c0_.id) * c0_.id > 100' |
||
1728 | ); |
||
1729 | $this->assertSqlGeneration( |
||
1730 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u where 100 < (u.id + u.id) * u.id ', |
||
1731 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE 100 < (c0_.id + c0_.id) * c0_.id' |
||
1732 | ); |
||
1733 | } |
||
1734 | |||
1735 | public function testSupportsParenthesisExpressionInSubSelect() { |
||
1736 | $this->assertSqlGeneration( |
||
1737 | 'SELECT u.id, (SELECT (1000*SUM(subU.id)/SUM(subU.id)) FROM Doctrine\Tests\Models\CMS\CmsUser subU where subU.id = u.id) AS subSelect FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
1738 | 'SELECT c0_.id AS id_0, (SELECT (1000 * SUM(c1_.id) / SUM(c1_.id)) FROM cms_users c1_ WHERE c1_.id = c0_.id) AS sclr_1 FROM cms_users c0_' |
||
1739 | ); |
||
1740 | } |
||
1741 | |||
1742 | /** |
||
1743 | * @group DDC-1557 |
||
1744 | */ |
||
1745 | public function testSupportsSubSqlFunction() |
||
1746 | { |
||
1747 | $this->assertSqlGeneration( |
||
1748 | 'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE u1.name IN ( SELECT TRIM(u2.name) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )', |
||
1749 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE c0_.name IN (SELECT TRIM(c1_.name) AS sclr_4 FROM cms_users c1_)' |
||
1750 | ); |
||
1751 | $this->assertSqlGeneration( |
||
1752 | 'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE u1.name IN ( SELECT TRIM(u2.name) FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE LOWER(u2.name) LIKE \'%fabio%\')', |
||
1753 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE c0_.name IN (SELECT TRIM(c1_.name) AS sclr_4 FROM cms_users c1_ WHERE LOWER(c1_.name) LIKE \'%fabio%\')' |
||
1754 | ); |
||
1755 | $this->assertSqlGeneration( |
||
1756 | 'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE u1.email IN ( SELECT TRIM(IDENTITY(u2.email)) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )', |
||
1757 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE c0_.email_id IN (SELECT TRIM(c1_.email_id) AS sclr_4 FROM cms_users c1_)' |
||
1758 | ); |
||
1759 | $this->assertSqlGeneration( |
||
1760 | 'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE u1.email IN ( SELECT IDENTITY(u2.email) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )', |
||
1761 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE c0_.email_id IN (SELECT c1_.email_id AS sclr_4 FROM cms_users c1_)' |
||
1762 | ); |
||
1763 | $this->assertSqlGeneration( |
||
1764 | 'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE COUNT(u1.id) = ( SELECT SUM(u2.id) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )', |
||
1765 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE COUNT(c0_.id) = (SELECT SUM(c1_.id) AS sclr_4 FROM cms_users c1_)' |
||
1766 | ); |
||
1767 | $this->assertSqlGeneration( |
||
1768 | 'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE COUNT(u1.id) <= ( SELECT SUM(u2.id) + COUNT(u2.email) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )', |
||
1769 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE COUNT(c0_.id) <= (SELECT SUM(c1_.id) + COUNT(c1_.email_id) AS sclr_4 FROM cms_users c1_)' |
||
1770 | ); |
||
1771 | } |
||
1772 | |||
1773 | /** |
||
1774 | * @group DDC-1574 |
||
1775 | */ |
||
1776 | public function testSupportsNewOperator() |
||
1777 | { |
||
1778 | $this->assertSqlGeneration( |
||
1779 | "SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO(u.name, e.email, a.city) FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e JOIN u.address a", |
||
1780 | "SELECT c0_.name AS sclr_0, c1_.email AS sclr_1, c2_.city AS sclr_2 FROM cms_users c0_ INNER JOIN cms_emails c1_ ON c0_.email_id = c1_.id INNER JOIN cms_addresses c2_ ON c0_.id = c2_.user_id" |
||
1781 | ); |
||
1782 | |||
1783 | $this->assertSqlGeneration( |
||
1784 | "SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO(u.name, e.email, a.id + u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e JOIN u.address a", |
||
1785 | "SELECT c0_.name AS sclr_0, c1_.email AS sclr_1, c2_.id + c0_.id AS sclr_2 FROM cms_users c0_ INNER JOIN cms_emails c1_ ON c0_.email_id = c1_.id INNER JOIN cms_addresses c2_ ON c0_.id = c2_.user_id" |
||
1786 | ); |
||
1787 | |||
1788 | $this->assertSqlGeneration( |
||
1789 | "SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO(u.name, e.email, a.city, COUNT(p)) FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e JOIN u.address a JOIN u.phonenumbers p", |
||
1790 | "SELECT c0_.name AS sclr_0, c1_.email AS sclr_1, c2_.city AS sclr_2, COUNT(c3_.phonenumber) AS sclr_3 FROM cms_users c0_ INNER JOIN cms_emails c1_ ON c0_.email_id = c1_.id INNER JOIN cms_addresses c2_ ON c0_.id = c2_.user_id INNER JOIN cms_phonenumbers c3_ ON c0_.id = c3_.user_id" |
||
1791 | ); |
||
1792 | |||
1793 | $this->assertSqlGeneration( |
||
1794 | "SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO(u.name, e.email, a.city, COUNT(p) + u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e JOIN u.address a JOIN u.phonenumbers p", |
||
1795 | "SELECT c0_.name AS sclr_0, c1_.email AS sclr_1, c2_.city AS sclr_2, COUNT(c3_.phonenumber) + c0_.id AS sclr_3 FROM cms_users c0_ INNER JOIN cms_emails c1_ ON c0_.email_id = c1_.id INNER JOIN cms_addresses c2_ ON c0_.id = c2_.user_id INNER JOIN cms_phonenumbers c3_ ON c0_.id = c3_.user_id" |
||
1796 | ); |
||
1797 | |||
1798 | $this->assertSqlGeneration( |
||
1799 | "SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO(a.id, a.country, a.city), new Doctrine\Tests\Models\CMS\CmsAddressDTO(u.name, e.email) FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e JOIN u.address a ORDER BY u.name", |
||
1800 | "SELECT c0_.id AS sclr_0, c0_.country AS sclr_1, c0_.city AS sclr_2, c1_.name AS sclr_3, c2_.email AS sclr_4 FROM cms_users c1_ INNER JOIN cms_emails c2_ ON c1_.email_id = c2_.id INNER JOIN cms_addresses c0_ ON c1_.id = c0_.user_id ORDER BY c1_.name ASC" |
||
1801 | ); |
||
1802 | |||
1803 | $this->assertSqlGeneration( |
||
1804 | "SELECT new Doctrine\Tests\Models\CMS\CmsUserDTO(a.id, (SELECT 1 FROM Doctrine\Tests\Models\CMS\CmsUser su), a.country, a.city), new Doctrine\Tests\Models\CMS\CmsAddressDTO(u.name, e.email) FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.email e JOIN u.address a ORDER BY u.name", |
||
1805 | "SELECT c0_.id AS sclr_0, (SELECT 1 AS sclr_2 FROM cms_users c1_) AS sclr_1, c0_.country AS sclr_3, c0_.city AS sclr_4, c2_.name AS sclr_5, c3_.email AS sclr_6 FROM cms_users c2_ INNER JOIN cms_emails c3_ ON c2_.email_id = c3_.id INNER JOIN cms_addresses c0_ ON c2_.id = c0_.user_id ORDER BY c2_.name ASC" |
||
1806 | ); |
||
1807 | } |
||
1808 | |||
1809 | /** |
||
1810 | * @group DDC-2234 |
||
1811 | */ |
||
1812 | public function testWhereFunctionIsNullComparisonExpression() |
||
1813 | { |
||
1814 | $this->assertSqlGeneration( |
||
1815 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE IDENTITY(u.email) IS NULL", |
||
1816 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE c0_.email_id IS NULL" |
||
1817 | ); |
||
1818 | |||
1819 | $this->assertSqlGeneration( |
||
1820 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE NULLIF(u.name, 'FabioBatSilva') IS NULL AND IDENTITY(u.email) IS NOT NULL", |
||
1821 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE NULLIF(c0_.name, 'FabioBatSilva') IS NULL AND c0_.email_id IS NOT NULL" |
||
1822 | ); |
||
1823 | |||
1824 | $this->assertSqlGeneration( |
||
1825 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE IDENTITY(u.email) IS NOT NULL", |
||
1826 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE c0_.email_id IS NOT NULL" |
||
1827 | ); |
||
1828 | |||
1829 | $this->assertSqlGeneration( |
||
1830 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE NULLIF(u.name, 'FabioBatSilva') IS NOT NULL", |
||
1831 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE NULLIF(c0_.name, 'FabioBatSilva') IS NOT NULL" |
||
1832 | ); |
||
1833 | |||
1834 | $this->assertSqlGeneration( |
||
1835 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE COALESCE(u.name, u.id) IS NOT NULL", |
||
1836 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE COALESCE(c0_.name, c0_.id) IS NOT NULL" |
||
1837 | ); |
||
1838 | |||
1839 | $this->assertSqlGeneration( |
||
1840 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE COALESCE(u.id, IDENTITY(u.email)) IS NOT NULL", |
||
1841 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE COALESCE(c0_.id, c0_.email_id) IS NOT NULL" |
||
1842 | ); |
||
1843 | |||
1844 | $this->assertSqlGeneration( |
||
1845 | "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE COALESCE(IDENTITY(u.email), NULLIF(u.name, 'FabioBatSilva')) IS NOT NULL", |
||
1846 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ WHERE COALESCE(c0_.email_id, NULLIF(c0_.name, 'FabioBatSilva')) IS NOT NULL" |
||
1847 | ); |
||
1848 | } |
||
1849 | |||
1850 | public function testCustomTypeValueSql() |
||
1851 | { |
||
1852 | if (DBALType::hasType('negative_to_positive')) { |
||
1853 | DBALType::overrideType('negative_to_positive', NegativeToPositiveType::class); |
||
1854 | } else { |
||
1855 | DBALType::addType('negative_to_positive', NegativeToPositiveType::class); |
||
1856 | } |
||
1857 | |||
1858 | $this->assertSqlGeneration( |
||
1859 | 'SELECT p.customInteger FROM Doctrine\Tests\Models\CustomType\CustomTypeParent p WHERE p.id = 1', |
||
1860 | 'SELECT -(c0_.customInteger) AS customInteger_0 FROM customtype_parents c0_ WHERE c0_.id = 1' |
||
1861 | ); |
||
1862 | } |
||
1863 | |||
1864 | public function testCustomTypeValueSqlIgnoresIdentifierColumn() |
||
1865 | { |
||
1866 | if (DBALType::hasType('negative_to_positive')) { |
||
1867 | DBALType::overrideType('negative_to_positive', NegativeToPositiveType::class); |
||
1868 | } else { |
||
1869 | DBALType::addType('negative_to_positive', NegativeToPositiveType::class); |
||
1870 | } |
||
1871 | |||
1872 | $this->assertSqlGeneration( |
||
1873 | 'SELECT p.id FROM Doctrine\Tests\Models\CustomType\CustomTypeParent p WHERE p.id = 1', |
||
1874 | 'SELECT c0_.id AS id_0 FROM customtype_parents c0_ WHERE c0_.id = 1' |
||
1875 | ); |
||
1876 | } |
||
1877 | |||
1878 | public function testCustomTypeValueSqlForAllFields() |
||
1879 | { |
||
1880 | if (DBALType::hasType('negative_to_positive')) { |
||
1881 | DBALType::overrideType('negative_to_positive', NegativeToPositiveType::class); |
||
1882 | } else { |
||
1883 | DBALType::addType('negative_to_positive', NegativeToPositiveType::class); |
||
1884 | } |
||
1885 | |||
1886 | $this->assertSqlGeneration( |
||
1887 | 'SELECT p FROM Doctrine\Tests\Models\CustomType\CustomTypeParent p', |
||
1888 | 'SELECT c0_.id AS id_0, -(c0_.customInteger) AS customInteger_1 FROM customtype_parents c0_' |
||
1889 | ); |
||
1890 | } |
||
1891 | |||
1892 | public function testCustomTypeValueSqlForPartialObject() |
||
1893 | { |
||
1894 | if (DBALType::hasType('negative_to_positive')) { |
||
1895 | DBALType::overrideType('negative_to_positive', NegativeToPositiveType::class); |
||
1896 | } else { |
||
1897 | DBALType::addType('negative_to_positive', NegativeToPositiveType::class); |
||
1898 | } |
||
1899 | |||
1900 | $this->assertSqlGeneration( |
||
1901 | 'SELECT partial p.{id, customInteger} FROM Doctrine\Tests\Models\CustomType\CustomTypeParent p', |
||
1902 | 'SELECT c0_.id AS id_0, -(c0_.customInteger) AS customInteger_1 FROM customtype_parents c0_' |
||
1903 | ); |
||
1904 | } |
||
1905 | |||
1906 | /** |
||
1907 | * @group DDC-1529 |
||
1908 | */ |
||
1909 | public function testMultipleFromAndInheritanceCondition() |
||
1910 | { |
||
1911 | $this->assertSqlGeneration( |
||
1912 | 'SELECT fix, flex FROM Doctrine\Tests\Models\Company\CompanyFixContract fix, Doctrine\Tests\Models\Company\CompanyFlexContract flex', |
||
1913 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c1_.id AS id_3, c1_.completed AS completed_4, c1_.hoursWorked AS hoursWorked_5, c1_.pricePerHour AS pricePerHour_6, c1_.maxPrice AS maxPrice_7, c0_.discr AS discr_8, c1_.discr AS discr_9 FROM company_contracts c0_, company_contracts c1_ WHERE (c0_.discr IN ('fix') AND c1_.discr IN ('flexible', 'flexultra'))" |
||
1914 | ); |
||
1915 | } |
||
1916 | |||
1917 | /** |
||
1918 | * @group DDC-775 |
||
1919 | */ |
||
1920 | public function testOrderByClauseSupportsSimpleArithmeticExpression() |
||
1921 | { |
||
1922 | $this->assertSqlGeneration( |
||
1923 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.id + 1 ', |
||
1924 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ ORDER BY c0_.id + 1 ASC' |
||
1925 | ); |
||
1926 | $this->assertSqlGeneration( |
||
1927 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY ( ( (u.id + 1) * (u.id - 1) ) / 2)', |
||
1928 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ ORDER BY (((c0_.id + 1) * (c0_.id - 1)) / 2) ASC' |
||
1929 | ); |
||
1930 | $this->assertSqlGeneration( |
||
1931 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY ((u.id + 5000) * u.id + 3) ', |
||
1932 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ ORDER BY ((c0_.id + 5000) * c0_.id + 3) ASC' |
||
1933 | ); |
||
1934 | } |
||
1935 | |||
1936 | public function testOrderByClauseSupportsFunction() |
||
1937 | { |
||
1938 | $this->assertSqlGeneration( |
||
1939 | 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY CONCAT(u.username, u.name) ', |
||
1940 | 'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ ORDER BY c0_.username || c0_.name ASC' |
||
1941 | ); |
||
1942 | } |
||
1943 | |||
1944 | /** |
||
1945 | * @group DDC-1719 |
||
1946 | */ |
||
1947 | public function testStripNonAlphanumericCharactersFromAlias() |
||
1948 | { |
||
1949 | $this->assertSqlGeneration( |
||
1950 | 'SELECT e FROM Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity e', |
||
1951 | 'SELECT n0_."simple-entity-id" AS simpleentityid_0, n0_."simple-entity-value" AS simpleentityvalue_1 FROM "not-a-simple-entity" n0_' |
||
1952 | ); |
||
1953 | |||
1954 | $this->assertSqlGeneration( |
||
1955 | 'SELECT e.value FROM Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity e ORDER BY e.value', |
||
1956 | 'SELECT n0_."simple-entity-value" AS simpleentityvalue_0 FROM "not-a-simple-entity" n0_ ORDER BY n0_."simple-entity-value" ASC' |
||
1957 | ); |
||
1958 | |||
1959 | $this->assertSqlGeneration( |
||
1960 | 'SELECT TRIM(e.value) FROM Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity e ORDER BY e.value', |
||
1961 | 'SELECT TRIM(n0_."simple-entity-value") AS sclr_0 FROM "not-a-simple-entity" n0_ ORDER BY n0_."simple-entity-value" ASC' |
||
1962 | ); |
||
1963 | } |
||
1964 | |||
1965 | /** |
||
1966 | * @group DDC-2435 |
||
1967 | */ |
||
1968 | public function testColumnNameWithNumbersAndNonAlphanumericCharacters() |
||
1983 | ); |
||
1984 | } |
||
1985 | |||
1986 | /** |
||
1987 | * @group DDC-1845 |
||
1988 | */ |
||
1989 | public function testQuotedTableDeclaration() |
||
1990 | { |
||
1991 | $this->assertSqlGeneration( |
||
1992 | 'SELECT u FROM Doctrine\Tests\Models\Quote\User u', |
||
1993 | 'SELECT q0_."user-id" AS userid_0, q0_."user-name" AS username_1 FROM "quote-user" q0_' |
||
1994 | ); |
||
1995 | } |
||
1996 | |||
1997 | /** |
||
1998 | * @group DDC-1845 |
||
1999 | */ |
||
2000 | public function testQuotedWalkJoinVariableDeclaration() |
||
2001 | { |
||
2002 | $this->assertSqlGeneration( |
||
2003 | 'SELECT u, a FROM Doctrine\Tests\Models\Quote\User u JOIN u.address a', |
||
2004 | 'SELECT q0_."user-id" AS userid_0, q0_."user-name" AS username_1, q1_."address-id" AS addressid_2, q1_."address-zip" AS addresszip_3, q1_.type AS type_4 FROM "quote-user" q0_ INNER JOIN "quote-address" q1_ ON q0_."address-id" = q1_."address-id" AND q1_.type IN (\'simple\', \'full\')' |
||
2005 | ); |
||
2006 | |||
2007 | $this->assertSqlGeneration( |
||
2008 | 'SELECT u, p FROM Doctrine\Tests\Models\Quote\User u JOIN u.phones p', |
||
2009 | 'SELECT q0_."user-id" AS userid_0, q0_."user-name" AS username_1, q1_."phone-number" AS phonenumber_2 FROM "quote-user" q0_ INNER JOIN "quote-phone" q1_ ON q0_."user-id" = q1_."user-id"' |
||
2010 | ); |
||
2011 | |||
2012 | $this->assertSqlGeneration( |
||
2013 | 'SELECT u, g FROM Doctrine\Tests\Models\Quote\User u JOIN u.groups g', |
||
2014 | 'SELECT q0_."user-id" AS userid_0, q0_."user-name" AS username_1, q1_."group-id" AS groupid_2, q1_."group-name" AS groupname_3 FROM "quote-user" q0_ INNER JOIN "quote-users-groups" q2_ ON q0_."user-id" = q2_."user-id" INNER JOIN "quote-group" q1_ ON q1_."group-id" = q2_."group-id"' |
||
2015 | ); |
||
2016 | |||
2017 | $this->assertSqlGeneration( |
||
2018 | 'SELECT a, u FROM Doctrine\Tests\Models\Quote\Address a JOIN a.user u', |
||
2019 | 'SELECT q0_."address-id" AS addressid_0, q0_."address-zip" AS addresszip_1, q1_."user-id" AS userid_2, q1_."user-name" AS username_3, q0_.type AS type_4 FROM "quote-address" q0_ INNER JOIN "quote-user" q1_ ON q0_."user-id" = q1_."user-id" WHERE q0_.type IN (\'simple\', \'full\')' |
||
2020 | ); |
||
2021 | |||
2022 | $this->assertSqlGeneration( |
||
2023 | 'SELECT g, u FROM Doctrine\Tests\Models\Quote\Group g JOIN g.users u', |
||
2024 | 'SELECT q0_."group-id" AS groupid_0, q0_."group-name" AS groupname_1, q1_."user-id" AS userid_2, q1_."user-name" AS username_3 FROM "quote-group" q0_ INNER JOIN "quote-users-groups" q2_ ON q0_."group-id" = q2_."group-id" INNER JOIN "quote-user" q1_ ON q1_."user-id" = q2_."user-id"' |
||
2025 | ); |
||
2026 | |||
2027 | $this->assertSqlGeneration( |
||
2028 | 'SELECT g, p FROM Doctrine\Tests\Models\Quote\Group g JOIN g.parent p', |
||
2029 | 'SELECT q0_."group-id" AS groupid_0, q0_."group-name" AS groupname_1, q1_."group-id" AS groupid_2, q1_."group-name" AS groupname_3 FROM "quote-group" q0_ INNER JOIN "quote-group" q1_ ON q0_."parent-id" = q1_."group-id"' |
||
2030 | ); |
||
2031 | } |
||
2032 | |||
2033 | /** |
||
2034 | * @group DDC-2208 |
||
2035 | */ |
||
2036 | public function testCaseThenParameterArithmeticExpression() |
||
2037 | { |
||
2038 | $this->assertSqlGeneration( |
||
2039 | 'SELECT SUM(CASE WHEN e.salary <= :value THEN e.salary - :value WHEN e.salary >= :value THEN :value - e.salary ELSE 0 END) FROM Doctrine\Tests\Models\Company\CompanyEmployee e', |
||
2040 | 'SELECT SUM(CASE WHEN c0_.salary <= ? THEN c0_.salary - ? WHEN c0_.salary >= ? THEN ? - c0_.salary ELSE 0 END) AS sclr_0 FROM company_employees c0_ INNER JOIN company_persons c1_ ON c0_.id = c1_.id' |
||
2041 | ); |
||
2042 | |||
2043 | $this->assertSqlGeneration( |
||
2044 | 'SELECT SUM(CASE WHEN e.salary <= :value THEN e.salary - :value WHEN e.salary >= :value THEN :value - e.salary ELSE e.salary + 0 END) FROM Doctrine\Tests\Models\Company\CompanyEmployee e', |
||
2045 | 'SELECT SUM(CASE WHEN c0_.salary <= ? THEN c0_.salary - ? WHEN c0_.salary >= ? THEN ? - c0_.salary ELSE c0_.salary + 0 END) AS sclr_0 FROM company_employees c0_ INNER JOIN company_persons c1_ ON c0_.id = c1_.id' |
||
2046 | ); |
||
2047 | |||
2048 | $this->assertSqlGeneration( |
||
2049 | 'SELECT SUM(CASE WHEN e.salary <= :value THEN (e.salary - :value) WHEN e.salary >= :value THEN (:value - e.salary) ELSE (e.salary + :value) END) FROM Doctrine\Tests\Models\Company\CompanyEmployee e', |
||
2050 | 'SELECT SUM(CASE WHEN c0_.salary <= ? THEN (c0_.salary - ?) WHEN c0_.salary >= ? THEN (? - c0_.salary) ELSE (c0_.salary + ?) END) AS sclr_0 FROM company_employees c0_ INNER JOIN company_persons c1_ ON c0_.id = c1_.id' |
||
2051 | ); |
||
2052 | } |
||
2053 | |||
2054 | /** |
||
2055 | * @group DDC-2268 |
||
2056 | */ |
||
2057 | public function testCaseThenFunction() |
||
2058 | { |
||
2059 | $this->assertSqlGeneration( |
||
2060 | 'SELECT CASE WHEN LENGTH(u.name) <> 0 THEN CONCAT(u.id, u.name) ELSE u.id END AS name FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
2061 | 'SELECT CASE WHEN LENGTH(c0_.name) <> 0 THEN c0_.id || c0_.name ELSE c0_.id END AS sclr_0 FROM cms_users c0_' |
||
2062 | ); |
||
2063 | |||
2064 | $this->assertSqlGeneration( |
||
2065 | 'SELECT CASE WHEN LENGTH(u.name) <> LENGTH(TRIM(u.name)) THEN TRIM(u.name) ELSE u.name END AS name FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
2066 | 'SELECT CASE WHEN LENGTH(c0_.name) <> LENGTH(TRIM(c0_.name)) THEN TRIM(c0_.name) ELSE c0_.name END AS sclr_0 FROM cms_users c0_' |
||
2067 | ); |
||
2068 | |||
2069 | $this->assertSqlGeneration( |
||
2070 | 'SELECT CASE WHEN LENGTH(u.name) > :value THEN SUBSTRING(u.name, 0, :value) ELSE TRIM(u.name) END AS name FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
2071 | 'SELECT CASE WHEN LENGTH(c0_.name) > ? THEN SUBSTRING(c0_.name FROM 0 FOR ?) ELSE TRIM(c0_.name) END AS sclr_0 FROM cms_users c0_' |
||
2072 | ); |
||
2073 | } |
||
2074 | |||
2075 | /** |
||
2076 | * @group DDC-2268 |
||
2077 | */ |
||
2078 | public function testSupportsMoreThanTwoParametersInConcatFunction() |
||
2079 | { |
||
2080 | $connMock = $this->_em->getConnection(); |
||
2081 | $orgPlatform = $connMock->getDatabasePlatform(); |
||
2082 | |||
2083 | $connMock->setDatabasePlatform(new MySqlPlatform()); |
||
2084 | $this->assertSqlGeneration( |
||
2085 | "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, u.status, 's') = ?1", |
||
2086 | "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE CONCAT(c0_.name, c0_.status, 's') = ?" |
||
2087 | ); |
||
2088 | $this->assertSqlGeneration( |
||
2089 | "SELECT CONCAT(u.id, u.name, u.status) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1", |
||
2090 | "SELECT CONCAT(c0_.id, c0_.name, c0_.status) AS sclr_0 FROM cms_users c0_ WHERE c0_.id = ?" |
||
2091 | ); |
||
2092 | |||
2093 | $connMock->setDatabasePlatform(new PostgreSqlPlatform()); |
||
2094 | $this->assertSqlGeneration( |
||
2095 | "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, u.status, 's') = ?1", |
||
2096 | "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE c0_.name || c0_.status || 's' = ?" |
||
2097 | ); |
||
2098 | $this->assertSqlGeneration( |
||
2099 | "SELECT CONCAT(u.id, u.name, u.status) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1", |
||
2100 | "SELECT c0_.id || c0_.name || c0_.status AS sclr_0 FROM cms_users c0_ WHERE c0_.id = ?" |
||
2101 | ); |
||
2102 | |||
2103 | $connMock->setDatabasePlatform(new SQLServerPlatform()); |
||
2104 | $this->assertSqlGeneration( |
||
2105 | "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, u.status, 's') = ?1", |
||
2106 | "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE (c0_.name + c0_.status + 's') = ?" |
||
2107 | ); |
||
2108 | $this->assertSqlGeneration( |
||
2109 | "SELECT CONCAT(u.id, u.name, u.status) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1", |
||
2110 | "SELECT (c0_.id + c0_.name + c0_.status) AS sclr_0 FROM cms_users c0_ WHERE c0_.id = ?" |
||
2111 | ); |
||
2112 | |||
2113 | $connMock->setDatabasePlatform($orgPlatform); |
||
2114 | } |
||
2115 | |||
2116 | /** |
||
2117 | * @group DDC-2188 |
||
2118 | */ |
||
2119 | public function testArithmeticPriority() |
||
2120 | { |
||
2121 | $this->assertSqlGeneration( |
||
2122 | 'SELECT 100/(2*2) FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
2123 | 'SELECT 100 / (2 * 2) AS sclr_0 FROM cms_users c0_' |
||
2124 | ); |
||
2125 | |||
2126 | $this->assertSqlGeneration( |
||
2127 | 'SELECT (u.id / (u.id * 2)) FROM Doctrine\Tests\Models\CMS\CmsUser u', |
||
2128 | 'SELECT (c0_.id / (c0_.id * 2)) AS sclr_0 FROM cms_users c0_' |
||
2129 | ); |
||
2130 | |||
2131 | $this->assertSqlGeneration( |
||
2132 | 'SELECT 100/(2*2) + (u.id / (u.id * 2)) FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id / (u.id * 2)) > 0', |
||
2133 | 'SELECT 100 / (2 * 2) + (c0_.id / (c0_.id * 2)) AS sclr_0 FROM cms_users c0_ WHERE (c0_.id / (c0_.id * 2)) > 0' |
||
2134 | ); |
||
2135 | } |
||
2136 | |||
2137 | /** |
||
2138 | * @group DDC-2475 |
||
2139 | */ |
||
2140 | public function testOrderByClauseShouldReplaceOrderByRelationMapping() |
||
2150 | ); |
||
2151 | } |
||
2152 | |||
2153 | /** |
||
2154 | * @group DDC-1858 |
||
2155 | */ |
||
2156 | public function testHavingSupportIsNullExpression() |
||
2157 | { |
||
2158 | $this->assertSqlGeneration( |
||
2159 | 'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING u.username IS NULL', |
||
2160 | 'SELECT c0_.name AS name_0 FROM cms_users c0_ HAVING c0_.username IS NULL' |
||
2161 | ); |
||
2162 | |||
2163 | $this->assertSqlGeneration( |
||
2164 | 'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING MAX(u.name) IS NULL', |
||
2165 | 'SELECT c0_.name AS name_0 FROM cms_users c0_ HAVING MAX(c0_.name) IS NULL' |
||
2166 | ); |
||
2167 | } |
||
2168 | |||
2169 | /** |
||
2170 | * @group DDC-2506 |
||
2171 | */ |
||
2172 | public function testClassTableInheritanceJoinWithConditionAppliesToBaseTable() |
||
2173 | { |
||
2174 | $this->assertSqlGeneration( |
||
2175 | 'SELECT e.id FROM Doctrine\Tests\Models\Company\CompanyOrganization o JOIN o.events e WITH e.id = ?1', |
||
2176 | 'SELECT c0_.id AS id_0 FROM company_organizations c1_ INNER JOIN (company_events c0_ LEFT JOIN company_auctions c2_ ON c0_.id = c2_.id LEFT JOIN company_raffles c3_ ON c0_.id = c3_.id) ON c1_.id = c0_.org_id AND (c0_.id = ?)', |
||
2177 | [ORMQuery::HINT_FORCE_PARTIAL_LOAD => false] |
||
2178 | ); |
||
2179 | } |
||
2180 | |||
2181 | /** |
||
2182 | * @group DDC-2235 |
||
2183 | */ |
||
2184 | public function testSingleTableInheritanceLeftJoinWithCondition() |
||
2185 | { |
||
2186 | // Regression test for the bug |
||
2187 | $this->assertSqlGeneration( |
||
2188 | 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyEmployee e LEFT JOIN Doctrine\Tests\Models\Company\CompanyContract c WITH c.salesPerson = e.id', |
||
2189 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_employees c1_ INNER JOIN company_persons c2_ ON c1_.id = c2_.id LEFT JOIN company_contracts c0_ ON (c0_.salesPerson_id = c2_.id) AND c0_.discr IN ('fix', 'flexible', 'flexultra')" |
||
2190 | ); |
||
2191 | } |
||
2192 | |||
2193 | /** |
||
2194 | * @group DDC-2235 |
||
2195 | */ |
||
2196 | public function testSingleTableInheritanceLeftJoinWithConditionAndWhere() |
||
2197 | { |
||
2198 | // Ensure other WHERE predicates are passed through to the main WHERE clause |
||
2199 | $this->assertSqlGeneration( |
||
2200 | 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyEmployee e LEFT JOIN Doctrine\Tests\Models\Company\CompanyContract c WITH c.salesPerson = e.id WHERE e.salary > 1000', |
||
2201 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_employees c1_ INNER JOIN company_persons c2_ ON c1_.id = c2_.id LEFT JOIN company_contracts c0_ ON (c0_.salesPerson_id = c2_.id) AND c0_.discr IN ('fix', 'flexible', 'flexultra') WHERE c1_.salary > 1000" |
||
2202 | ); |
||
2203 | } |
||
2204 | |||
2205 | /** |
||
2206 | * @group DDC-2235 |
||
2207 | */ |
||
2208 | public function testSingleTableInheritanceInnerJoinWithCondition() |
||
2209 | { |
||
2210 | // Test inner joins too |
||
2211 | $this->assertSqlGeneration( |
||
2212 | 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyEmployee e INNER JOIN Doctrine\Tests\Models\Company\CompanyContract c WITH c.salesPerson = e.id', |
||
2213 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_employees c1_ INNER JOIN company_persons c2_ ON c1_.id = c2_.id INNER JOIN company_contracts c0_ ON (c0_.salesPerson_id = c2_.id) AND c0_.discr IN ('fix', 'flexible', 'flexultra')" |
||
2214 | ); |
||
2215 | } |
||
2216 | |||
2217 | /** |
||
2218 | * @group DDC-2235 |
||
2219 | */ |
||
2220 | public function testSingleTableInheritanceLeftJoinNonAssociationWithConditionAndWhere() |
||
2221 | { |
||
2222 | // Test that the discriminator IN() predicate is still added into |
||
2223 | // the where clause when not joining onto that table |
||
2224 | $this->assertSqlGeneration( |
||
2225 | 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c LEFT JOIN Doctrine\Tests\Models\Company\CompanyEmployee e WITH e.id = c.salesPerson WHERE c.completed = true', |
||
2226 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_contracts c0_ LEFT JOIN (company_employees c1_ INNER JOIN company_persons c2_ ON c1_.id = c2_.id) ON (c2_.id = c0_.salesPerson_id) WHERE (c0_.completed = 1) AND c0_.discr IN ('fix', 'flexible', 'flexultra')" |
||
2227 | ); |
||
2228 | } |
||
2229 | |||
2230 | /** |
||
2231 | * @group DDC-2235 |
||
2232 | */ |
||
2233 | public function testSingleTableInheritanceJoinCreatesOnCondition() |
||
2234 | { |
||
2235 | // Test that the discriminator IN() predicate is still added |
||
2236 | // into the where clause when not joining onto a single table inheritance entity |
||
2237 | // via a join association |
||
2238 | $this->assertSqlGeneration( |
||
2239 | 'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c JOIN c.salesPerson s WHERE c.completed = true', |
||
2240 | "SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_contracts c0_ INNER JOIN company_employees c1_ ON c0_.salesPerson_id = c1_.id LEFT JOIN company_persons c2_ ON c1_.id = c2_.id WHERE (c0_.completed = 1) AND c0_.discr IN ('fix', 'flexible', 'flexultra')" |
||
2241 | ); |
||
2242 | } |
||
2243 | |||
2244 | /** |
||
2245 | * @group DDC-2235 |
||
2246 | */ |
||
2247 | public function testSingleTableInheritanceCreatesOnConditionAndWhere() |
||
2248 | { |
||
2249 | // Test that when joining onto an entity using single table inheritance via |
||
2250 | // a join association that the discriminator IN() predicate is placed |
||
2251 | // into the ON clause of the join |
||
2252 | $this->assertSqlGeneration( |
||
2253 | 'SELECT e, COUNT(c) FROM Doctrine\Tests\Models\Company\CompanyEmployee e JOIN e.contracts c WHERE e.department = :department', |
||
2254 | "SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, COUNT(c2_.id) AS sclr_5, c0_.discr AS discr_6 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id INNER JOIN company_contract_employees c3_ ON c1_.id = c3_.employee_id INNER JOIN company_contracts c2_ ON c2_.id = c3_.contract_id AND c2_.discr IN ('fix', 'flexible', 'flexultra') WHERE c1_.department = ?", |
||
2255 | [], |
||
2256 | ['department' => 'foobar'] |
||
2257 | ); |
||
2258 | } |
||
2259 | |||
2260 | /** |
||
2261 | * @group DDC-1858 |
||
2262 | */ |
||
2263 | public function testHavingSupportResultVariableInExpression() |
||
2268 | ); |
||
2269 | } |
||
2270 | |||
2271 | /** |
||
2272 | * @group DDC-1858 |
||
2273 | */ |
||
2274 | public function testHavingSupportResultVariableLikeExpression() |
||
2275 | { |
||
2276 | $this->assertSqlGeneration( |
||
2277 | "SELECT u.name AS foo FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING foo LIKE '3'", |
||
2278 | "SELECT c0_.name AS name_0 FROM cms_users c0_ HAVING name_0 LIKE '3'" |
||
2279 | ); |
||
2280 | } |
||
2281 | |||
2282 | /** |
||
2283 | * @group DDC-3085 |
||
2284 | */ |
||
2285 | public function testHavingSupportResultVariableNullComparisonExpression() |
||
2286 | { |
||
2287 | $this->assertSqlGeneration( |
||
2288 | "SELECT u AS user, SUM(a.id) AS score FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN Doctrine\Tests\Models\CMS\CmsAddress a WITH a.user = u GROUP BY u HAVING score IS NOT NULL AND score >= 5", |
||
2289 | "SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, SUM(c1_.id) AS sclr_4 FROM cms_users c0_ LEFT JOIN cms_addresses c1_ ON (c1_.user_id = c0_.id) GROUP BY c0_.id, c0_.status, c0_.username, c0_.name, c0_.email_id HAVING sclr_4 IS NOT NULL AND sclr_4 >= 5" |
||
2290 | ); |
||
2291 | } |
||
2292 | |||
2293 | /** |
||
2294 | * @group DDC-1858 |
||
2295 | */ |
||
2296 | public function testHavingSupportResultVariableInAggregateFunction() |
||
2297 | { |
||
2298 | $this->assertSqlGeneration( |
||
2299 | 'SELECT COUNT(u.name) AS countName FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING countName IS NULL', |
||
2300 | 'SELECT COUNT(c0_.name) AS sclr_0 FROM cms_users c0_ HAVING sclr_0 IS NULL' |
||
2301 | ); |
||
2302 | } |
||
2303 | |||
2304 | /** |
||
2305 | * GitHub issue #4764: https://github.com/doctrine/orm/issues/4764 |
||
2306 | * @group DDC-3907 |
||
2307 | * @dataProvider mathematicOperatorsProvider |
||
2308 | */ |
||
2309 | public function testHavingRegressionUsingVariableWithMathOperatorsExpression($operator) |
||
2314 | ); |
||
2315 | } |
||
2316 | |||
2317 | /** |
||
2318 | * GitHub issue #7846: https://github.com/doctrine/orm/issues/7846 |
||
2319 | * @group 7846 |
||
2320 | */ |
||
2321 | public function testAliasCanBeUsedWithFunctions() |
||
2322 | { |
||
2323 | $this->assertSqlGeneration( |
||
2324 | "SELECT u.name AS foo FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE LOWER(foo) = '3'", |
||
2325 | "SELECT c0_.name AS name_0 FROM cms_users c0_ WHERE LOWER(name_0) = '3'" |
||
2326 | ); |
||
2327 | } |
||
2328 | |||
2329 | /** |
||
2330 | * @return array |
||
2331 | */ |
||
2332 | public function mathematicOperatorsProvider() |
||
2333 | { |
||
2334 | return [['+'], ['-'], ['*'], ['/']]; |
||
2335 | } |
||
2336 | } |
||
2337 | |||
2338 | class MyAbsFunction extends FunctionNode |
||
2339 | { |
||
2340 | public $simpleArithmeticExpression; |
||
2341 | |||
2342 | /** |
||
2343 | * @override |
||
2344 | */ |
||
2345 | public function getSql(SqlWalker $sqlWalker) |
||
2346 | { |
||
2347 | return 'ABS(' . $sqlWalker->walkSimpleArithmeticExpression($this->simpleArithmeticExpression) . ')'; |
||
2348 | } |
||
2349 | |||
2350 | /** |
||
2351 | * @override |
||
2352 | */ |
||
2353 | public function parse(Parser $parser) |
||
2354 | { |
||
2355 | $lexer = $parser->getLexer(); |
||
2356 | |||
2357 | $parser->match(Lexer::T_IDENTIFIER); |
||
2358 | $parser->match(Lexer::T_OPEN_PARENTHESIS); |
||
2359 | |||
2360 | $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression(); |
||
2361 | |||
2362 | $parser->match(Lexer::T_CLOSE_PARENTHESIS); |
||
2363 | } |
||
2364 | } |
||
2365 | /** |
||
2366 | * @Entity |
||
2367 | */ |
||
2368 | class DDC1384Model |
||
2369 | { |
||
2370 | /** |
||
2371 | * @Id |
||
2372 | * @Column(type="integer") |
||
2373 | * @GeneratedValue |
||
2374 | */ |
||
2375 | protected $aVeryLongIdentifierThatShouldBeShortenedByTheSQLWalker_fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo; |
||
2376 | } |
||
2377 | |||
2378 | |||
2379 | /** |
||
2380 | * @Entity |
||
2381 | */ |
||
2382 | class DDC1474Entity |
||
2383 | { |
||
2384 | |||
2385 | /** |
||
2386 | * @Id |
||
2387 | * @Column(type="integer") |
||
2388 | * @GeneratedValue() |
||
2389 | */ |
||
2390 | protected $id; |
||
2391 | |||
2392 | /** |
||
2393 | * @column(type="float") |
||
2394 | */ |
||
2395 | private $value; |
||
2396 | |||
2397 | /** |
||
2398 | * @param string $float |
||
2399 | */ |
||
2400 | public function __construct($float) |
||
2401 | { |
||
2402 | $this->value = $float; |
||
2403 | } |
||
2404 | |||
2405 | /** |
||
2406 | * @return int |
||
2407 | */ |
||
2408 | public function getId() |
||
2409 | { |
||
2410 | return $this->id; |
||
2411 | } |
||
2412 | |||
2413 | /** |
||
2414 | * @return float |
||
2415 | */ |
||
2416 | public function getValue() |
||
2417 | { |
||
2418 | return $this->value; |
||
2419 | } |
||
2420 | |||
2421 | /** |
||
2422 | * @param float $value |
||
2423 | */ |
||
2424 | public function setValue($value) |
||
2425 | { |
||
2426 | $this->value = $value; |
||
2427 | } |
||
2428 | |||
2429 | } |
||
2430 |