You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by mi...@apache.org on 2014/10/09 17:47:10 UTC
svn commit: r1630516 - in /db/derby/code/branches/10.10: ./
java/engine/org/apache/derby/impl/sql/compile/
java/testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: mikem
Date: Thu Oct 9 15:47:09 2014
New Revision: 1630516
URL: http://svn.apache.org/r1630516
Log:
DERBY-6423: The expression syntax in CASE's THEN clause doesn't accept boolean value expression
backported change #r1592465 from trunk to 10.10 branch.
Allow boolean value expressions in CASE and NULLIF expressions.
Modified:
db/derby/code/branches/10.10/ (props changed)
db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java
Propchange: db/derby/code/branches/10.10/
------------------------------------------------------------------------------
Merged /db/derby/code/trunk:r1592465
Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=1630516&r1=1630515&r2=1630516&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Thu Oct 9 15:47:09 2014
@@ -12606,7 +12606,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
@@ -12721,7 +12722,7 @@ thenElseExpression() throws StandardExce
return value;
}
|
- expr = additiveExpression(null, 0)
+ expr = valueExpression()
{
return expr;
}
Modified: db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java?rev=1630516&r1=1630515&r2=1630516&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java Thu Oct 9 15:47:09 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/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java?rev=1630516&r1=1630515&r2=1630516&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NullIfTest.java Thu Oct 9 15:47:09 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