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 km...@apache.org on 2013/08/01 20:32:41 UTC
svn commit: r1509375 - in /db/derby/code/branches/10.8: ./
java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
Author: kmarsden
Date: Thu Aug 1 18:32:41 2013
New Revision: 1509375
URL: http://svn.apache.org/r1509375
Log:
DERBY-5972 - Grammar doesn't accept OR operator without parentheses
backport 1408136 from trunk to 10.8
Contributed by Knut Anders Hatlen
Modified:
db/derby/code/branches/10.8/ (props changed)
db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
Propchange: db/derby/code/branches/10.8/
------------------------------------------------------------------------------
Merged /db/derby/code/trunk:r1408136
Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=1509375&r1=1509374&r2=1509375&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Thu Aug 1 18:32:41 2013
@@ -5253,7 +5253,7 @@ derivedColumn(ResultColumnList resultCol
String columnName = null;
}
{
- columnExpression = orExpression( null )
+ columnExpression = valueExpression()
[ columnName = asClause() ]
{
/*
@@ -6009,7 +6009,7 @@ methodParameter(Vector parameterList) th
ValueNode parameter;
}
{
- parameter = orExpression(null)
+ parameter = valueExpression()
{
parameterList.addElement(parameter);
}
@@ -8372,7 +8372,7 @@ updateSource(String columnName) throws S
ValueNode valueNode;
}
{
- valueNode = orExpression(null)
+ valueNode = valueExpression()
{
return valueNode;
}
@@ -8623,7 +8623,7 @@ rowValueConstructorElement(ResultColumnL
ValueNode value;
}
{
- value = orExpression(null)
+ value = valueExpression()
{
resultColumns.addResultColumn(
(ResultColumn) nodeFactory.getNode(
@@ -12491,8 +12491,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/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java?rev=1509375&r1=1509374&r2=1509375&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java (original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java Thu Aug 1 18:32:41 2013
@@ -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";
///////////////////////////////////////////////////////////////////////////////////
//
@@ -1917,6 +1918,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");
+ }
///////////////////////////////////////////////////////////////////////////////////
//