diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 376e51369..d8e982a75 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -31,6 +31,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; * @author Jonathan Wage * @author Roman Borschel * @author Janne Vanhala + * @author Fabio B. Silva */ class Parser { @@ -1641,12 +1642,12 @@ class Parser $className = $this->_lexer->token['value']; if ( ! class_exists($className, true)) { - $this->semanticalError("Class '$className' is not defined.", $this->_lexer->token); + $this->semanticalError("Class \"$className\" is not defined.", $this->_lexer->token); } $class = new \ReflectionClass($className); if($class->getConstructor() === null) { - $this->semanticalError("Class '$className' has not a valid contructor.", $this->_lexer->token); + $this->semanticalError("Class \"$className\" has not a valid contructor.", $this->_lexer->token); } $this->match(Lexer::T_OPEN_PARENTHESIS); @@ -1661,7 +1662,7 @@ class Parser $this->match(Lexer::T_CLOSE_PARENTHESIS); if($class->getConstructor()->getNumberOfRequiredParameters() > sizeof($args)) { - $this->semanticalError("Number of arguments does not match definition.", $this->_lexer->token); + $this->semanticalError("Number of arguments does not match.", $this->_lexer->token); } return new AST\NewObjectExpression($className, $args);; @@ -1680,9 +1681,6 @@ class Parser return new AST\SimpleSelectExpression($expression); - case ($this->_lexer->lookahead['type'] === Lexer::T_NEW): - return $this->NewObjectExpression(); - default: if ( ! ($this->_isFunction() || $this->_isAggregateFunction($this->_lexer->lookahead))) { $this->syntaxError(); diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 9c8f870e6..71b88ec5d 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -34,6 +34,7 @@ use Doctrine\DBAL\LockMode, * @author Roman Borschel * @author Benjamin Eberlei * @author Alexander + * @author Fabio B. Silva * @since 2.0 * @todo Rename: SQLWalker */ @@ -1410,7 +1411,7 @@ class SqlWalker implements TreeWalker foreach ($newObjectExpression->args as $argIndex => $e) { $resultAlias = $this->scalarResultCounter++; - $columnAlias = $this->getSQLColumnAlias('sclr') . $resultAlias; + $columnAlias = $this->getSQLColumnAlias('sclr'); switch (true) { case $e instanceof AST\NewObjectExpression: @@ -1418,13 +1419,13 @@ class SqlWalker implements TreeWalker break; default: - $sqlSelectExpressions[] = $e->dispatch($this) . ' AS ' . $columnAlias; + $sqlSelectExpressions[] = trim($e->dispatch($this)) . ' AS ' . $columnAlias; break; } $this->scalarResultAliasMap[$resultAlias] = $columnAlias; - $this->rsm->addScalarResult($columnAlias, $resultAlias, 'string'); + $this->rsm->addScalarResult($columnAlias, $resultAlias); $this->rsm->newObjectMappings[$columnAlias] = array( 'className' => $newObjectExpression->className, @@ -1433,7 +1434,7 @@ class SqlWalker implements TreeWalker ); } - return implode(',', $sqlSelectExpressions); + return implode(', ', $sqlSelectExpressions); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php index d1a4f3ad8..7f56bc6c5 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NewOperatorTest.php @@ -2,12 +2,8 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\Common\Collections\ArrayCollection; - -use Doctrine\DBAL\Connection; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsEmail; -use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsPhonenumber; @@ -133,40 +129,6 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals($this->fixtures[2]->address->city, $result[2]->address); } - public function testShouldSupportNestedOperators() - { - $this->markTestIncomplete(); - $dql = " - SELECT - new Doctrine\Tests\Models\CMS\CmsUserDTO( - u.name, - e.email, - new Doctrine\Tests\Models\CMS\CmsAddressDTO( - a.country, - a.city, - a.zip - ) - ) - FROM - Doctrine\Tests\Models\CMS\CmsUser u - JOIN - u.email e - JOIN - u.address a - ORDER BY - u.name"; - - $query = $this->_em->createQuery($dql); - $result = $query->getResult(); - - $this->assertCount(3, $result); - - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[0]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[1]); - $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUserDTO', $result[2]); - - } - public function testShouldSupportAggregateFunctions() { $dql = " diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index b9ec036ee..fdedb921a 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1562,7 +1562,17 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase { $this->assertSqlGeneration( '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', - 'SELECT c0_.name AS sclr01, c1_.email AS sclr12, c2_.city AS sclr23 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' + 'SELECT c0_.name AS sclr0, c1_.email AS sclr1, c2_.city AS sclr2 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' + ); + + $this->assertSqlGeneration( + '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', + 'SELECT c0_.name AS sclr0, c1_.email AS sclr1, c2_.city AS sclr2, COUNT(c3_.phonenumber) AS sclr3 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' + ); + + $this->assertSqlGeneration( + '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', + 'SELECT c0_.name AS sclr0, c1_.email AS sclr1, c2_.city AS sclr2, COUNT(c3_.phonenumber) + c0_.id AS sclr3 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' ); }