db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1592465 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Mon, 05 May 2014 08:10:51 GMT
Author: kahatlen
Date: Mon May  5 08:10:50 2014
New Revision: 1592465

URL: http://svn.apache.org/r1592465
Log:
DERBY-6423: The expression syntax in CASE's THEN clause doesn't accept boolean value expression

Allow boolean value expressions in CASE and NULLIF expressions.

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/CaseExpressionTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.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=1592465&r1=1592464&r2=1592465&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 Mon May
 5 08:10:50 2014
@@ -12567,7 +12567,8 @@ valueSpecification() throws StandardExce
 		return value;
 	}
 |
-	<NULLIF> <LEFT_PAREN> leftExpression = additiveExpression(null, 0) <COMMA>
rightExpression = additiveExpression(null, 0) <RIGHT_PAREN>
+    <NULLIF> <LEFT_PAREN> leftExpression = valueExpression()
+        <COMMA> rightExpression = valueExpression() <RIGHT_PAREN>
 	{
 		// "NULLIF(L, R)" is the same as "L=R ? untyped NULL : L"
 		// An impl assumption here is that Derby can promote CHAR to any comparable datatypes such
as numeric
@@ -12671,7 +12672,7 @@ thenElseExpression() throws StandardExce
 		return value;
 	}
 |
-	expr = additiveExpression(null, 0)
+    expr = valueExpression()
 	{
 		return expr;
 	}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java?rev=1592465&r1=1592464&r2=1592465&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
Mon May  5 08:10:50 2014
@@ -228,6 +228,40 @@ public class CaseExpressionTest extends 
     }
 
     /**
+     * Before DERBY-6423, boolean expressions (such as A OR B, or A AND B)
+     * were not accepted in THEN and ELSE clauses.
+     */
+    public void testBooleanExpressions() throws SQLException {
+        Statement s = createStatement();
+
+        // Test both with and without parentheses around the expressions.
+        // Those with parentheses used to work, and those without used to
+        // cause syntax errors. Now both should work.
+        JDBC.assertFullResultSet(
+            s.executeQuery(
+                "select case when a or b then b or c else a or c end,\n" +
+                "   case when a and b then b and c else a and c end,\n" +
+                "   case when (a or b) then (b or c) else (a or c) end,\n" +
+                "   case when (a and b) then (b and c) else (a and c) end\n" +
+                "from (values (true, true, true), (true, true, false),\n" +
+                "             (true, false, true), (true, false, false),\n" +
+                "             (false, true, true), (false, true, false),\n" +
+                "             (false, false, true), (false, false, false)\n" +
+                "      ) v(a, b, c)\n" +
+                "order by a desc, b desc, c desc"),
+            new String[][] {
+                { "true", "true", "true", "true" },
+                { "true", "false", "true", "false" },
+                { "true", "true", "true", "true" },
+                { "false", "false", "false", "false" },
+                { "true", "false", "true", "false" },
+                { "true", "false", "true", "false" },
+                { "true", "false", "true", "false" },
+                { "false", "false", "false", "false" },
+            });
+    }
+
+    /**
      * Runs the test fixtures in embedded.
      *
      * @return test suite

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java?rev=1592465&r1=1592464&r2=1592465&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java
Mon May  5 08:10:50 2014
@@ -34,6 +34,7 @@ import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
 import org.apache.derbyTesting.junit.SQLUtilities;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
@@ -274,6 +275,36 @@ public class NullIfTest extends BaseJDBC
     }
 
     /**
+     * Before DERBY-6423, boolean expressions (such as A OR B, or A AND B)
+     * were not accepted as arguments to NULLIF.
+     */
+    public void testBooleanExpressions() throws SQLException {
+        Statement s = createStatement();
+
+        // The following statements used to fail with syntax error.
+        JDBC.assertSingleValueResultSet(
+            s.executeQuery("values nullif(true or false, true or false)"),
+            null);
+        JDBC.assertSingleValueResultSet(
+            s.executeQuery("values nullif(true and false, true and false)"),
+            null);
+        JDBC.assertSingleValueResultSet(
+            s.executeQuery("values nullif(true and false, true or false)"),
+            "false");
+
+        // These, on the other hand, used to work. Verify that they still do.
+        JDBC.assertSingleValueResultSet(
+            s.executeQuery("values nullif((true or false), (true or false))"),
+            null);
+        JDBC.assertSingleValueResultSet(
+            s.executeQuery("values nullif((true and false), (true and false))"),
+            null);
+        JDBC.assertSingleValueResultSet(
+            s.executeQuery("values nullif((true and false), (true or false))"),
+            "false");
+    }
+
+    /**
      * Runs the test fixtures in embedded and client.
      * 
      * @return test suite



Mime
View raw message