db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r634316 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/SelectNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/NestedWhereSubqueryTest.java
Date Thu, 06 Mar 2008 15:52:20 GMT
Author: dyre
Date: Thu Mar  6 07:52:18 2008
New Revision: 634316

URL: http://svn.apache.org/viewvc?rev=634316&view=rev
Log:
DERBY-3321: NullPointerException for 'NOT EXISTS' with nested subquery
Checks fromList for a FromSubquery using a CollectNodesVistior.
The value of bindTargetListOnly is based on the contents of the visitor. 
Patch contributed by Thomas Nielsen
Patch file: d3321.diff

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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java?rev=634316&r1=634315&r2=634316&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java Thu
Mar  6 07:52:18 2008
@@ -591,7 +591,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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedWhereSubqueryTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedWhereSubqueryTest.java?rev=634316&r1=634315&r2=634316&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedWhereSubqueryTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/NestedWhereSubqueryTest.java
Thu Mar  6 07:52:18 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();
 	}



Mime
View raw message