Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1474

Selecting expressions involving the unary minus operator will not work, whereas the EBNF syntax definitions for DQL say they should

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.2
    • Fix Version/s: 2.1.3
    • Component/s: DQL
    • Security Level: All
    • Labels:
      None

      Description

      DQL queries like:

      SELECT - someEntity.someNumericField FROM \SomeEntity someEntity
      

      will result in a syntax error:

      [Syntax Error] line 0, col 7: Error: Expected IdentificationVariable | StateFieldPathExpression | AggregateExpression | "(" Subselect ")" | ScalarExpression, got '-''
      

      I think this should work, because the relevant EBNF definitions state the following:

      SimpleSelectExpression  ::= ScalarExpression | IdentificationVariable |
                                  (AggregateExpression [["AS"] AliasResultVariable])
      ScalarExpression       ::= SimpleArithmeticExpression | StringPrimary | DateTimePrimary | StateFieldPathExpression
                                 BooleanPrimary | EntityTypeExpression | CaseExpression
      SimpleArithmeticExpression ::= ArithmeticTerm {("+" | "-") ArithmeticTerm}*
      ArithmeticTerm             ::= ArithmeticFactor {("*" | "/") ArithmeticFactor}*
      ArithmeticFactor           ::= [("+" | "-")] ArithmeticPrimary
      ArithmeticPrimary          ::= SingleValuedPathExpression | Literal | "(" SimpleArithmeticExpression ")"
                                     | FunctionsReturningNumerics | AggregateExpression | FunctionsReturningStrings
                                     | FunctionsReturningDatetime | IdentificationVariable | InputParameter | CaseExpression
      SingleValuedPathExpression                ::= StateFieldPathExpression | SingleValuedAssociationPathExpression
      StateFieldPathExpression                  ::= IdentificationVariable "." StateField | SingleValuedAssociationPathExpression "." StateField
      

      Therefore, the expression "- someEntity.someField" is a legitimate arithmetic factor, which ultimately should be a legitimate scalar expression too, which is a legitimate simple select expression.

      Fortunately, this is easy to work around, by simply subtracting from zero, like in:

      SELECT 0 - someEntity.someNumericField FROM \SomeEntity someEntity
      

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Fixed.

        Show
        Benjamin Eberlei added a comment - Fixed.

          People

          • Assignee:
            Fabio B. Silva
            Reporter:
            Daniel Alvarez Arribas
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: