1
0
mirror of synced 2025-01-18 22:41:43 +03:00

[DDC-581] Implemented support to SingleValuedPathExpression to InExpression.

This commit is contained in:
Guilherme Blanco 2010-08-12 00:16:07 -03:00
parent c3064336ab
commit 496a34a4d2
3 changed files with 70 additions and 2 deletions

View File

@ -2421,13 +2421,13 @@ class Parser
}
/**
* InExpression ::= StateFieldPathExpression ["NOT"] "IN" "(" (InParameter {"," InParameter}* | Subselect) ")"
* InExpression ::= SingleValuedPathExpression ["NOT"] "IN" "(" (InParameter {"," InParameter}* | Subselect) ")"
*
* @return \Doctrine\ORM\Query\AST\InExpression
*/
public function InExpression()
{
$inExpression = new AST\InExpression($this->StateFieldPathExpression());
$inExpression = new AST\InExpression($this->SingleValuedPathExpression());
if ($this->_lexer->isNextToken(Lexer::T_NOT)) {
$this->match(Lexer::T_NOT);

View File

@ -135,6 +135,16 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase
$this->assertValidDql('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT IN (1)');
}
public function testInExpressionWithSingleValuedAssociationPathExpression()
{
$this->assertValidDql("SELECT u FROM Doctrine\Tests\Models\Forum\ForumUser u WHERE u.avatar IN (?1, ?2)");
}
public function testInvalidInExpressionWithCollectionValuedAssociationPathExpression()
{
$this->assertInvalidDql("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.phonenumbers IN (?1, ?2)");
}
public function testInstanceOfExpressionSupportedInWherePart()
{
$this->assertValidDql('SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee');

View File

@ -15,6 +15,14 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
$this->_em = $this->_getTestEntityManager();
}
/**
* Assert a valid SQL generation.
*
* @param string $dqlToBeTested
* @param string $sqlToBeConfirmed
* @param array $queryHints
* @param array $queryParams
*/
public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $queryHints = array(), array $queryParams = array())
{
try {
@ -38,6 +46,39 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
}
}
/**
* Asser an invalid SQL generation.
*
* @param string $dqlToBeTested
* @param string $expectedException
* @param array $queryHints
* @param array $queryParams
*/
public function assertInvalidSqlGeneration($dqlToBeTested, $expectedException, array $queryHints = array(), array $queryParams = array())
{
$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)
->useQueryCache(false);
foreach ($queryHints AS $name => $value) {
$query->setHint($name, $value);
}
$sql = $query->getSql();
$query->free();
// If we reached here, test failed
$this->fail($sql);
}
public function testSupportsSelectForAllFields()
{
$this->assertSqlGeneration(
@ -374,6 +415,23 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
);
}
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\Tests\Models\CMS\CmsUser u WHERE u.address IN (?1, ?2)",
"Doctrine\ORM\Query\QueryException"
);
}
public function testSupportsConcatFunctionForMysqlAndPostgresql()
{
$connMock = $this->_em->getConnection();