db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (DERBY-5972) Grammar doesn't accept OR operator without parentheses
Date Mon, 05 Nov 2012 17:24:12 GMT

     [ https://issues.apache.org/jira/browse/DERBY-5972?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Knut Anders Hatlen updated DERBY-5972:
--------------------------------------

    Attachment: d5972-1a.diff

The attached patch changes occurrences of orExpression(null) with valueExpression() in sqlgrammar.jj.
Since the orExpression() rule only matches conjunctions of boolean primaries and valueExpression()
matches disjunctions of orExpression(), this change makes it possible to both OR and AND expressions
where only AND expressions could be used previously.

The patch changes the following production rules:

derivedColumn(): This rule is used in select lists. The change allows statements like "SELECT
b1 OR b2 FROM t".

methodParameter(): Used for parameters in function/procedure calls. Makes statements like
"VALUES booleanFunction(TRUE OR FALSE)" work.

updateSource(): Used in UPDATE statements and allows statements like: "UPDATE t SET b = TRUE
OR FALSE"

rowValueConstructorElement(): Used in VALUES statements and allows statements like: VALUES
TRUE OR FALSE

whenThenExpression(): This production rule actually worked before, because it had inlined
valueExpression(). The patch changes it to call valueExpression() instead of duplicating the
code. Added a test case for CASE WHEN ... THEN ... ELSE to verify that it still works.

With these changes, only the valueExpression() rule uses the orExpression() rule directly.
The patch also adds test cases for all the expressions mentioned above.

I have only run BooleanValuesTest so far. Will run the full regression test suite.
                
> Grammar doesn't accept OR operator without parentheses
> ------------------------------------------------------
>
>                 Key: DERBY-5972
>                 URL: https://issues.apache.org/jira/browse/DERBY-5972
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.10.0.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>         Attachments: d5972-1a.diff
>
>
> The grammar doesn't accept the OR operator without parentheses in some constructs.
> For example, in a select list:
> ij> create table t(b1 boolean, b2 boolean);
> 0 rows inserted/updated/deleted
> ij> select b1 or b2 from t;
> ERROR 42X01: Syntax error: Encountered "or" at line 1, column 11. (errorCode = 30000)
> Issue the 'help' command for general information on IJ command syntax.
> Any unrecognized commands are treated as potential SQL commands and executed directly.
> Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
> However, it does not fail if OR is replaced by AND, or if parentheses are used around
the OR expression:
> ij> select (b1 or b2) from t;
> 1    
> -----
> 0 rows selected
> ij> select b1 and b2 from t;
> 1    
> -----
> 0 rows selected
> Similar behaviour is seen in VALUES statements:
> ij> values true or false;
> ERROR 42X01: Syntax error: Encountered "or" at line 1, column 13. (errorCode = 30000)
> Issue the 'help' command for general information on IJ command syntax.
> Any unrecognized commands are treated as potential SQL commands and executed directly.
> Consult your DBMS server reference documentation for details of the SQL syntax supported
by your server.
> ij> values (true or false);
> 1    
> -----
> true 
> 1 row selected
> ij> values true and false;
> 1    
> -----
> false
> 1 row selected

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message