diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 51d589095..2ba869f22 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1732,7 +1732,8 @@ class Parser $expression = $this->PartialObjectExpression(); $identVariable = $expression->identificationVariable; } else if ($this->_lexer->lookahead['type'] == Lexer::T_INTEGER || - $this->_lexer->lookahead['type'] == Lexer::T_FLOAT) { + $this->_lexer->lookahead['type'] == Lexer::T_FLOAT || + $this->_lexer->lookahead['type'] == Lexer::T_STRING) { // Shortcut: ScalarExpression => SimpleArithmeticExpression $expression = $this->SimpleArithmeticExpression(); } else { diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 84a4f8308..a14987eaa 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -961,7 +961,8 @@ class SqlWalker implements TreeWalker $expr instanceof AST\SimpleArithmeticExpression || $expr instanceof AST\ArithmeticTerm || $expr instanceof AST\ArithmeticFactor || - $expr instanceof AST\ArithmeticPrimary + $expr instanceof AST\ArithmeticPrimary || + $expr instanceof AST\Literal ) { if ( ! $selectExpression->fieldIdentificationVariable) { $resultAlias = $this->_scalarResultCounter++; @@ -970,7 +971,11 @@ class SqlWalker implements TreeWalker } $columnAlias = 'sclr' . $this->_aliasCounter++; - $sql .= $this->walkSimpleArithmeticExpression($expr) . ' AS ' . $columnAlias; + if ($expr instanceof AST\Literal) { + $sql .= $this->walkLiteral($expr) . ' AS ' .$columnAlias; + } else { + $sql .= $this->walkSimpleArithmeticExpression($expr) . ' AS ' . $columnAlias; + } $this->_scalarResultAliasMap[$resultAlias] = $columnAlias; $columnAlias = $this->_platform->getSQLResultCasing($columnAlias); diff --git a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php index fa1da40d5..1ac05df90 100644 --- a/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php +++ b/tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php @@ -260,6 +260,14 @@ class LanguageRecognitionTest extends \Doctrine\Tests\OrmTestCase $this->assertValidDQL('SELECT (SELECT 0 FROM Doctrine\Tests\Models\CMS\CmsUser u2) value FROM Doctrine\Tests\Models\CMS\CmsUser u'); } + /** + * @group DDC-1077 + */ + public function testConstantValueInSelect() + { + $this->assertValidDQL("SELECT u.name, 'foo' AS bar FROM Doctrine\Tests\Models\CMS\CmsUser u", true); + } + public function testDuplicateAliasInSubselectPart() { $this->assertInvalidDQL("SELECT (SELECT SUM(u.id) / COUNT(u.id) AS foo FROM Doctrine\Tests\Models\CMS\CmsUser u2) foo FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = 'jon'"); diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 08fb9edb0..2d0101e03 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -42,7 +42,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase parent::assertEquals($sqlToBeConfirmed, $query->getSql()); $query->free(); } catch (\Exception $e) { - $this->fail($e->getMessage()); + $this->fail($e->getMessage() ."\n".$e->getTraceAsString()); } } @@ -170,6 +170,17 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); }*/ + /** + * @group DDC-1077 + */ + public function testConstantValueInSelect() + { + $this->assertSqlGeneration( + "SELECT u.name, 'foo' AS bar FROM Doctrine\Tests\Models\CMS\CmsUser u", + "SELECT c0_.name AS name0, 'foo' AS sclr1 FROM cms_users c0_" + ); + } + public function testSupportsOrderByWithAscAsDefault() { $this->assertSqlGeneration(