diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 2af4bb452..1a34963f2 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -1905,6 +1905,9 @@ class Parser } else if (in_array($this->_lexer->lookahead['type'], array(Lexer::T_OPEN_PARENTHESIS, Lexer::T_INTEGER, Lexer::T_FLOAT, Lexer::T_STRING))) { // Shortcut: ScalarExpression => SimpleArithmeticExpression $expression = $this->SimpleArithmeticExpression(); + } else if (in_array($this->_lexer->lookahead['type'], array(Lexer::T_PLUS, Lexer::T_MINUS))) { + // SimpleArithmeticExpression : (- u.value ) or ( + u.value ) + $expression = $this->SimpleArithmeticExpression(); } else { $this->syntaxError( 'IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression', diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1474Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1474Test.php new file mode 100644 index 000000000..e1256f3c3 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1474Test.php @@ -0,0 +1,122 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1474Entity'), + )); + + $this->loadFixtures(); + } catch (\Exception $exc) { + + } + } + + public function testTicket() + { + $query = $this->_em->createQuery('SELECT - e.value AS value, e.id FROM ' . __NAMESPACE__ . '\DDC1474Entity e'); + $this->assertEquals('SELECT -d0_.value AS sclr0, d0_.id AS id1 FROM DDC1474Entity d0_', $query->getSQL()); + $result = $query->getResult(); + + $this->assertEquals(2, sizeof($result)); + + $this->assertEquals(1, $result[0]['id']); + $this->assertEquals(2, $result[1]['id']); + + $this->assertEquals(-10, $result[0]['value']); + $this->assertEquals(20, $result[1]['value']); + + + + + + $query = $this->_em->createQuery('SELECT e.id, + e.value AS value FROM ' . __NAMESPACE__ . '\DDC1474Entity e'); + $this->assertEquals('SELECT d0_.id AS id0, +d0_.value AS sclr1 FROM DDC1474Entity d0_', $query->getSQL()); + $result = $query->getResult(); + + $this->assertEquals(2, sizeof($result)); + + $this->assertEquals(1, $result[0]['id']); + $this->assertEquals(2, $result[1]['id']); + + $this->assertEquals(10, $result[0]['value']); + $this->assertEquals(-20, $result[1]['value']); + } + + public function loadFixtures() + { + $e1 = new DDC1474Entity(10); + $e2 = new DDC1474Entity(-20); + + $this->_em->persist($e1); + $this->_em->persist($e2); + + $this->_em->flush(); + } + +} + +/** + * @Entity + */ +class DDC1474Entity +{ + + /** + * @Id + * @Column(type="integer") + * @GeneratedValue() + */ + protected $id; + + /** + * @column(type="float") + */ + private $value; + + /** + * @param string $float + */ + public function __construct($float) + { + $this->value = $float; + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @return float + */ + public function getValue() + { + return $this->value; + } + + /** + * @param float $value + */ + public function setValue($value) + { + $this->value = $value; + } + +}