2008-05-24 22:18:37 +04:00
< ? php
2009-01-22 22:38:10 +03:00
namespace Doctrine\Tests\ORM\Query ;
2011-11-19 03:35:29 +04:00
use Doctrine\DBAL\Types\Type as DBALType ;
2010-03-05 19:35:00 +03:00
use Doctrine\ORM\Query ;
2009-10-15 18:39:43 +04:00
2009-01-24 19:56:44 +03:00
require_once __DIR__ . '/../../TestInit.php' ;
2009-01-22 22:38:10 +03:00
class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
2008-05-24 22:18:37 +04:00
{
2009-01-19 21:40:12 +03:00
private $_em ;
2009-02-18 10:59:11 +03:00
protected function setUp ()
{
2009-01-19 21:40:12 +03:00
$this -> _em = $this -> _getTestEntityManager ();
}
2010-08-12 07:16:07 +04:00
/**
* Assert a valid SQL generation .
2011-10-29 22:42:44 +04:00
*
2010-08-12 07:16:07 +04:00
* @ param string $dqlToBeTested
* @ param string $sqlToBeConfirmed
* @ param array $queryHints
2011-10-29 22:42:44 +04:00
* @ param array $queryParams
2010-08-12 07:16:07 +04:00
*/
2010-07-30 08:30:02 +04:00
public function assertSqlGeneration ( $dqlToBeTested , $sqlToBeConfirmed , array $queryHints = array (), array $queryParams = array ())
2008-05-24 22:18:37 +04:00
{
2008-05-27 08:52:50 +04:00
try {
2009-01-19 21:40:12 +03:00
$query = $this -> _em -> createQuery ( $dqlToBeTested );
2010-07-30 08:30:02 +04:00
foreach ( $queryParams AS $name => $value ) {
$query -> setParameter ( $name , $value );
}
2010-02-25 18:47:20 +03:00
$query -> setHint ( Query :: HINT_FORCE_PARTIAL_LOAD , true )
2011-10-15 07:18:57 +04:00
-> useQueryCache ( false );
2011-10-29 22:42:44 +04:00
2010-04-09 00:50:06 +04:00
foreach ( $queryHints AS $name => $value ) {
$query -> setHint ( $name , $value );
}
2011-10-29 22:42:44 +04:00
2011-12-02 08:52:35 +04:00
$sqlGenerated = $query -> getSQL ();
parent :: assertEquals (
$sqlToBeConfirmed ,
$sqlGenerated ,
sprintf ( '"%s" is not equal of "%s"' , $sqlGenerated , $sqlToBeConfirmed )
);
2008-05-27 08:52:50 +04:00
$query -> free ();
2010-02-20 00:28:17 +03:00
} catch ( \Exception $e ) {
2011-03-27 23:10:50 +04:00
$this -> fail ( $e -> getMessage () . " \n " . $e -> getTraceAsString ());
2008-05-27 08:52:50 +04:00
}
}
2010-08-12 07:16:07 +04:00
/**
* Asser an invalid SQL generation .
*
* @ param string $dqlToBeTested
* @ param string $expectedException
* @ param array $queryHints
* @ param array $queryParams
*/
2011-10-15 07:21:11 +04:00
public function assertInvalidSqlGeneration ( $dqlToBeTested , $expectedException , array $queryHints = array (), array $queryParams = array ())
2010-08-12 07:16:07 +04:00
{
$this -> setExpectedException ( $expectedException );
$query = $this -> _em -> createQuery ( $dqlToBeTested );
foreach ( $queryParams AS $name => $value ) {
$query -> setParameter ( $name , $value );
}
$query -> setHint ( Query :: HINT_FORCE_PARTIAL_LOAD , true )
2011-10-15 07:18:57 +04:00
-> useQueryCache ( false );
2010-08-12 07:16:07 +04:00
foreach ( $queryHints AS $name => $value ) {
$query -> setHint ( $name , $value );
}
$sql = $query -> getSql ();
$query -> free ();
// If we reached here, test failed
$this -> fail ( $sql );
}
2009-07-08 11:48:44 +04:00
public function testSupportsSelectForAllFields ()
2008-05-28 10:01:04 +04:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u' ,
2009-04-09 22:12:48 +04:00
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_'
2008-05-28 10:01:04 +04:00
);
2009-07-08 11:48:44 +04:00
}
2008-05-28 10:01:04 +04:00
2009-07-08 11:48:44 +04:00
public function testSupportsSelectForOneField ()
{
2008-05-28 10:01:04 +04:00
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u' ,
2009-04-09 22:12:48 +04:00
'SELECT c0_.id AS id0 FROM cms_users c0_'
2008-05-28 10:01:04 +04:00
);
}
2010-03-05 19:35:00 +03:00
2010-01-01 01:48:51 +03:00
public function testSupportsSelectForOneNestedField ()
{
$this -> assertSqlGeneration (
2010-07-23 08:55:33 +04:00
'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsArticle a JOIN a.user u' ,
2010-01-01 01:48:51 +03:00
'SELECT c0_.id AS id0 FROM cms_articles c1_ INNER JOIN cms_users c0_ ON c1_.user_id = c0_.id'
);
}
2010-03-05 19:35:00 +03:00
2010-01-01 01:48:51 +03:00
public function testSupportsSelectForAllNestedField ()
{
$this -> assertSqlGeneration (
2010-07-23 08:55:33 +04:00
'SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a JOIN a.user u ORDER BY u.name ASC' ,
2010-04-11 18:43:33 +04:00
'SELECT c0_.id AS id0, c0_.topic AS topic1, c0_.text AS text2, c0_.version AS version3 FROM cms_articles c0_ INNER JOIN cms_users c1_ ON c0_.user_id = c1_.id ORDER BY c1_.name ASC'
2010-01-01 01:48:51 +03:00
);
}
2008-05-28 10:01:04 +04:00
2009-07-08 11:48:44 +04:00
public function testSupportsSelectForMultipleColumnsOfASingleComponent ()
2008-05-28 10:01:04 +04:00
{
2008-05-27 08:52:50 +04:00
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'SELECT u.username, u.name FROM Doctrine\Tests\Models\CMS\CmsUser u' ,
2009-04-09 22:12:48 +04:00
'SELECT c0_.username AS username0, c0_.name AS name1 FROM cms_users c0_'
2008-05-27 08:52:50 +04:00
);
2008-05-24 22:18:37 +04:00
}
2010-07-20 07:51:01 +04:00
public function testSupportsSelectUsingMultipleFromComponents ()
{
$this -> assertSqlGeneration (
'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsPhonenumber p WHERE u = p.user' ,
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c1_.phonenumber AS phonenumber4 FROM cms_users c0_, cms_phonenumbers c1_ WHERE c0_.id = c1_.user_id'
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsSelectWithCollectionAssociationJoin ()
2008-05-28 10:01:04 +04:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'SELECT u, p FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.phonenumbers p' ,
2009-04-09 22:12:48 +04:00
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c1_.phonenumber AS phonenumber4 FROM cms_users c0_ INNER JOIN cms_phonenumbers c1_ ON c0_.id = c1_.user_id'
2008-05-28 10:01:04 +04:00
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsSelectWithSingleValuedAssociationJoin ()
2008-05-28 10:01:04 +04:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'SELECT u, a FROM Doctrine\Tests\Models\Forum\ForumUser u JOIN u.avatar a' ,
2009-04-09 22:12:48 +04:00
'SELECT f0_.id AS id0, f0_.username AS username1, f1_.id AS id2 FROM forum_users f0_ INNER JOIN forum_avatars f1_ ON f0_.avatar_id = f1_.id'
2008-05-28 10:01:04 +04:00
);
}
2008-06-02 19:00:50 +04:00
2010-08-12 06:12:44 +04:00
public function testSelectCorrelatedSubqueryComplexMathematicalExpression ()
{
$this -> assertSqlGeneration (
'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' ,
'SELECT (SELECT (count(c0_.phonenumber) + 5) * 10 AS sclr1 FROM cms_phonenumbers c0_ INNER JOIN cms_users c1_ ON c0_.user_id = c1_.id WHERE c1_.id = c2_.id) AS sclr0 FROM cms_users c2_'
);
}
public function testSelectComplexMathematicalExpression ()
{
$this -> assertSqlGeneration (
'SELECT (count(p.phonenumber)+5)*10 FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p JOIN p.user ui WHERE ui.id = ?1' ,
'SELECT (count(c0_.phonenumber) + 5) * 10 AS sclr0 FROM cms_phonenumbers c0_ INNER JOIN cms_users c1_ ON c0_.user_id = c1_.id WHERE c1_.id = ?'
);
}
/* NOT ( YET ? ) SUPPORTED .
Can be supported if SimpleSelectExpresion supports SingleValuedPathExpression instead of StateFieldPathExpression .
public function testSingleAssociationPathExpressionInSubselect ()
{
$this -> assertSqlGeneration (
'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' ,
'SELECT (SELECT c0_.user_id FROM cms_phonenumbers c0_ WHERE c0_.user_id = c1_.id) AS sclr0 FROM cms_users c1_ WHERE c1_.id = ?'
);
} */
2011-03-27 23:10:50 +04:00
/**
* @ group DDC - 1077
*/
public function testConstantValueInSelect ()
{
$this -> assertSqlGeneration (
" SELECT u.name, 'foo' AS bar FROM Doctrine \T ests \ Models \ CMS \ CmsUser u " ,
" SELECT c0_.name AS name0, 'foo' AS sclr1 FROM cms_users c0_ "
);
}
2009-07-28 15:43:42 +04:00
public function testSupportsOrderByWithAscAsDefault ()
{
$this -> assertSqlGeneration (
'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u ORDER BY u.id' ,
2009-07-28 20:36:24 +04:00
'SELECT f0_.id AS id0, f0_.username AS username1 FROM forum_users f0_ ORDER BY f0_.id ASC'
2009-07-28 15:43:42 +04:00
);
}
public function testSupportsOrderByAsc ()
{
$this -> assertSqlGeneration (
'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u ORDER BY u.id asc' ,
2009-07-28 20:36:24 +04:00
'SELECT f0_.id AS id0, f0_.username AS username1 FROM forum_users f0_ ORDER BY f0_.id ASC'
2009-07-28 15:43:42 +04:00
);
}
public function testSupportsOrderByDesc ()
{
$this -> assertSqlGeneration (
'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u ORDER BY u.id desc' ,
2009-07-28 20:36:24 +04:00
'SELECT f0_.id AS id0, f0_.username AS username1 FROM forum_users f0_ ORDER BY f0_.id DESC'
2009-07-28 15:43:42 +04:00
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsSelectDistinct ()
2008-05-28 10:01:04 +04:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'SELECT DISTINCT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u' ,
2009-04-09 22:12:48 +04:00
'SELECT DISTINCT c0_.name AS name0 FROM cms_users c0_'
2008-05-28 10:01:04 +04:00
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsAggregateFunctionInSelectedFields ()
2008-05-28 10:01:04 +04:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'SELECT COUNT(u.id) FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id' ,
2009-04-09 22:12:48 +04:00
'SELECT COUNT(c0_.id) AS sclr0 FROM cms_users c0_ GROUP BY c0_.id'
2008-05-28 10:01:04 +04:00
);
}
2011-02-20 07:44:05 +03:00
public function testSupportsAggregateFunctionWithSimpleArithmetic ()
{
$this -> assertSqlGeneration (
'SELECT MAX(u.id + 4) * 2 FROM Doctrine\Tests\Models\CMS\CmsUser u' ,
'SELECT MAX(c0_.id + 4) * 2 AS sclr0 FROM cms_users c0_'
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsWhereClauseWithPositionalParameter ()
2009-01-19 21:40:12 +03:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.id = ?1' ,
2009-04-09 22:12:48 +04:00
'SELECT f0_.id AS id0, f0_.username AS username1 FROM forum_users f0_ WHERE f0_.id = ?'
2009-01-19 21:40:12 +03:00
);
}
2009-01-19 22:24:40 +03:00
2009-07-08 11:48:44 +04:00
public function testSupportsWhereClauseWithNamedParameter ()
2008-05-28 10:01:04 +04:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name' ,
2009-06-14 21:34:28 +04:00
'SELECT f0_.id AS id0, f0_.username AS username1 FROM forum_users f0_ WHERE f0_.username = ?'
2008-05-28 10:01:04 +04:00
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsWhereAndClauseWithNamedParameters ()
2009-01-21 21:25:05 +03:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'select u from Doctrine\Tests\Models\Forum\ForumUser u where u.username = :name and u.username = :name2' ,
2009-06-14 21:34:28 +04:00
'SELECT f0_.id AS id0, f0_.username AS username1 FROM forum_users f0_ WHERE f0_.username = ? AND f0_.username = ?'
2009-01-21 21:25:05 +03:00
);
}
2008-05-28 10:01:04 +04:00
2009-07-08 11:48:44 +04:00
public function testSupportsCombinedWhereClauseWithNamedParameter ()
2008-05-28 10:01:04 +04:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'select u from Doctrine\Tests\Models\Forum\ForumUser u where (u.username = :name OR u.username = :name2) AND u.id = :id' ,
2009-06-14 21:34:28 +04:00
'SELECT f0_.id AS id0, f0_.username AS username1 FROM forum_users f0_ WHERE (f0_.username = ? OR f0_.username = ?) AND f0_.id = ?'
2008-05-28 10:01:04 +04:00
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsAggregateFunctionInASelectDistinct ()
2009-01-21 21:25:05 +03:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'SELECT COUNT(DISTINCT u.name) FROM Doctrine\Tests\Models\CMS\CmsUser u' ,
2009-04-09 22:12:48 +04:00
'SELECT COUNT(DISTINCT c0_.name) AS sclr0 FROM cms_users c0_'
2009-01-21 21:25:05 +03:00
);
}
2008-05-28 10:01:04 +04:00
2008-08-23 20:42:23 +04:00
// Ticket #668
2009-07-08 11:48:44 +04:00
public function testSupportsASqlKeywordInAStringLiteralParam ()
2008-08-23 20:42:23 +04:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
" SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name LIKE '%foo OR bar%' " ,
2009-04-09 22:12:48 +04:00
" SELECT c0_.name AS name0 FROM cms_users c0_ WHERE c0_.name LIKE '%foo OR bar%' "
2008-08-23 20:42:23 +04:00
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsArithmeticExpressionsInWherePart ()
2009-01-21 21:25:05 +03:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((u.id + 5000) * u.id + 3) < 10000000' ,
2010-04-30 05:15:36 +04:00
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (c0_.id + 5000) * c0_.id + 3 < 10000000'
2009-01-21 21:25:05 +03:00
);
}
2010-04-11 18:43:33 +04:00
public function testSupportsMultipleEntitiesInFromClause ()
2010-02-14 13:08:58 +03:00
{
$this -> assertSqlGeneration (
2010-07-20 07:51:01 +04:00
'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' ,
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c1_.id AS id4, c1_.topic AS topic5, c1_.text AS text6, c1_.version AS version7 FROM cms_users c0_, cms_articles c1_ INNER JOIN cms_users c2_ ON c1_.user_id = c2_.id WHERE c0_.id = c2_.id'
);
}
public function testSupportsMultipleEntitiesInFromClauseUsingPathExpression ()
{
$this -> assertSqlGeneration (
'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u, Doctrine\Tests\Models\CMS\CmsArticle a WHERE u.id = a.user' ,
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c1_.id AS id4, c1_.topic AS topic5, c1_.text AS text6, c1_.version AS version7 FROM cms_users c0_, cms_articles c1_ WHERE c0_.id = c1_.user_id'
2010-02-14 13:08:58 +03:00
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsPlainJoinWithoutClause ()
2009-01-21 21:25:05 +03:00
{
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a' ,
2009-04-09 22:12:48 +04:00
'SELECT c0_.id AS id0, c1_.id AS id1 FROM cms_users c0_ LEFT JOIN cms_articles c1_ ON c0_.id = c1_.user_id'
2009-01-21 21:25:05 +03:00
);
$this -> assertSqlGeneration (
2009-01-22 22:38:10 +03:00
'SELECT u.id, a.id from Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a' ,
2009-04-09 22:12:48 +04:00
'SELECT c0_.id AS id0, c1_.id AS id1 FROM cms_users c0_ INNER JOIN cms_articles c1_ ON c0_.id = c1_.user_id'
2009-01-21 21:25:05 +03:00
);
}
2008-08-23 20:42:23 +04:00
2010-02-14 12:53:38 +03:00
/**
* @ group DDC - 135
*/
public function testSupportsJoinAndWithClauseRestriction ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u LEFT JOIN u.articles a WITH a.topic LIKE '%foo%' " ,
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ LEFT JOIN cms_articles c1_ ON c0_.id = c1_.user_id AND (c1_.topic LIKE '%foo%') "
);
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u INNER JOIN u.articles a WITH a.topic LIKE '%foo%' " ,
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ INNER JOIN cms_articles c1_ ON c0_.id = c1_.user_id AND (c1_.topic LIKE '%foo%') "
);
}
/**
* @ group DDC - 135
* @ group DDC - 177
*/
public function testJoinOnClause_NotYetSupported_ThrowsException ()
{
$this -> setExpectedException ( 'Doctrine\ORM\Query\QueryException' );
$sql = $this -> _em -> createQuery (
" SELECT u, a FROM Doctrine \T ests \ Models \ CMS \ CmsUser u LEFT JOIN u.articles a ON a.topic LIKE '%foo%' "
) -> getSql ();
}
2009-07-08 11:48:44 +04:00
public function testSupportsMultipleJoins ()
2009-01-21 21:25:05 +03:00
{
$this -> assertSqlGeneration (
2010-12-28 12:17:33 +03:00
'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' ,
2009-04-09 22:12:48 +04:00
'SELECT c0_.id AS id0, c1_.id AS id1, c2_.phonenumber AS phonenumber2, c3_.id AS id3 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'
2009-01-21 21:25:05 +03:00
);
}
2010-03-05 19:35:00 +03:00
2009-07-08 11:48:44 +04:00
public function testSupportsTrimFunction ()
2009-03-23 20:39:33 +03:00
{
$this -> assertSqlGeneration (
" SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE TRIM(TRAILING ' ' FROM u.name) = 'someone' " ,
2009-04-09 22:12:48 +04:00
" SELECT c0_.name AS name0 FROM cms_users c0_ WHERE TRIM(TRAILING ' ' FROM c0_.name) = 'someone' "
2009-03-23 20:39:33 +03:00
);
}
2009-01-21 21:25:05 +03:00
2009-03-28 20:10:41 +03:00
// Ticket 894
2009-07-08 11:48:44 +04:00
public function testSupportsBetweenClauseWithPositionalParameters ()
2009-03-28 20:10:41 +03:00
{
$this -> assertSqlGeneration (
" SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.id BETWEEN ?1 AND ?2 " ,
2009-04-09 22:12:48 +04:00
" SELECT c0_.name AS name0 FROM cms_users c0_ WHERE c0_.id BETWEEN ? AND ? "
2009-03-28 20:10:41 +03:00
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsFunctionalExpressionsInWherePart ()
2009-01-21 21:25:05 +03:00
{
$this -> assertSqlGeneration (
2009-03-28 20:10:41 +03:00
" SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE TRIM(u.name) = 'someone' " ,
2009-01-21 21:25:05 +03:00
// String quoting in the SQL usually depends on the database platform.
// This test works with a mock connection which uses ' for string quoting.
2010-02-12 00:19:54 +03:00
" SELECT c0_.name AS name0 FROM cms_users c0_ WHERE TRIM(c0_.name) = 'someone' "
2009-01-21 21:25:05 +03:00
);
2009-03-28 20:10:41 +03:00
}
2009-01-21 21:25:05 +03:00
2010-07-30 08:30:02 +04:00
public function testSupportsInstanceOfExpressionsInWherePart ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ Company \ CompanyPerson u WHERE u INSTANCE OF Doctrine \T ests \ Models \ Company \ CompanyEmployee " ,
2011-08-15 08:53:56 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee') "
);
}
2011-10-29 22:42:44 +04:00
2011-08-15 08:53:56 +04:00
public function testSupportsInstanceOfExpressionInWherePartWithMultipleValues ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ Company \ CompanyPerson u WHERE u INSTANCE OF (Doctrine \T ests \ Models \ Company \ CompanyEmployee, \ Doctrine \T ests \ Models \ Company \ CompanyManager) " ,
" SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee', 'manager') "
2010-07-30 08:30:02 +04:00
);
}
2011-10-29 22:42:44 +04:00
2011-06-05 12:48:21 +04:00
/**
* @ group DDC - 1194
*/
public function testSupportsInstanceOfExpressionsInWherePartPrefixedSlash ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ Company \ CompanyPerson u WHERE u INSTANCE OF \ Doctrine \T ests \ Models \ Company \ CompanyEmployee " ,
2011-08-15 08:53:56 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee') "
2011-06-05 12:48:21 +04:00
);
}
2011-10-29 22:42:44 +04:00
2011-06-05 12:48:21 +04:00
/**
* @ group DDC - 1194
*/
public function testSupportsInstanceOfExpressionsInWherePartWithUnrelatedClass ()
{
$this -> assertInvalidSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ Company \ CompanyPerson u WHERE u INSTANCE OF \ Doctrine \T ests \ Models \ CMS \ CmsUser " ,
" Doctrine \ ORM \ Query \ QueryException "
);
}
2010-07-30 08:30:02 +04:00
public function testSupportsInstanceOfExpressionsInWherePartInDeeperLevel ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ Company \ CompanyEmployee u WHERE u INSTANCE OF Doctrine \T ests \ Models \ Company \ CompanyManager " ,
2011-08-28 20:48:15 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c0_.discr AS discr5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id WHERE c0_.discr IN ('manager') "
2010-07-30 08:30:02 +04:00
);
}
public function testSupportsInstanceOfExpressionsInWherePartInDeepestLevel ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ Company \ CompanyManager u WHERE u INSTANCE OF Doctrine \T ests \ Models \ Company \ CompanyManager " ,
2011-08-28 20:48:15 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c2_.title AS title5, c0_.discr AS discr6 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') "
2010-07-30 08:30:02 +04:00
);
}
public function testSupportsInstanceOfExpressionsUsingInputParameterInWherePart ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ Company \ CompanyPerson u WHERE u INSTANCE OF ?1 " ,
2011-08-15 08:53:56 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee') " ,
2010-07-30 08:30:02 +04:00
array (), array ( 1 => $this -> _em -> getClassMetadata ( 'Doctrine\Tests\Models\Company\CompanyEmployee' ))
);
}
2008-08-23 20:42:23 +04:00
// Ticket #973
2009-07-08 11:48:44 +04:00
public function testSupportsSingleValuedInExpressionWithoutSpacesInWherePart ()
2008-08-23 20:42:23 +04:00
{
$this -> assertSqlGeneration (
2011-12-04 11:41:54 +04:00
" SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE IDENTITY(u.email) IN(46) " ,
" SELECT c0_.name AS name0 FROM cms_users c0_ WHERE c0_.email_id IN (46) "
2008-08-23 20:42:23 +04:00
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsMultipleValuedInExpressionInWherePart ()
2008-08-23 20:42:23 +04:00
{
$this -> assertSqlGeneration (
2009-03-28 20:10:41 +03:00
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN (1, 2)' ,
2009-04-09 22:12:48 +04:00
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.id IN (1, 2)'
2008-08-23 20:42:23 +04:00
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsNotInExpressionInWherePart ()
2008-05-28 10:01:04 +04:00
{
$this -> assertSqlGeneration (
2011-12-04 11:41:54 +04:00
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :id NOT IN (1)' ,
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE ? NOT IN (1)'
2008-05-28 10:01:04 +04:00
);
}
2010-08-12 07:16:07 +04:00
public function testInExpressionWithSingleValuedAssociationPathExpressionInWherePart ()
{
$this -> assertSqlGeneration (
'SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u WHERE u.avatar IN (?1, ?2)' ,
'SELECT f0_.id AS id0, f0_.username AS username1 FROM forum_users f0_ WHERE f0_.avatar_id IN (?, ?)'
);
}
public function testInvalidInExpressionWithSingleValuedAssociationPathExpressionOnInverseSide ()
{
// We do not support SingleValuedAssociationPathExpression on inverse side
$this -> assertInvalidSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.address IN (?1, ?2) " ,
" Doctrine \ ORM \ Query \ QueryException "
);
}
2009-07-08 11:48:44 +04:00
public function testSupportsConcatFunctionForMysqlAndPostgresql ()
2008-05-24 22:18:37 +04:00
{
2009-03-28 20:10:41 +03:00
$connMock = $this -> _em -> getConnection ();
$orgPlatform = $connMock -> getDatabasePlatform ();
$connMock -> setDatabasePlatform ( new \Doctrine\DBAL\Platforms\MySqlPlatform );
2008-05-27 08:52:50 +04:00
$this -> assertSqlGeneration (
2009-03-28 20:10:41 +03:00
" SELECT u.id FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE CONCAT(u.name, 's') = ?1 " ,
2009-04-09 22:12:48 +04:00
" SELECT c0_.id AS id0 FROM cms_users c0_ WHERE CONCAT(c0_.name, 's') = ? "
2009-03-28 20:10:41 +03:00
);
$this -> assertSqlGeneration (
" SELECT CONCAT(u.id, u.name) FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.id = ?1 " ,
2009-04-09 22:12:48 +04:00
" SELECT CONCAT(c0_.id, c0_.name) AS sclr0 FROM cms_users c0_ WHERE c0_.id = ? "
2008-05-27 08:52:50 +04:00
);
2009-03-28 20:10:41 +03:00
$connMock -> setDatabasePlatform ( new \Doctrine\DBAL\Platforms\PostgreSqlPlatform );
$this -> assertSqlGeneration (
" SELECT u.id FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE CONCAT(u.name, 's') = ?1 " ,
2009-04-09 22:12:48 +04:00
" SELECT c0_.id AS id0 FROM cms_users c0_ WHERE c0_.name || 's' = ? "
2009-03-28 20:10:41 +03:00
);
$this -> assertSqlGeneration (
" SELECT CONCAT(u.id, u.name) FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.id = ?1 " ,
2009-04-09 22:12:48 +04:00
" SELECT c0_.id || c0_.name AS sclr0 FROM cms_users c0_ WHERE c0_.id = ? "
2009-03-28 20:10:41 +03:00
);
$connMock -> setDatabasePlatform ( $orgPlatform );
}
2009-05-17 23:27:12 +04:00
2009-07-08 11:48:44 +04:00
public function testSupportsExistsExpressionInWherePartWithCorrelatedSubquery ()
2009-05-17 23:27:12 +04:00
{
$this -> assertSqlGeneration (
'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)' ,
'SELECT c0_.id AS id0 FROM cms_users c0_ WHERE EXISTS (SELECT c1_.phonenumber FROM cms_phonenumbers c1_ WHERE c1_.phonenumber = c0_.id)'
);
}
2010-02-25 23:25:28 +03:00
2010-05-16 15:30:40 +04:00
/**
* @ group DDC - 593
*/
public function testSubqueriesInComparisonExpression ()
{
$this -> assertSqlGeneration (
'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))' ,
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 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 = ?))'
);
}
2011-12-04 00:19:21 +04:00
public function testSupportsMemberOfExpressionOneToMany ()
2009-06-14 21:34:28 +04:00
{
// "Get all users who have $phone as a phonenumber." (*cough* doesnt really make sense...)
2011-12-04 00:19:21 +04:00
$q = $this -> _em -> createQuery ( 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.phonenumbers' );
$q -> setHint ( Query :: HINT_FORCE_PARTIAL_LOAD , true );
2010-03-05 19:35:00 +03:00
2009-06-14 21:34:28 +04:00
$phone = new \Doctrine\Tests\Models\CMS\CmsPhonenumber ;
$phone -> phonenumber = 101 ;
2011-12-04 00:19:21 +04:00
$q -> setParameter ( 'param' , $phone );
2010-03-05 19:35:00 +03:00
2009-06-14 21:34:28 +04:00
$this -> assertEquals (
'SELECT c0_.id AS id0 FROM cms_users c0_ WHERE EXISTS (SELECT 1 FROM cms_phonenumbers c1_ WHERE c0_.id = c1_.user_id AND c1_.phonenumber = ?)' ,
2011-12-04 00:19:21 +04:00
$q -> getSql ()
2009-06-14 21:34:28 +04:00
);
2011-12-04 00:19:21 +04:00
}
2010-03-05 19:35:00 +03:00
2011-12-04 00:19:21 +04:00
public function testSupportsMemberOfExpressionManyToMany ()
{
2009-06-14 21:34:28 +04:00
// "Get all users who are members of $group."
2011-12-04 00:19:21 +04:00
$q = $this -> _em -> createQuery ( 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE :param MEMBER OF u.groups' );
$q -> setHint ( Query :: HINT_FORCE_PARTIAL_LOAD , true );
2010-03-05 19:35:00 +03:00
2009-06-14 21:34:28 +04:00
$group = new \Doctrine\Tests\Models\CMS\CmsGroup ;
$group -> id = 101 ;
2011-12-04 00:19:21 +04:00
$q -> setParameter ( 'param' , $group );
2010-03-05 19:35:00 +03:00
2009-06-14 21:34:28 +04:00
$this -> assertEquals (
2010-03-27 01:07:31 +03:00
'SELECT c0_.id AS id0 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 = ?)' ,
2011-12-04 00:19:21 +04:00
$q -> getSql ()
2009-06-14 21:34:28 +04:00
);
2011-12-04 00:19:21 +04:00
}
2010-03-05 19:35:00 +03:00
2011-12-04 00:19:21 +04:00
public function testSupportsMemberOfExpressionSelfReferencing ()
{
2009-06-14 21:34:28 +04:00
// "Get all persons who have $person as a friend."
// Tough one: Many-many self-referencing ("friends") with class table inheritance
2011-12-04 00:19:21 +04:00
$q = $this -> _em -> createQuery ( 'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p WHERE :param MEMBER OF p.friends' );
2009-06-14 21:34:28 +04:00
$person = new \Doctrine\Tests\Models\Company\CompanyPerson ;
2010-07-20 16:20:13 +04:00
$this -> _em -> getClassMetadata ( get_class ( $person )) -> setIdentifierValues ( $person , array ( 'id' => 101 ));
2011-12-04 00:19:21 +04:00
$q -> setParameter ( 'param' , $person );
2009-06-14 21:34:28 +04:00
$this -> assertEquals (
2011-11-03 08:44:50 +04:00
'SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c2_.salary AS salary3, c2_.department AS department4, c2_.startDate AS startDate5, c0_.discr AS discr6, c0_.spouse_id AS spouse_id7, c1_.car_id AS car_id8 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 = ?)' ,
2011-12-04 00:19:21 +04:00
$q -> getSql ()
);
}
public function testSupportsMemberOfWithSingleValuedAssociation ()
{
// Impossible example, but it illustrates the purpose
$q = $this -> _em -> createQuery ( 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.email MEMBER OF u.groups' );
$this -> assertEquals (
'SELECT c0_.id AS id0 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 = c0_.email_id)' ,
$q -> getSql ()
);
}
public function testSupportsMemberOfWithIdentificationVariable ()
{
// Impossible example, but it illustrates the purpose
$q = $this -> _em -> createQuery ( 'SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u MEMBER OF u.groups' );
$this -> assertEquals (
'SELECT c0_.id AS id0 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 = c0_.id)' ,
$q -> getSql ()
2009-06-14 21:34:28 +04:00
);
}
2009-05-17 23:27:12 +04:00
2009-07-08 11:48:44 +04:00
public function testSupportsCurrentDateFunction ()
2009-06-20 16:59:33 +04:00
{
2009-10-15 18:39:43 +04:00
$q = $this -> _em -> createQuery ( 'SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime > current_date()' );
$q -> setHint ( Query :: HINT_FORCE_PARTIAL_LOAD , true );
2010-02-26 22:39:12 +03:00
$this -> assertEquals ( 'SELECT d0_.id AS id0 FROM date_time_model d0_ WHERE d0_.col_datetime > CURRENT_DATE' , $q -> getSql ());
2009-06-20 16:59:33 +04:00
}
2009-07-08 11:48:44 +04:00
public function testSupportsCurrentTimeFunction ()
2009-06-20 18:24:21 +04:00
{
2009-10-15 18:39:43 +04:00
$q = $this -> _em -> createQuery ( 'SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.time > current_time()' );
$q -> setHint ( Query :: HINT_FORCE_PARTIAL_LOAD , true );
2010-02-26 22:39:12 +03:00
$this -> assertEquals ( 'SELECT d0_.id AS id0 FROM date_time_model d0_ WHERE d0_.col_time > CURRENT_TIME' , $q -> getSql ());
2009-06-20 18:24:21 +04:00
}
2009-07-08 11:48:44 +04:00
public function testSupportsCurrentTimestampFunction ()
2009-06-20 18:24:21 +04:00
{
2009-10-15 18:39:43 +04:00
$q = $this -> _em -> createQuery ( 'SELECT d.id FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime > current_timestamp()' );
$q -> setHint ( Query :: HINT_FORCE_PARTIAL_LOAD , true );
2010-02-26 22:39:12 +03:00
$this -> assertEquals ( 'SELECT d0_.id AS id0 FROM date_time_model d0_ WHERE d0_.col_datetime > CURRENT_TIMESTAMP' , $q -> getSql ());
2009-06-20 18:24:21 +04:00
}
2010-04-14 07:04:44 +04:00
public function testExistsExpressionInWhereCorrelatedSubqueryAssocCondition ()
2009-05-17 23:27:12 +04:00
{
$this -> assertSqlGeneration (
// DQL
// The result of this query consists of all employees whose spouses are also employees.
' SELECT DISTINCT emp FROM Doctrine\Tests\Models\CMS\CmsEmployee emp
WHERE EXISTS (
SELECT spouseEmp
FROM Doctrine\Tests\Models\CMS\CmsEmployee spouseEmp
WHERE spouseEmp = emp . spouse ) ' ,
// SQL
'SELECT DISTINCT c0_.id AS id0, c0_.name AS name1 FROM cms_employees c0_'
. ' WHERE EXISTS ('
. 'SELECT c1_.id FROM cms_employees c1_ WHERE c1_.id = c0_.spouse_id'
. ')'
2011-10-28 18:56:14 +04:00
);
}
2009-05-17 23:27:12 +04:00
2011-10-28 18:56:14 +04:00
public function testExistsExpressionWithSimpleSelectReturningScalar ()
{
$this -> assertSqlGeneration (
// DQL
// The result of this query consists of all employees whose spouses are also employees.
' SELECT DISTINCT emp FROM Doctrine\Tests\Models\CMS\CmsEmployee emp
WHERE EXISTS (
SELECT 1
FROM Doctrine\Tests\Models\CMS\CmsEmployee spouseEmp
WHERE spouseEmp = emp . spouse ) ' ,
// SQL
'SELECT DISTINCT c0_.id AS id0, c0_.name AS name1 FROM cms_employees c0_'
. ' WHERE EXISTS ('
2011-10-28 20:25:12 +04:00
. 'SELECT 1 AS sclr2 FROM cms_employees c1_ WHERE c1_.id = c0_.spouse_id'
2011-10-28 18:56:14 +04:00
. ')'
2009-05-17 23:27:12 +04:00
);
2010-04-14 07:04:44 +04:00
}
2009-07-14 02:59:36 +04:00
public function testLimitFromQueryClass ()
{
$q = $this -> _em
-> createQuery ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u' )
-> setMaxResults ( 10 );
2011-09-07 20:12:02 +04:00
$this -> assertEquals ( 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c0_.email_id AS email_id4 FROM cms_users c0_ LIMIT 10' , $q -> getSql ());
2009-07-14 02:59:36 +04:00
}
public function testLimitAndOffsetFromQueryClass ()
{
$q = $this -> _em
-> createQuery ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u' )
-> setMaxResults ( 10 )
-> setFirstResult ( 0 );
2011-09-07 20:12:02 +04:00
$this -> assertEquals ( 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c0_.email_id AS email_id4 FROM cms_users c0_ LIMIT 10 OFFSET 0' , $q -> getSql ());
2009-07-14 02:59:36 +04:00
}
2010-03-05 19:35:00 +03:00
2009-08-05 19:47:41 +04:00
public function testSizeFunction ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE SIZE(u.phonenumbers) > 1 " ,
2010-02-14 21:44:33 +03:00
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (SELECT COUNT(*) FROM cms_phonenumbers c1_ WHERE c1_.user_id = c0_.id) > 1 "
2009-08-05 19:47:41 +04:00
);
}
2010-03-05 19:35:00 +03:00
2010-02-10 05:31:55 +03:00
public function testSizeFunctionSupportsManyToMany ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE SIZE(u.groups) > 1 " ,
2010-02-14 21:44:33 +03:00
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (SELECT COUNT(*) FROM cms_users_groups c1_ WHERE c1_.user_id = c0_.id) > 1 "
2010-02-10 05:31:55 +03:00
);
}
2009-08-05 19:47:41 +04:00
public function testEmptyCollectionComparisonExpression ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.phonenumbers IS EMPTY " ,
2010-02-14 21:44:33 +03:00
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (SELECT COUNT(*) FROM cms_phonenumbers c1_ WHERE c1_.user_id = c0_.id) = 0 "
2009-08-05 19:47:41 +04:00
);
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.phonenumbers IS NOT EMPTY " ,
2010-02-14 21:44:33 +03:00
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (SELECT COUNT(*) FROM cms_phonenumbers c1_ WHERE c1_.user_id = c0_.id) > 0 "
2009-08-05 19:47:41 +04:00
);
}
2010-03-05 19:35:00 +03:00
2009-08-16 20:36:00 +04:00
public function testNestedExpressions ()
{
$this -> assertSqlGeneration (
" select u from Doctrine \T ests \ Models \ CMS \ CmsUser u where u.id > 10 and u.id < 42 and ((u.id * 2) > 5) " ,
2010-04-30 05:15:36 +04:00
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.id > 10 AND c0_.id < 42 AND (c0_.id * 2 > 5) "
2009-08-16 20:36:00 +04:00
);
}
2010-03-05 19:35:00 +03:00
2009-08-16 20:36:00 +04:00
public function testNestedExpressions2 ()
{
$this -> assertSqlGeneration (
" select u from Doctrine \T ests \ Models \ CMS \ CmsUser u where (u.id > 10) and (u.id < 42 and ((u.id * 2) > 5)) or u.id <> 42 " ,
2010-04-30 05:15:36 +04:00
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (c0_.id > 10) AND (c0_.id < 42 AND (c0_.id * 2 > 5)) OR c0_.id <> 42 "
2009-08-16 20:36:00 +04:00
);
}
2010-03-05 19:35:00 +03:00
2009-08-16 20:36:00 +04:00
public function testNestedExpressions3 ()
{
$this -> assertSqlGeneration (
" select u from Doctrine \T ests \ Models \ CMS \ CmsUser u where (u.id > 10) and (u.id between 1 and 10 or u.id in (1, 2, 3, 4, 5)) " ,
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (c0_.id > 10) AND (c0_.id BETWEEN 1 AND 10 OR c0_.id IN (1, 2, 3, 4, 5)) "
);
}
2010-03-05 19:35:00 +03:00
2009-09-11 23:50:48 +04:00
public function testOrderByCollectionAssociationSize ()
{
$this -> assertSqlGeneration (
" select u, size(u.articles) as numArticles from Doctrine \T ests \ Models \ CMS \ CmsUser u order by numArticles " ,
2010-02-14 21:44:33 +03:00
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT COUNT(*) FROM cms_articles c1_ WHERE c1_.user_id = c0_.id) AS sclr4 FROM cms_users c0_ ORDER BY sclr4 ASC "
2009-09-11 23:50:48 +04:00
);
}
2011-10-29 22:42:44 +04:00
2011-08-14 07:46:02 +04:00
public function testOrderBySupportsSingleValuedPathExpressionOwningSide ()
{
$this -> assertSqlGeneration (
" select a from Doctrine \T ests \ Models \ CMS \ CmsArticle a order by a.user " ,
" SELECT c0_.id AS id0, c0_.topic AS topic1, c0_.text AS text2, c0_.version AS version3 FROM cms_articles c0_ ORDER BY c0_.user_id ASC "
);
}
2011-10-29 22:42:44 +04:00
2011-08-14 07:46:02 +04:00
/**
* @ expectedException Doctrine\ORM\Query\QueryException
*/
public function testOrderBySupportsSingleValuedPathExpressionInverseSide ()
{
$q = $this -> _em -> createQuery ( " select u from Doctrine \T ests \ Models \ CMS \ CmsUser u order by u.address " );
$q -> getSQL ();
}
2010-03-05 19:35:00 +03:00
2009-10-13 14:48:46 +04:00
public function testBooleanLiteralInWhereOnSqlite ()
{
$oldPlat = $this -> _em -> getConnection () -> getDatabasePlatform ();
$this -> _em -> getConnection () -> setDatabasePlatform ( new \Doctrine\DBAL\Platforms\SqlitePlatform );
2010-03-05 19:35:00 +03:00
2009-10-13 14:48:46 +04:00
$this -> assertSqlGeneration (
" SELECT b FROM Doctrine \T ests \ Models \ Generic \ BooleanModel b WHERE b.booleanField = true " ,
" SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 1 "
);
2010-03-05 19:35:00 +03:00
2009-10-13 14:48:46 +04:00
$this -> assertSqlGeneration (
" SELECT b FROM Doctrine \T ests \ Models \ Generic \ BooleanModel b WHERE b.booleanField = false " ,
" SELECT b0_.id AS id0, b0_.booleanField AS booleanField1 FROM boolean_model b0_ WHERE b0_.booleanField = 0 "
);
2010-03-05 19:35:00 +03:00
2009-10-13 14:48:46 +04:00
$this -> _em -> getConnection () -> setDatabasePlatform ( $oldPlat );
}
2010-03-05 19:35:00 +03:00
2009-10-13 14:48:46 +04:00
public function testBooleanLiteralInWhereOnPostgres ()
{
$oldPlat = $this -> _em -> getConnection () -> getDatabasePlatform ();
$this -> _em -> getConnection () -> setDatabasePlatform ( new \Doctrine\DBAL\Platforms\PostgreSqlPlatform );
2010-03-05 19:35:00 +03:00
2009-10-13 14:48:46 +04:00
$this -> assertSqlGeneration (
" SELECT b FROM Doctrine \T ests \ Models \ Generic \ BooleanModel b WHERE b.booleanField = true " ,
2011-10-22 18:27:56 +04:00
" SELECT b0_.id AS id0, b0_.booleanField AS booleanfield1 FROM boolean_model b0_ WHERE b0_.booleanField = true "
2009-10-13 14:48:46 +04:00
);
2010-03-05 19:35:00 +03:00
2009-10-13 14:48:46 +04:00
$this -> assertSqlGeneration (
" SELECT b FROM Doctrine \T ests \ Models \ Generic \ BooleanModel b WHERE b.booleanField = false " ,
2011-10-22 18:27:56 +04:00
" SELECT b0_.id AS id0, b0_.booleanField AS booleanfield1 FROM boolean_model b0_ WHERE b0_.booleanField = false "
2009-10-13 14:48:46 +04:00
);
2010-03-05 19:35:00 +03:00
2009-10-13 14:48:46 +04:00
$this -> _em -> getConnection () -> setDatabasePlatform ( $oldPlat );
}
2010-02-20 21:27:05 +03:00
2009-08-13 14:13:06 +04:00
public function testSingleValuedAssociationFieldInWhere ()
{
2010-02-20 21:27:05 +03:00
$this -> assertSqlGeneration (
2009-08-13 14:13:06 +04:00
" SELECT p FROM Doctrine \T ests \ Models \ CMS \ CmsPhonenumber p WHERE p.user = ?1 " ,
2010-02-20 21:27:05 +03:00
" SELECT c0_.phonenumber AS phonenumber0 FROM cms_phonenumbers c0_ WHERE c0_.user_id = ? "
2009-08-13 14:13:06 +04:00
);
2009-12-27 06:26:15 +03:00
}
2010-02-20 00:28:17 +03:00
public function testSingleValuedAssociationNullCheckOnOwningSide ()
{
$this -> assertSqlGeneration (
" SELECT a FROM Doctrine \T ests \ Models \ CMS \ CmsAddress a WHERE a.user IS NULL " ,
" SELECT c0_.id AS id0, c0_.country AS country1, c0_.zip AS zip2, c0_.city AS city3 FROM cms_addresses c0_ WHERE c0_.user_id IS NULL "
);
}
// Null check on inverse side has to happen through explicit JOIN.
// "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.address IS NULL"
// where the CmsUser is the inverse side is not supported.
public function testSingleValuedAssociationNullCheckOnInverseSide ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u LEFT JOIN u.address a WHERE a.id IS NULL " ,
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ LEFT JOIN cms_addresses c1_ ON c0_.id = c1_.user_id WHERE c1_.id IS NULL "
);
}
2010-03-05 19:35:00 +03:00
2010-02-20 21:27:05 +03:00
/**
* @ group DDC - 339
*/
public function testStringFunctionLikeExpression ()
{
$this -> assertSqlGeneration (
" SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE LOWER(u.name) LIKE '%foo OR bar%' " ,
" SELECT c0_.name AS name0 FROM cms_users c0_ WHERE LOWER(c0_.name) LIKE '%foo OR bar%' "
);
$this -> assertSqlGeneration (
" SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE LOWER(u.name) LIKE :str " ,
" SELECT c0_.name AS name0 FROM cms_users c0_ WHERE LOWER(c0_.name) LIKE ? "
);
$this -> assertSqlGeneration (
" SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE CONCAT(UPPER(u.name), '_moo') LIKE :str " ,
" SELECT c0_.name AS name0 FROM cms_users c0_ WHERE UPPER(c0_.name) || '_moo' LIKE ? "
);
}
2010-02-21 03:06:34 +03:00
/**
* @ group DDC - 338
*/
public function testOrderedCollectionFetchJoined ()
{
$this -> assertSqlGeneration (
" SELECT r, l FROM Doctrine \T ests \ Models \R outing \R outingRoute r JOIN r.legs l " ,
" SELECT r0_.id AS id0, r1_.id AS id1, r1_.departureDate AS departureDate2, r1_.arrivalDate AS arrivalDate3 FROM RoutingRoute r0_ INNER JOIN RoutingRouteLegs r2_ ON r0_.id = r2_.route_id INNER JOIN RoutingLeg r1_ ON r1_.id = r2_.leg_id " .
" ORDER BY r1_.departureDate ASC "
);
}
2010-02-25 23:25:28 +03:00
public function testSubselectInSelect ()
{
$this -> assertSqlGeneration (
" SELECT u.name, (SELECT COUNT(p.phonenumber) FROM Doctrine \T ests \ Models \ CMS \ CmsPhonenumber p WHERE p.phonenumber = 1234) pcount FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name = 'jon' " ,
2010-02-25 23:31:53 +03:00
" SELECT c0_.name AS name0, (SELECT COUNT(c1_.phonenumber) AS dctrn__1 FROM cms_phonenumbers c1_ WHERE c1_.phonenumber = 1234) AS sclr1 FROM cms_users c0_ WHERE c0_.name = 'jon' "
2010-02-25 23:25:28 +03:00
);
}
2010-04-15 05:49:53 +04:00
/**
2010-04-09 00:50:06 +04:00
* @ group locking
* @ group DDC - 178
*/
public function testPessimisticWriteLockQueryHint ()
{
if ( $this -> _em -> getConnection () -> getDatabasePlatform () instanceof \Doctrine\DBAL\Platforms\SqlitePlatform ) {
$this -> markTestSkipped ( 'SqLite does not support Row locking at all.' );
}
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.username = 'gblanco' " ,
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 " .
" FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR UPDATE " ,
2010-05-15 13:48:20 +04:00
array ( Query :: HINT_LOCK_MODE => \Doctrine\DBAL\LockMode :: PESSIMISTIC_WRITE )
2010-04-09 00:50:06 +04:00
);
}
/**
* @ group locking
* @ group DDC - 178
*/
public function testPessimisticReadLockQueryHintPostgreSql ()
{
$this -> _em -> getConnection () -> setDatabasePlatform ( new \Doctrine\DBAL\Platforms\PostgreSqlPlatform );
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.username = 'gblanco' " ,
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 " .
" FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR SHARE " ,
2010-05-15 13:48:20 +04:00
array ( Query :: HINT_LOCK_MODE => \Doctrine\DBAL\LockMode :: PESSIMISTIC_READ )
2010-05-02 15:02:44 +04:00
);
}
/**
* @ group DDC - 430
2010-04-15 05:49:53 +04:00
*/
public function testSupportSelectWithMoreThan10InputParameters ()
{
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ 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 " ,
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 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 = ? "
);
}
2010-04-15 06:27:33 +04:00
/**
2010-04-09 00:50:06 +04:00
* @ group locking
* @ group DDC - 178
*/
public function testPessimisticReadLockQueryHintMySql ()
{
$this -> _em -> getConnection () -> setDatabasePlatform ( new \Doctrine\DBAL\Platforms\MySqlPlatform );
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.username = 'gblanco' " ,
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 " .
" FROM cms_users c0_ WHERE c0_.username = 'gblanco' LOCK IN SHARE MODE " ,
2010-05-15 13:48:20 +04:00
array ( Query :: HINT_LOCK_MODE => \Doctrine\DBAL\LockMode :: PESSIMISTIC_READ )
2010-04-09 00:50:06 +04:00
);
}
/**
* @ group locking
* @ group DDC - 178
*/
public function testPessimisticReadLockQueryHintOracle ()
{
$this -> _em -> getConnection () -> setDatabasePlatform ( new \Doctrine\DBAL\Platforms\OraclePlatform );
$this -> assertSqlGeneration (
" SELECT u FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.username = 'gblanco' " ,
2011-10-22 18:27:56 +04:00
" SELECT c0_.id AS ID0, c0_.status AS STATUS1, c0_.username AS USERNAME2, c0_.name AS NAME3 " .
2010-04-09 00:50:06 +04:00
" FROM cms_users c0_ WHERE c0_.username = 'gblanco' FOR UPDATE " ,
2010-05-15 13:48:20 +04:00
array ( Query :: HINT_LOCK_MODE => \Doctrine\DBAL\LockMode :: PESSIMISTIC_READ )
2010-04-09 00:50:06 +04:00
);
}
2010-05-02 15:02:44 +04:00
/**
* @ group DDC - 431
2010-04-15 06:27:33 +04:00
*/
public function testSupportToCustomDQLFunctions ()
{
$config = $this -> _em -> getConfiguration ();
$config -> addCustomNumericFunction ( 'MYABS' , 'Doctrine\Tests\ORM\Query\MyAbsFunction' );
$this -> assertSqlGeneration (
'SELECT MYABS(p.phonenumber) FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p' ,
'SELECT ABS(c0_.phonenumber) AS sclr0 FROM cms_phonenumbers c0_'
);
2010-04-15 13:55:03 +04:00
$config -> setCustomNumericFunctions ( array ());
2010-04-15 06:27:33 +04:00
}
2010-10-31 10:13:59 +03:00
/**
* @ group DDC - 826
*/
public function testMappedSuperclassAssociationJoin ()
{
$this -> assertSqlGeneration (
'SELECT f FROM Doctrine\Tests\Models\DirectoryTree\File f JOIN f.parentDirectory d WHERE f.id = ?1' ,
2010-11-19 01:07:32 +03:00
'SELECT f0_.id AS id0, f0_.extension AS extension1, f0_.name AS name2 FROM "file" f0_ INNER JOIN Directory d1_ ON f0_.parentDirectory_id = d1_.id WHERE f0_.id = ?'
2010-10-31 10:13:59 +03:00
);
}
2011-03-20 16:07:33 +03:00
/**
* @ group DDC - 1053
*/
public function testGroupBy ()
{
$this -> assertSqlGeneration (
'SELECT g.id, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g.id' ,
'SELECT c0_.id AS id0, count(c1_.id) AS sclr1 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'
);
}
/**
* @ group DDC - 1053
*/
public function testGroupByIdentificationVariable ()
{
$this -> assertSqlGeneration (
'SELECT g, count(u.id) FROM Doctrine\Tests\Models\CMS\CmsGroup g JOIN g.users u GROUP BY g' ,
2011-11-15 20:28:57 +04:00
'SELECT c0_.id AS id0, c0_.name AS name1, count(c1_.id) AS sclr2 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'
2011-03-20 16:07:33 +03:00
);
}
2011-10-29 22:42:44 +04:00
2011-06-17 23:16:22 +04:00
public function testCaseContainingNullIf ()
{
$this -> assertSqlGeneration (
" SELECT NULLIF(g.id, g.name) AS NullIfEqual FROM Doctrine \T ests \ Models \ CMS \ CmsGroup g " ,
'SELECT NULLIF(c0_.id, c0_.name) AS sclr0 FROM cms_groups c0_'
);
}
2011-10-29 22:42:44 +04:00
2011-06-17 23:16:22 +04:00
public function testCaseContainingCoalesce ()
{
$this -> assertSqlGeneration (
" SELECT COALESCE(NULLIF(u.name, ''), u.username) as Display FROM Doctrine \T ests \ Models \ CMS \ CmsUser u " ,
" SELECT COALESCE(NULLIF(c0_.name, ''), c0_.username) AS sclr0 FROM cms_users c0_ "
);
}
2011-07-26 02:19:26 +04:00
/**
* Test that the right discriminator data is inserted in a subquery .
*/
public function testSubSelectDiscriminator ()
{
$this -> assertSqlGeneration (
" SELECT u.name, (SELECT COUNT(cfc.id) total FROM Doctrine \T ests \ Models \ Company \ CompanyFixContract cfc) as cfc_count FROM Doctrine \T ests \ Models \ CMS \ CmsUser u " ,
" SELECT c0_.name AS name0, (SELECT COUNT(c1_.id) AS dctrn__total FROM company_contracts c1_ WHERE c1_.discr IN ('fix')) AS sclr1 FROM cms_users c0_ "
);
}
2011-07-26 19:15:21 +04:00
public function testIdVariableResultVariableReuse ()
{
$exceptionThrown = false ;
try {
$query = $this -> _em -> createQuery ( " SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u WHERE u.name IN (SELECT u.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u) " );
$query -> getSql ();
$query -> free ();
} catch ( \Exception $e ) {
$exceptionThrown = true ;
}
$this -> assertTrue ( $exceptionThrown );
}
public function testSubSelectAliasesFromOuterQuery ()
{
$this -> assertSqlGeneration (
" SELECT uo, (SELECT ui.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser ui WHERE ui.id = uo.id) AS bar FROM Doctrine \T ests \ Models \ CMS \ CmsUser uo " ,
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT c1_.name FROM cms_users c1_ WHERE c1_.id = c0_.id) AS sclr4 FROM cms_users c0_ "
);
}
public function testSubSelectAliasesFromOuterQueryWithSubquery ()
{
$this -> assertSqlGeneration (
" SELECT uo, (SELECT ui.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser ui WHERE ui.id = uo.id AND ui.name IN (SELECT uii.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser uii)) AS bar FROM Doctrine \T ests \ Models \ CMS \ CmsUser uo " ,
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT c1_.name FROM cms_users c1_ WHERE c1_.id = c0_.id AND c1_.name IN (SELECT c2_.name FROM cms_users c2_)) AS sclr4 FROM cms_users c0_ "
);
}
2011-07-28 01:22:20 +04:00
2011-09-05 10:16:01 +04:00
public function testSubSelectAliasesFromOuterQueryReuseInWhereClause ()
{
$this -> assertSqlGeneration (
" SELECT uo, (SELECT ui.name FROM Doctrine \T ests \ Models \ CMS \ CmsUser ui WHERE ui.id = uo.id) AS bar FROM Doctrine \T ests \ Models \ CMS \ CmsUser uo WHERE bar = ?0 " ,
" SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT c1_.name FROM cms_users c1_ WHERE c1_.id = c0_.id) AS sclr4 FROM cms_users c0_ WHERE sclr4 = ? "
);
}
2011-07-28 01:22:20 +04:00
/**
* @ group DDC - 1298
*/
public function testSelectForeignKeyPKWithoutFields ()
{
$this -> assertSqlGeneration (
" SELECT t, s, l FROM Doctrine \T ests \ Models \ DDC117 \ DDC117Link l INNER JOIN l.target t INNER JOIN l.source s " ,
" SELECT d0_.article_id AS article_id0, d0_.title AS title1, d1_.article_id AS article_id2, d1_.title AS title3 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 "
);
}
2011-10-29 22:42:44 +04:00
2011-08-08 09:09:25 +04:00
public function testGeneralCaseWithSingleWhenClause ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
" SELECT g.id, CASE WHEN ((g.id / 2) > 18) THEN 1 ELSE 0 END AS test FROM Doctrine \T ests \ Models \ CMS \ CmsGroup g " ,
2011-08-08 09:09:25 +04:00
" SELECT c0_.id AS id0, CASE WHEN (c0_.id / 2 > 18) THEN 1 ELSE 0 END AS sclr1 FROM cms_groups c0_ "
);
}
2011-10-29 22:42:44 +04:00
2011-08-08 09:09:25 +04:00
public function testGeneralCaseWithMultipleWhenClause ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
" 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 \T ests \ Models \ CMS \ CmsGroup g " ,
2011-08-08 09:09:25 +04:00
" SELECT c0_.id AS id0, CASE WHEN (c0_.id / 2 < 10) THEN 2 WHEN (c0_.id / 2 > 20) THEN 1 ELSE 0 END AS sclr1 FROM cms_groups c0_ "
);
}
2011-10-29 22:42:44 +04:00
2011-08-08 09:09:25 +04:00
public function testSimpleCaseWithSingleWhenClause ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
" SELECT g FROM Doctrine \T ests \ Models \ CMS \ CmsGroup g WHERE g.id = CASE g.name WHEN 'admin' THEN 1 ELSE 2 END " ,
2011-08-08 09:09:25 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id = CASE c0_.name WHEN admin THEN 1 ELSE 2 END "
);
}
2011-10-29 22:42:44 +04:00
2011-08-08 09:09:25 +04:00
public function testSimpleCaseWithMultipleWhenClause ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
" SELECT g FROM Doctrine \T ests \ Models \ CMS \ CmsGroup g WHERE g.id = (CASE g.name WHEN 'admin' THEN 1 WHEN 'moderator' THEN 2 ELSE 3 END) " ,
2011-08-08 09:09:25 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id = CASE c0_.name WHEN admin THEN 1 WHEN moderator THEN 2 ELSE 3 END "
);
}
2011-10-29 22:42:44 +04:00
2011-09-22 00:30:45 +04:00
public function testGeneralCaseWithSingleWhenClauseInSubselect ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
" SELECT g FROM Doctrine \T ests \ Models \ CMS \ CmsGroup g WHERE g.id IN (SELECT CASE WHEN ((g2.id / 2) > 18) THEN 2 ELSE 1 END FROM Doctrine \T ests \ Models \ CMS \ CmsGroup g2) " ,
2011-09-22 00:30:45 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE WHEN (c1_.id / 2 > 18) THEN 2 ELSE 1 END AS sclr2 FROM cms_groups c1_) "
);
}
2011-10-29 22:42:44 +04:00
2011-09-22 00:30:45 +04:00
public function testGeneralCaseWithMultipleWhenClauseInSubselect ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
" SELECT g FROM Doctrine \T ests \ 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 \T ests \ Models \ CMS \ CmsGroup g2) " ,
2011-09-22 00:30:45 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1 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 sclr2 FROM cms_groups c1_) "
);
}
2011-10-29 22:42:44 +04:00
2011-09-22 00:30:45 +04:00
public function testSimpleCaseWithSingleWhenClauseInSubselect ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
" SELECT g FROM Doctrine \T ests \ Models \ CMS \ CmsGroup g WHERE g.id IN (SELECT CASE g2.name WHEN 'admin' THEN 1 ELSE 2 END FROM Doctrine \T ests \ Models \ CMS \ CmsGroup g2) " ,
2011-09-22 00:30:45 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE c1_.name WHEN admin THEN 1 ELSE 2 END AS sclr2 FROM cms_groups c1_) "
);
}
2011-10-29 22:42:44 +04:00
2011-09-22 00:30:45 +04:00
public function testSimpleCaseWithMultipleWhenClauseInSubselect ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
" SELECT g FROM Doctrine \T ests \ 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 \T ests \ Models \ CMS \ CmsGroup g2) " ,
2011-09-22 00:30:45 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_groups c0_ WHERE c0_.id IN (SELECT CASE c1_.name WHEN admin THEN 1 WHEN moderator THEN 2 ELSE 3 END AS sclr2 FROM cms_groups c1_) "
);
}
2011-10-29 22:42:44 +04:00
2011-09-08 09:10:48 +04:00
/**
* @ group DDC - 1339
*/
public function testIdentityFunctionInSelectClause ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
" SELECT IDENTITY(u.email) as email_id FROM Doctrine \T ests \ Models \ CMS \ CmsUser u " ,
2011-09-08 09:10:48 +04:00
" SELECT c0_.email_id AS sclr0 FROM cms_users c0_ "
);
}
2011-10-29 22:42:44 +04:00
2011-09-08 09:10:48 +04:00
/**
* @ group DDC - 1339
*/
public function testIdentityFunctionDoesNotAcceptStateField ()
{
$this -> assertInvalidSqlGeneration (
2011-10-29 22:42:44 +04:00
" SELECT IDENTITY(u.name) as name FROM Doctrine \T ests \ Models \ CMS \ CmsUser u " ,
2011-09-08 09:10:48 +04:00
" Doctrine \ ORM \ Query \ QueryException "
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeJoinInRootClassWithDisabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p' ,
2011-11-03 08:44:50 +04:00
'SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c2_.salary AS salary3, c2_.department AS department4, c2_.startDate AS startDate5, c0_.discr AS discr6, c0_.spouse_id AS spouse_id7, c1_.car_id AS car_id8 FROM company_persons c0_ LEFT JOIN company_managers c1_ ON c0_.id = c1_.id LEFT JOIN company_employees c2_ ON c0_.id = c2_.id' ,
2011-10-15 07:18:57 +04:00
array ( Query :: HINT_FORCE_PARTIAL_LOAD => false )
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeJoinInRootClassWithEnabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT p FROM Doctrine\Tests\Models\Company\CompanyPerson p' ,
2011-10-15 07:18:57 +04:00
'SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_' ,
array ( Query :: HINT_FORCE_PARTIAL_LOAD => true )
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeJoinInChildClassWithDisabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e' ,
2011-11-03 08:44:50 +04:00
'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c2_.title AS title5, c0_.discr AS discr6, c0_.spouse_id AS spouse_id7, c2_.car_id AS car_id8 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN company_managers c2_ ON c1_.id = c2_.id' ,
2011-10-15 07:18:57 +04:00
array ( Query :: HINT_FORCE_PARTIAL_LOAD => false )
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeJoinInChildClassWithEnabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e' ,
2011-10-15 07:18:57 +04:00
'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c0_.discr AS discr5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id' ,
array ( Query :: HINT_FORCE_PARTIAL_LOAD => true )
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeJoinInLeafClassWithDisabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m' ,
2011-10-15 07:18:57 +04:00
'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c2_.title AS title5, c0_.discr AS discr6, c0_.spouse_id AS spouse_id7, c2_.car_id AS car_id8 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id' ,
array ( Query :: HINT_FORCE_PARTIAL_LOAD => false )
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeJoinInLeafClassWithEnabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT m FROM Doctrine\Tests\Models\Company\CompanyManager m' ,
2011-10-15 07:18:57 +04:00
'SELECT c0_.id AS id0, c0_.name AS name1, c1_.salary AS salary2, c1_.department AS department3, c1_.startDate AS startDate4, c2_.title AS title5, c0_.discr AS discr6 FROM company_managers c2_ INNER JOIN company_employees c1_ ON c2_.id = c1_.id INNER JOIN company_persons c0_ ON c2_.id = c0_.id' ,
array ( Query :: HINT_FORCE_PARTIAL_LOAD => true )
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeSingleTableInRootClassWithDisabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c' ,
2011-10-15 07:18:57 +04:00
" SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.fixPrice AS fixPrice2, c0_.hoursWorked AS hoursWorked3, c0_.pricePerHour AS pricePerHour4, c0_.maxPrice AS maxPrice5, c0_.discr AS discr6, c0_.salesPerson_id AS salesPerson_id7 FROM company_contracts c0_ WHERE c0_.discr IN ('fix', 'flexible', 'flexultra') " ,
array ( Query :: HINT_FORCE_PARTIAL_LOAD => false )
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeSingleTableInRootClassWithEnabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c' ,
2011-10-15 07:18:57 +04:00
" SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.fixPrice AS fixPrice2, c0_.hoursWorked AS hoursWorked3, c0_.pricePerHour AS pricePerHour4, c0_.maxPrice AS maxPrice5, c0_.discr AS discr6 FROM company_contracts c0_ WHERE c0_.discr IN ('fix', 'flexible', 'flexultra') " ,
array ( Query :: HINT_FORCE_PARTIAL_LOAD => true )
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeSingleTableInChildClassWithDisabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc' ,
2011-10-15 07:18:57 +04:00
" SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5, c0_.salesPerson_id AS salesPerson_id6 FROM company_contracts c0_ WHERE c0_.discr IN ('flexible', 'flexultra') " ,
array ( Query :: HINT_FORCE_PARTIAL_LOAD => false )
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeSingleTableInChildClassWithEnabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT fc FROM Doctrine\Tests\Models\Company\CompanyFlexContract fc' ,
2011-10-15 07:18:57 +04:00
" SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5 FROM company_contracts c0_ WHERE c0_.discr IN ('flexible', 'flexultra') " ,
array ( Query :: HINT_FORCE_PARTIAL_LOAD => true )
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeSingleTableInLeafClassWithDisabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc' ,
2011-10-15 07:18:57 +04:00
" SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5, c0_.salesPerson_id AS salesPerson_id6 FROM company_contracts c0_ WHERE c0_.discr IN ('flexultra') " ,
array ( Query :: HINT_FORCE_PARTIAL_LOAD => false )
);
}
2011-10-29 22:42:44 +04:00
2011-10-15 07:18:57 +04:00
/**
* @ group DDC - 1389
*/
public function testInheritanceTypeSingleTableInLeafClassWithEnabledForcePartialLoad ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT fuc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract fuc' ,
2011-10-15 07:18:57 +04:00
" SELECT c0_.id AS id0, c0_.completed AS completed1, c0_.hoursWorked AS hoursWorked2, c0_.pricePerHour AS pricePerHour3, c0_.maxPrice AS maxPrice4, c0_.discr AS discr5 FROM company_contracts c0_ WHERE c0_.discr IN ('flexultra') " ,
array ( Query :: HINT_FORCE_PARTIAL_LOAD => true )
);
}
2011-10-29 22:42:44 +04:00
2011-10-16 07:42:36 +04:00
/**
* @ group DDC - 1161
*/
public function testSelfReferenceWithOneToOneDoesNotDuplicateAlias ()
{
$this -> assertSqlGeneration (
2011-10-29 22:42:44 +04:00
'SELECT p, pp FROM Doctrine\Tests\Models\Company\CompanyPerson p JOIN p.spouse pp' ,
2011-11-03 08:44:50 +04:00
" SELECT c0_.id AS id0, c0_.name AS name1, c1_.title AS title2, c2_.salary AS salary3, c2_.department AS department4, c2_.startDate AS startDate5, c3_.id AS id6, c3_.name AS name7, c4_.title AS title8, c5_.salary AS salary9, c5_.department AS department10, c5_.startDate AS startDate11, c0_.discr AS discr12, c0_.spouse_id AS spouse_id13, c1_.car_id AS car_id14, c3_.discr AS discr15, c3_.spouse_id AS spouse_id16, c4_.car_id AS car_id17 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 " ,
2011-10-16 07:42:36 +04:00
array ( Query :: HINT_FORCE_PARTIAL_LOAD => false )
);
}
2011-10-22 18:27:56 +04:00
/**
* @ group DDC - 1384
*/
2011-10-29 22:42:44 +04:00
public function testAliasDoesNotExceedPlatformDefinedLength ()
2011-10-22 18:27:56 +04:00
{
$this -> assertSqlGeneration (
'SELECT m FROM ' . __NAMESPACE__ . '\\DDC1384Model m' ,
" SELECT d0_.aVeryLongIdentifierThatShouldBeShortenedByTheSQLWalker_fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo AS fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0 FROM DDC1384Model d0_ "
);
}
2011-10-29 22:42:44 +04:00
/**
* @ group DDC - 331
* @ group DDC - 1384
*/
public function testIssue331 ()
{
$this -> assertSqlGeneration (
'SELECT e.name FROM Doctrine\Tests\Models\Company\CompanyEmployee e' ,
'SELECT c0_.name AS name0 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id'
);
}
2011-10-29 08:00:35 +04:00
/**
* @ group DDC - 1435
*/
public function testForeignKeyAsPrimaryKeySubselect ()
{
$this -> assertSqlGeneration (
" SELECT s FROM Doctrine \T ests \ Models \ DDC117 \ DDC117Article s WHERE EXISTS (SELECT r FROM Doctrine \T ests \ Models \ DDC117 \ DDC117Reference r WHERE r.source = s) " ,
" SELECT d0_.article_id AS article_id0, d0_.title AS title1 FROM DDC117Article d0_ WHERE EXISTS (SELECT d1_.source_id, d1_.target_id FROM DDC117Reference d1_ WHERE d1_.source_id = d0_.article_id) "
);
}
2011-12-02 08:52:35 +04:00
2011-11-15 23:27:17 +04:00
/**
* @ group DDC - 1474
*/
public function testSelectWithArithmeticExpressionBeforeField ()
{
$this -> assertSqlGeneration (
'SELECT - e.value AS value, e.id FROM ' . __NAMESPACE__ . '\DDC1474Entity e' ,
'SELECT -d0_.value AS sclr0, d0_.id AS id1 FROM DDC1474Entity d0_'
);
2011-12-02 08:52:35 +04:00
2011-11-15 23:27:17 +04:00
$this -> assertSqlGeneration (
'SELECT e.id, + e.value AS value FROM ' . __NAMESPACE__ . '\DDC1474Entity e' ,
'SELECT d0_.id AS id0, +d0_.value AS sclr1 FROM DDC1474Entity d0_'
);
}
2011-12-02 08:52:35 +04:00
2011-11-16 02:27:45 +04:00
/**
* @ group DDC - 1430
*/
public function testGroupByAllFieldsWhenObjectHasForeignKeys ()
{
$this -> assertSqlGeneration (
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u' ,
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ GROUP BY c0_.id, c0_.status, c0_.username, c0_.name, c0_.email_id'
);
2011-12-02 08:52:35 +04:00
2011-11-16 02:27:45 +04:00
$this -> assertSqlGeneration (
'SELECT e FROM Doctrine\Tests\Models\CMS\CmsEmployee e GROUP BY e' ,
'SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_employees c0_ GROUP BY c0_.id, c0_.name, c0_.spouse_id'
);
}
2011-11-19 03:35:29 +04:00
2011-12-02 08:52:35 +04:00
/**
* @ group DDC - 1236
*/
public function testGroupBySupportsResultVariable ()
{
$this -> assertSqlGeneration (
'SELECT u, u.status AS st FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY st' ,
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, c0_.status AS status4 FROM cms_users c0_ GROUP BY status4'
);
}
/**
* @ group DDC - 1236
*/
public function testGroupBySupportsIdentificationVariable ()
{
$this -> assertSqlGeneration (
'SELECT u AS user FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY user' ,
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ GROUP BY id0, status1, username2, name3'
);
}
2011-12-18 20:56:57 +04:00
/**
* @ group DDC - 1213
*/
public function testSupportsBitComparison ()
{
$this -> assertSqlGeneration (
'SELECT BIT_OR(4,2), BIT_AND(4,2), u FROM Doctrine\Tests\Models\CMS\CmsUser u' ,
'SELECT (4 | 2) AS sclr0, (4 & 2) AS sclr1, c0_.id AS id2, c0_.status AS status3, c0_.username AS username4, c0_.name AS name5 FROM cms_users c0_'
);
$this -> assertSqlGeneration (
'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' ,
'SELECT (c0_.id | 2) AS sclr0, (c0_.id & 2) AS sclr1 FROM cms_users c0_ WHERE (c0_.id | 2) > 0'
);
$this -> assertSqlGeneration (
'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' ,
'SELECT (c0_.id | 2) AS sclr0, (c0_.id & 2) AS sclr1 FROM cms_users c0_ WHERE (c0_.id & 4) > 0'
);
$this -> assertSqlGeneration (
'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' ,
'SELECT (c0_.id | 2) AS sclr0, (c0_.id & 2) AS sclr1 FROM cms_users c0_ WHERE (c0_.id | 2) > 0 OR (c0_.id & 4) > 0'
);
}
2011-12-20 16:31:00 +04:00
/**
* @ group DDC - 1539
*/
public function testParenthesesOnTheLeftHandOfComparison ()
{
$this -> assertSqlGeneration (
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u where ( (u.id + u.id) * u.id ) > 100' ,
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (c0_.id + c0_.id) * c0_.id > 100'
);
$this -> assertSqlGeneration (
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u where (u.id + u.id) * u.id > 100' ,
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE (c0_.id + c0_.id) * c0_.id > 100'
);
$this -> assertSqlGeneration (
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u where 100 < (u.id + u.id) * u.id ' ,
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE 100 < (c0_.id + c0_.id) * c0_.id'
);
}
2011-11-19 03:35:29 +04:00
public function testCustomTypeValueSql ()
{
if ( DBALType :: hasType ( 'negative_to_positive' )) {
DBALType :: overrideType ( 'negative_to_positive' , 'Doctrine\Tests\DbalTypes\NegativeToPositiveType' );
} else {
DBALType :: addType ( 'negative_to_positive' , 'Doctrine\Tests\DbalTypes\NegativeToPositiveType' );
}
$this -> assertSqlGeneration (
'SELECT p.customInteger FROM Doctrine\Tests\Models\CustomType\CustomTypeParent p WHERE p.id = 1' ,
2011-11-21 18:08:36 +04:00
'SELECT -(c0_.customInteger) AS customInteger0 FROM customtype_parents c0_ WHERE c0_.id = 1'
2011-11-19 03:35:29 +04:00
);
}
public function testCustomTypeValueSqlIgnoresIdentifierColumn ()
{
if ( DBALType :: hasType ( 'negative_to_positive' )) {
DBALType :: overrideType ( 'negative_to_positive' , 'Doctrine\Tests\DbalTypes\NegativeToPositiveType' );
} else {
DBALType :: addType ( 'negative_to_positive' , 'Doctrine\Tests\DbalTypes\NegativeToPositiveType' );
}
$this -> assertSqlGeneration (
'SELECT p.id FROM Doctrine\Tests\Models\CustomType\CustomTypeParent p WHERE p.id = 1' ,
'SELECT c0_.id AS id0 FROM customtype_parents c0_ WHERE c0_.id = 1'
);
}
public function testCustomTypeValueSqlForAllFields ()
{
if ( DBALType :: hasType ( 'negative_to_positive' )) {
DBALType :: overrideType ( 'negative_to_positive' , 'Doctrine\Tests\DbalTypes\NegativeToPositiveType' );
} else {
DBALType :: addType ( 'negative_to_positive' , 'Doctrine\Tests\DbalTypes\NegativeToPositiveType' );
}
$this -> assertSqlGeneration (
'SELECT p FROM Doctrine\Tests\Models\CustomType\CustomTypeParent p' ,
2011-11-21 18:08:36 +04:00
'SELECT c0_.id AS id0, -(c0_.customInteger) AS customInteger1 FROM customtype_parents c0_'
);
}
public function testCustomTypeValueSqlForPartialObject ()
{
if ( DBALType :: hasType ( 'negative_to_positive' )) {
DBALType :: overrideType ( 'negative_to_positive' , 'Doctrine\Tests\DbalTypes\NegativeToPositiveType' );
} else {
DBALType :: addType ( 'negative_to_positive' , 'Doctrine\Tests\DbalTypes\NegativeToPositiveType' );
}
$this -> assertSqlGeneration (
'SELECT partial p.{id, customInteger} FROM Doctrine\Tests\Models\CustomType\CustomTypeParent p' ,
'SELECT c0_.id AS id0, -(c0_.customInteger) AS customInteger1 FROM customtype_parents c0_'
2011-11-19 03:35:29 +04:00
);
}
2009-07-28 15:43:42 +04:00
}
2010-04-15 06:27:33 +04:00
class MyAbsFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode
{
public $simpleArithmeticExpression ;
/**
* @ override
*/
public function getSql ( \Doctrine\ORM\Query\SqlWalker $sqlWalker )
{
2011-08-08 09:09:25 +04:00
return 'ABS(' . $sqlWalker -> walkSimpleArithmeticExpression ( $this -> simpleArithmeticExpression ) . ')' ;
2010-04-15 06:27:33 +04:00
}
/**
* @ override
*/
public function parse ( \Doctrine\ORM\Query\Parser $parser )
{
$lexer = $parser -> getLexer ();
$parser -> match ( \Doctrine\ORM\Query\Lexer :: T_IDENTIFIER );
$parser -> match ( \Doctrine\ORM\Query\Lexer :: T_OPEN_PARENTHESIS );
$this -> simpleArithmeticExpression = $parser -> SimpleArithmeticExpression ();
2011-10-29 22:42:44 +04:00
2010-04-15 06:27:33 +04:00
$parser -> match ( \Doctrine\ORM\Query\Lexer :: T_CLOSE_PARENTHESIS );
}
2010-11-19 01:14:07 +03:00
}
2011-10-22 18:27:56 +04:00
/**
* @ Entity
*/
class DDC1384Model
{
/**
* @ Id
* @ Column ( type = " integer " )
* @ GeneratedValue
*/
protected $aVeryLongIdentifierThatShouldBeShortenedByTheSQLWalker_fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ;
}
2011-11-15 23:27:17 +04:00
/**
* @ Entity
*/
class DDC1474Entity
{
/**
2011-12-02 08:52:35 +04:00
* @ Id
2011-11-15 23:27:17 +04:00
* @ Column ( type = " integer " )
* @ GeneratedValue ()
*/
protected $id ;
/**
2011-12-02 08:52:35 +04:00
* @ column ( type = " float " )
2011-11-15 23:27:17 +04:00
*/
private $value ;
/**
2011-12-02 08:52:35 +04:00
* @ param string $float
2011-11-15 23:27:17 +04:00
*/
public function __construct ( $float )
{
$this -> value = $float ;
}
/**
* @ return integer
*/
public function getId ()
{
return $this -> id ;
}
/**
2011-12-02 08:52:35 +04:00
* @ return float
2011-11-15 23:27:17 +04:00
*/
public function getValue ()
{
return $this -> value ;
}
/**
2011-12-02 08:52:35 +04:00
* @ param float $value
2011-11-15 23:27:17 +04:00
*/
public function setValue ( $value )
{
$this -> value = $value ;
}
}