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 ka...@apache.org on 2013/06/26 10:56:47 UTC
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
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
{