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 028B7C4D0 for ; Wed, 26 Jun 2013 08:57:12 +0000 (UTC) Received: (qmail 4150 invoked by uid 500); 26 Jun 2013 08:57:12 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 4092 invoked by uid 500); 26 Jun 2013 08:57:08 -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 4084 invoked by uid 99); 26 Jun 2013 08:57:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Jun 2013 08:57:07 +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; Wed, 26 Jun 2013 08:57:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6939123888FE; Wed, 26 Jun 2013 08:56:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1496837 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java Date: Wed, 26 Jun 2013 08:56:47 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130626085647.6939123888FE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Wed Jun 26 08:56:46 2013 New Revision: 1496837 URL: http://svn.apache.org/r1496837 Log: DERBY-6273: NullPointerException when using more than one parameter in COALESCE Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java?rev=1496837&r1=1496836&r2=1496837&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java Wed Jun 26 08:56:46 2013 @@ -179,7 +179,6 @@ class CoalesceFunctionNode extends Value if (((ValueNode) argumentsList.elementAt(index)).requiresTypeFromContext()) { ((ValueNode)argumentsList.elementAt(index)).setType(getTypeServices()); - break; } } return this; Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java?rev=1496837&r1=1496836&r2=1496837&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java Wed Jun 26 08:56:46 2013 @@ -1067,6 +1067,48 @@ public class CoalesceTest extends BaseJD "where coalesce(a2, 0) <> 1")); } + /** + * If more than one of the arguments passed to COALESCE are untyped + * parameter markers, compilation used to fail with a NullPointerException. + * Fixed in DERBY-6273. + */ + public void testMultipleUntypedParameters() throws SQLException { + // All parameters cannot be untyped. This should still fail. + assertCompileError("42610", "values coalesce(?,?,?)"); + + // But as long as we know the type of one parameter, it should be + // possible to have multiple parameters whose types are determined + // from the context. These queries used to raise NullPointerException + // before DERBY-6273. + vetThreeArgCoalesce("values coalesce(cast(? as char(1)), ?, ?)"); + vetThreeArgCoalesce("values coalesce(?, cast(? as char(1)), ?)"); + vetThreeArgCoalesce("values coalesce(?, ?, cast(? as char(1)))"); + } + + private void vetThreeArgCoalesce(String sql) throws SQLException { + // First three values in each row are arguments to COALESCE. The + // last value is the expected return value. + String[][] data = { + {"a", "b", "c", "a"}, + {null, "b", "c", "b"}, + {"a", null, "c", "a"}, + {"a", "b", null, "a"}, + {null, null, "c", "c"}, + {"a", null, null, "a"}, + {null, "b", null, "b"}, + {null, null, null, null}, + }; + + PreparedStatement ps = prepareStatement(sql); + + for (int i = 0; i < data.length; i++) { + ps.setString(1, data[i][0]); + ps.setString(2, data[i][1]); + ps.setString(3, data[i][2]); + JDBC.assertSingleValueResultSet(ps.executeQuery(), data[i][3]); + } + } + /**************supporting methods *******************/ private void dumpRS(ResultSet rs, String expectedValue) throws SQLException {