db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1408136 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
Date Sun, 11 Nov 2012 22:47:14 GMT
Author: kahatlen
Date: Sun Nov 11 22:47:13 2012
New Revision: 1408136

URL: http://svn.apache.org/viewvc?rev=1408136&view=rev
Log:
DERBY-5972: Grammar doesn't accept OR operator without parentheses

Update grammar to allow full value expressions where it previously
only allowed conjunctions of boolean primaries.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=1408136&r1=1408135&r2=1408136&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Sun Nov
11 22:47:13 2012
@@ -5334,7 +5334,7 @@ derivedColumn(ResultColumnList resultCol
 	String		columnName = null;
 }
 {
-	columnExpression = orExpression( null )
+	columnExpression = valueExpression()
 			[ columnName = asClause() ]
 	{ 
 		/*
@@ -6090,7 +6090,7 @@ methodParameter(Vector parameterList) th
 	ValueNode	parameter;
 }
 {
-	parameter = orExpression(null)
+	parameter = valueExpression()
 	{
 		parameterList.addElement(parameter);
 	}
@@ -8575,7 +8575,7 @@ updateSource(String columnName) throws S
 	ValueNode	valueNode;
 }
 {
-	valueNode = orExpression(null) 
+	valueNode = valueExpression()
 	{
 		return valueNode;
 	}
@@ -8830,7 +8830,7 @@ rowValueConstructorElement(ResultColumnL
 	ValueNode	value;
 }
 {
-	value = orExpression(null)
+	value = valueExpression()
 	{
 		resultColumns.addResultColumn(
 			(ResultColumn) nodeFactory.getNode(
@@ -12738,8 +12738,7 @@ whenThenExpression() throws StandardExce
 	ValueNode	   elseExpr;
 }
 {
-	<WHEN> expr = orExpression(null) 
-		   (<OR> expr = orExpression(expr) )*
+	<WHEN> expr = valueExpression()
 	<THEN> thenExpr = thenElseExpression()
 	elseExpr = caseExpression()
 	{

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java?rev=1408136&r1=1408135&r2=1408136&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
Sun Nov 11 22:47:13 2012
@@ -59,6 +59,7 @@ public class BooleanValuesTest  extends 
     private static final String ILLEGAL_INSERT = "42821";
     private static final String BAD_DEFAULT = "42894";
     private static final String ILLEGAL_UPDATE = "XCL12";
+    private static final String NON_BOOLEAN_OPERAND = "42Y94";
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -2077,6 +2078,66 @@ public class BooleanValuesTest  extends 
              false
              );
     }
+
+    /**
+     * Verify that you can use AND and OR expressions as BOOLEAN values.
+     * Regression test case for DERBY-5972.
+     */
+    public void test_5972() throws SQLException {
+        // Disable auto-commit so that tearDown() can roll back any changes.
+        setAutoCommit(false);
+
+        Statement s = createStatement();
+
+        // Test boolean expressions in select list. Used to fail with syntax
+        // errors with OR expressions.
+        JDBC.assertSingleValueResultSet(
+                s.executeQuery("select true and false from sysibm.sysdummy1"),
+                "false");
+        JDBC.assertSingleValueResultSet(
+                s.executeQuery("select true or false from sysibm.sysdummy1"),
+                "true");
+        assertCompileError(NON_BOOLEAN_OPERAND,
+                "select 1 and 2 from sysibm.sysdummy1");
+        assertCompileError(NON_BOOLEAN_OPERAND,
+                "select 1 or 2 from sysibm.sysdummy1");
+
+        // Test boolean expressions in VALUES statements. Used to fail with
+        // syntax errors with OR expressions.
+        JDBC.assertSingleValueResultSet(
+                s.executeQuery("values true and false"), "false");
+        JDBC.assertSingleValueResultSet(
+                s.executeQuery("values true or false"), "true");
+        assertCompileError(NON_BOOLEAN_OPERAND, "values 1 and 2");
+        assertCompileError(NON_BOOLEAN_OPERAND, "values 1 or 2");
+
+        // Test boolean expressions as parameters in function calls. Used to
+        // result in syntax errors with OR expressions.
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+                "values booleanValue(true and false)"), "False value");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+                "values booleanValue(true or false)"), "True value");
+        assertCompileError(NON_BOOLEAN_OPERAND, "values booleanValue(1 and 2)");
+        assertCompileError(NON_BOOLEAN_OPERAND, "values booleanValue(1 or 2)");
+
+        // Test boolean expressions in UPDATE statements. Used to fail with
+        // syntax errors with OR expressions.
+        s.execute("create table d5972(b boolean)");
+        assertUpdateCount(s, 0, "update d5972 set b = true and false");
+        assertUpdateCount(s, 0, "update d5972 set b = true or false");
+        assertCompileError(NON_BOOLEAN_OPERAND, "update d5972 set b = 1 and 2");
+        assertCompileError(NON_BOOLEAN_OPERAND, "update d5972 set b = 1 or 2");
+
+        // Used to work correctly. Verify for completeness.
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+                "values case when true and false then 1 else 0 end"), "0");
+        JDBC.assertSingleValueResultSet(s.executeQuery(
+                "values case when true or false then 1 else 0 end"), "1");
+        assertCompileError(NON_BOOLEAN_OPERAND,
+                "values case when 1 and 2 then 1 else 0 end");
+        assertCompileError(NON_BOOLEAN_OPERAND,
+                "values case when 1 or 2 then 1 else 0 end");
+    }
     
     ///////////////////////////////////////////////////////////////////////////////////
     //



Mime
View raw message