From 0c1a8cd43f48692a1d0a898b7afd002eed95d061 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Tue, 3 Jan 2012 10:31:54 -0200 Subject: [PATCH] sql generation --- lib/Doctrine/ORM/Query/Parser.php | 7 +++---- lib/Doctrine/ORM/Query/SqlWalker.php | 6 ++++++ tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php | 1 - 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 14d6c34f0..657280284 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1642,19 +1642,18 @@ class Parser $this->match(Lexer::T_OPEN_PARENTHESIS); - $fieldSet[] = $this->SimpleSelectExpression(); + $fieldSet[] = $this->SelectExpression(); while ($this->_lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); - $fieldSet[] = $this->SimpleSelectExpression(); + $fieldSet[] = $this->SelectExpression(); } $this->match(Lexer::T_CLOSE_PARENTHESIS); $expression = new AST\NewObjectExpression($identificationVariable, $fieldSet); - // @TODO : Defer NewObjectExpression validation - throw new \BadMethodCallException("Not complete yet !"); + // @TODO : Defer NewObjectExpression validation ? return $expression; } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 13c2b5df0..2bad829f9 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -1221,6 +1221,12 @@ class SqlWalker implements TreeWalker } break; + case ($expr instanceof AST\NewObjectExpression): + $sqlSelectExpressions = array_filter(array_map(array($this, 'walkSelectExpression'), $expr->fieldSet)); + $sql .= implode(', ', $sqlSelectExpressions); + + break; + default: // IdentificationVariable or PartialObjectExpression if ($expr instanceof AST\PartialObjectExpression) { diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 232a86ea7..074fdbd5f 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1560,7 +1560,6 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase */ public function testSupportsNewOperator() { - $this->markTestIncomplete('not complete yet !'); $this->assertSqlGeneration( 'SELECT new Doctrine\Tests\Models\CMS\CmsUser(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 name0, c1_.email AS email1, c2_.city AS city2 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'