Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7C4F910C7E for ; Thu, 1 Aug 2013 18:33:07 +0000 (UTC) Received: (qmail 69903 invoked by uid 500); 1 Aug 2013 18:33:07 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 69838 invoked by uid 500); 1 Aug 2013 18:33:04 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 69828 invoked by uid 99); 1 Aug 2013 18:33:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Aug 2013 18:33:03 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Aug 2013 18:33:02 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E481D2388906; Thu, 1 Aug 2013 18:32:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Thu, 01 Aug 2013 18:32:41 -0000 To: derby-commits@db.apache.org From: kmarsden@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130801183241.E481D2388906@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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; } { - expr = orExpression(null) - ( expr = orExpression(expr) )* + expr = valueExpression() 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"); + } /////////////////////////////////////////////////////////////////////////////////// //