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/07/08 23:18:11 UTC
svn commit: r1500958 - in /db/derby/code/branches/10.9: ./
java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java
Author: kmarsden
Date: Mon Jul 8 21:18:10 2013
New Revision: 1500958
URL: http://svn.apache.org/r1500958
Log:
DERBY-6273 NullPointerException when using more than one parameter in COALESCE
merge revision 1496837 from trunk to 10.9
Modified:
db/derby/code/branches/10.9/ (props changed)
db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java
Propchange: db/derby/code/branches/10.9/
------------------------------------------------------------------------------
Merged /db/derby/code/trunk:r1496837
Modified: db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java?rev=1500958&r1=1500957&r2=1500958&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java (original)
+++ db/derby/code/branches/10.9/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java Mon Jul 8 21:18:10 2013
@@ -178,7 +178,6 @@ public class CoalesceFunctionNode extend
if (((ValueNode) argumentsList.elementAt(index)).requiresTypeFromContext())
{
((ValueNode)argumentsList.elementAt(index)).setType(getTypeServices());
- break;
}
}
return this;
Modified: db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java?rev=1500958&r1=1500957&r2=1500958&view=diff
==============================================================================
--- db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java (original)
+++ db/derby/code/branches/10.9/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java Mon Jul 8 21:18:10 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
{