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 2008/04/25 23:09:50 UTC

svn commit: r651700 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/impl/sql/compile/SelectNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/NestedWhereSubqueryTest.java

Author: kmarsden
Date: Fri Apr 25 14:09:47 2008
New Revision: 651700

URL: http://svn.apache.org/viewvc?rev=651700&view=rev
Log:
DERBY-3321 NullPointerException for 'NOT EXISTS' with nested subquery

port from trunk revision 614316
Contributed by Thomas Nielsen (thomas dot nielsen at sun dot com)


Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedWhereSubqueryTest.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java?rev=651700&r1=651699&r2=651700&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java Fri Apr 25 14:09:47 2008
@@ -593,7 +593,18 @@
 	public void bindTargetExpressions(FromList fromListParam)
 					throws StandardException
 	{
-		bindTargetListOnly = true;
+		/*
+		 * With a FromSubquery in the FromList we cannot bind target expressions 
+		 * at this level (DERBY-3321)
+		 */
+		CollectNodesVisitor cnv = new CollectNodesVisitor(FromSubquery.class, 
+														  FromSubquery.class);
+		fromList.accept(cnv);
+		if (!cnv.getList().isEmpty()){		
+			bindTargetListOnly = false;
+		} else {
+			bindTargetListOnly = true;				
+		}		
 		bindExpressions(fromListParam);
 		bindTargetListOnly = false;
 	}

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedWhereSubqueryTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedWhereSubqueryTest.java?rev=651700&r1=651699&r2=651700&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedWhereSubqueryTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedWhereSubqueryTest.java Fri Apr 25 14:09:47 2008
@@ -356,12 +356,42 @@
 		JDBC.assertUnorderedResultSet(rs, expectedRows);
 		
 		/*
+		 * DERBY-3321 revealed an NPE with a subquery in the [NOT] EXIST subuery FromList.
+		 */
+		s.executeUpdate("create table a (aa int, bb int)");
+		s.executeUpdate("create table b (bb int)");
+		s.executeUpdate("insert into a values (1,1),(1,2),(2,2)");
+		s.executeUpdate("insert into b values (1)");
+		
+		/* NOT EXISTS */
+		sb = new StringBuffer();
+		sb.append("select * from a ");
+		sb.append("where not exists ");
+		sb.append("(select bb from (select bb from b) p where a.bb=p.bb)");
+		rs = s.executeQuery(sb.toString());
+		expectedRows = new String [][] {{"1","2"},		
+										{"2","2"}};
+		JDBC.assertUnorderedResultSet(rs, expectedRows);		
+		
+		/* EXISTS */
+		sb = new StringBuffer();
+		sb.append("select * from a ");
+		sb.append("where exists ");
+		sb.append("(select bb from (select bb from b) p where a.bb=p.bb)");
+		rs = s.executeQuery(sb.toString());
+		expectedRows = new String [][] {{"1","1"}};										
+		JDBC.assertUnorderedResultSet(rs, expectedRows);	
+		
+		/*
 		 * Clean up the tables used.
 		 */				
 		s.executeUpdate("drop table project_employees");	
 		s.executeUpdate("drop table projects");
 		s.executeUpdate("drop table employees");
 		s.executeUpdate("drop table departments");			
+		
+		s.executeUpdate("drop table a");	
+		s.executeUpdate("drop table b");	
 		
 		s.close();
 	}