db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1501013 - in /db/derby/code/branches/10.8: ./ java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java
Date Mon, 08 Jul 2013 23:27:18 GMT
Author: kmarsden
Date: Mon Jul  8 23:27:18 2013
New Revision: 1501013

URL: http://svn.apache.org/r1501013
Log:
DERBY-6273 NullPointerException when using more than one parameter in COALESCE 

merge revision 1496837 from trunk to 10.8


Modified:
    db/derby/code/branches/10.8/   (props changed)
    db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
    db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java

Propchange: db/derby/code/branches/10.8/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1496837

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java?rev=1501013&r1=1501012&r2=1501013&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
(original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
Mon Jul  8 23:27:18 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.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java?rev=1501013&r1=1501012&r2=1501013&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java
(original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CoalesceTest.java
Mon Jul  8 23:27:18 2013
@@ -1204,6 +1204,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
     {



Mime
View raw message