db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1087420 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Thu, 31 Mar 2011 19:33:57 GMT
Author: kmarsden
Date: Thu Mar 31 19:33:57 2011
New Revision: 1087420

URL: http://svn.apache.org/viewvc?rev=1087420&view=rev
Log:
DERBY-4488 Nullpointer when performing INSERT INTO

merge from 10.4 r1085551
contributed by Knut Anders Hatlen


Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/CallStatementResultSet.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/DeleteVTIResultSet.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/InsertVTIResultSet.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/MiscResultSet.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/SetTransactionResultSet.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/UpdateVTIResultSet.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/CallStatementResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/CallStatementResultSet.java?rev=1087420&r1=1087419&r2=1087420&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/CallStatementResultSet.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/CallStatementResultSet.java
Thu Mar 31 19:33:57 2011
@@ -58,7 +58,6 @@ class CallStatementResultSet extends NoR
     CallStatementResultSet(
 				GeneratedMethod methodCall,
 				Activation a) 
-			throws StandardException
     {
 		super(a);
 		this.methodCall = methodCall;

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java?rev=1087420&r1=1087419&r2=1087420&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java
Thu Mar 31 19:33:57 2011
@@ -209,9 +209,6 @@ class DeleteResultSet extends DMLWriteRe
 		activation.checkStatementValidity();
 
 		/* Get or re-use the row changer.
-		 * NOTE: We need to set ourself as the top result set
-		 * if this is not the 1st execution.  (Done in constructor
-		 * for 1st execution.)
 		 */
 		if (firstExecute)
 		{
@@ -232,10 +229,7 @@ class DeleteResultSet extends DMLWriteRe
 								constants.getStreamStorableHeapColIds(),
 								activation);
 		}
-		else
-		{
-			lcc.getStatementContext().setTopResultSet(this, subqueryTrackingArray);
-		}
+
 		/* decode the lock mode for the execution isolation level */
 		lockMode = decodeLockMode(constants.lockMode);
 

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/DeleteVTIResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/DeleteVTIResultSet.java?rev=1087420&r1=1087419&r2=1087420&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/DeleteVTIResultSet.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/DeleteVTIResultSet.java
Thu Mar 31 19:33:57 2011
@@ -75,8 +75,6 @@ class DeleteVTIResultSet extends DMLVTIR
 	*/
 	protected void openCore() throws StandardException
 	{
-		lcc.getStatementContext().setTopResultSet(this, subqueryTrackingArray);
-
 		ExecRow row = getNextRowCore(sourceResultSet);
 
 		if (row != null)

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java?rev=1087420&r1=1087419&r2=1087420&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java
Thu Mar 31 19:33:57 2011
@@ -887,9 +887,6 @@ class InsertResultSet extends DMLWriteRe
                 long user_autoinc=0;
                         
 		/* Get or re-use the row changer.
-		 * NOTE: We need to set ourself as the top result set
-		 * if this is not the 1st execution.  (Done in constructor
-		 * for 1st execution.)
 		 */
 		if (firstExecute)
 		{
@@ -910,10 +907,6 @@ class InsertResultSet extends DMLWriteRe
 							       );
 			rowChanger.setIndexNames(constants.indexNames);
 		}
-		else
-		{
-			lcc.getStatementContext().setTopResultSet(this, subqueryTrackingArray);
-		}
 
 		/* decode lock mode for the execution isolation level */
 		int lockMode = decodeLockMode(constants.lockMode);

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/InsertVTIResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/InsertVTIResultSet.java?rev=1087420&r1=1087419&r2=1087420&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/InsertVTIResultSet.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/InsertVTIResultSet.java
Thu Mar 31 19:33:57 2011
@@ -107,16 +107,6 @@ class InsertVTIResultSet extends DMLVTIR
 			throw StandardException.unexpectedUserException(t);
 		}
 
-		/* Get or re-use the row changer.
-		 * NOTE: We need to set ourself as the top result set
-		 * if this is not the 1st execution.  (Done in constructor
-		 * for 1st execution.)
-		 */
-		if (! firstExecute)
-		{
-			lcc.getStatementContext().setTopResultSet(this, subqueryTrackingArray);
-		}
-
 		/* The source does not know whether or not we are doing a
 		 * deferred mode insert.  If we are, then we must clear the
 		 * index scan info from the activation so that the row changer

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/MiscResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/MiscResultSet.java?rev=1087420&r1=1087419&r2=1087420&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/MiscResultSet.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/MiscResultSet.java
Thu Mar 31 19:33:57 2011
@@ -43,11 +43,8 @@ class MiscResultSet extends NoRowsResult
      * Construct a MiscResultSet
 	 *
 	 *  @param activation		Describes run-time environment.
-	 *
-	 *  @exception StandardException Standard Derby error policy.
      */
     MiscResultSet(Activation activation)
-		 throws StandardException
     {
 		super(activation);
 	}

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java?rev=1087420&r1=1087419&r2=1087420&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
Thu Mar 31 19:33:57 2011
@@ -67,7 +67,7 @@ abstract class NoRowsResultSetImpl imple
 {
 	final Activation    activation;
 	private boolean dumpedStats;
-	NoPutResultSet[]	subqueryTrackingArray;
+	private NoPutResultSet[]	subqueryTrackingArray;
 
 	private final boolean statisticsTimingOn;
 	/** True if the result set has been opened, and not yet closed. */
@@ -86,7 +86,6 @@ abstract class NoRowsResultSetImpl imple
 	protected long endExecutionTime;
 
 	NoRowsResultSetImpl(Activation activation)
-		throws StandardException
 	{
 		this.activation = activation;
 
@@ -105,14 +104,6 @@ abstract class NoRowsResultSetImpl imple
 		beginTime = getCurrentTimeMillis();
 		beginExecutionTime = beginTime;
 
-		StatementContext sc = lcc.getStatementContext();
-		sc.setTopResultSet(this, (NoPutResultSet[]) null);
-
-		// Pick up any materialized subqueries
-		if (subqueryTrackingArray == null)
-		{
-			subqueryTrackingArray = sc.getSubqueryTrackingArray();
-		}
 	}
 
 	/**
@@ -123,6 +114,14 @@ abstract class NoRowsResultSetImpl imple
 	 */
 	void setup() throws StandardException {
 		isOpen = true;
+
+        StatementContext sc = lcc.getStatementContext();
+        sc.setTopResultSet(this, subqueryTrackingArray);
+
+        // Pick up any materialized subqueries
+        if (subqueryTrackingArray == null) {
+            subqueryTrackingArray = sc.getSubqueryTrackingArray();
+        }
 	}
 
     /**

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/SetTransactionResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/SetTransactionResultSet.java?rev=1087420&r1=1087419&r2=1087420&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/SetTransactionResultSet.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/SetTransactionResultSet.java
Thu Mar 31 19:33:57 2011
@@ -40,11 +40,8 @@ class SetTransactionResultSet extends Mi
      * Construct a SetTransactionResultSet
 	 *
 	 *  @param activation		Describes run-time environment.
-	 *
-	 *  @exception StandardException Standard Derby error policy.
      */
     SetTransactionResultSet(Activation activation)
-		 throws StandardException
     {
 		super(activation);
 	}

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java?rev=1087420&r1=1087419&r2=1087420&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java
Thu Mar 31 19:33:57 2011
@@ -303,9 +303,6 @@ class UpdateResultSet extends DMLWriteRe
 		}
 
 		/* Get or re-use the row changer.
-		 * NOTE: We need to set ourself as the top result set
-		 * if this is not the 1st execution.  (Done in constructor
-		 * for 1st execution.)
 		 */
 		if (firstOpen)
 		{
@@ -326,10 +323,6 @@ class UpdateResultSet extends DMLWriteRe
 										 activation);
 			rowChanger.setIndexNames(constants.indexNames);
 		}
-		else
-		{
-			lcc.getStatementContext().setTopResultSet(this, subqueryTrackingArray);
-		}
 
 
 		/* Open the RowChanger before the source ResultSet so that

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/UpdateVTIResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/UpdateVTIResultSet.java?rev=1087420&r1=1087419&r2=1087420&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/UpdateVTIResultSet.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/execute/UpdateVTIResultSet.java
Thu Mar 31 19:33:57 2011
@@ -76,8 +76,6 @@ class UpdateVTIResultSet extends DMLVTIR
 
         if( null != row)
             rowLocationColumn = row.nColumns();
-		if (!firstExecute)
-			lcc.getStatementContext().setTopResultSet(this, subqueryTrackingArray);
 
 		/* The source does not know whether or not we are doing a
 		 * deferred mode insert.  If we are, then we must clear the

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java?rev=1087420&r1=1087419&r2=1087420&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
(original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
Thu Mar 31 19:33:57 2011
@@ -172,6 +172,8 @@ public class ResultSetsFromPreparedState
 
     private static final long DERBY_DEFAULT_TIMEOUT = 60;
 
+    private static final String SQLSTATE_NULL_INTO_NON_NULL = "23502";
+
     /**
      * Creates a String containing an insert statement for the
      * specified table containing the specified number of '?'
@@ -2485,4 +2487,30 @@ public class ResultSetsFromPreparedState
         stm.execute("SET SCHEMA " + schema);
         stm.close();
     }
+
+    /**
+     * Test case for DERBY-4488, where the third execution of a statement
+     * that attempted to insert a NULL into a non-nullable column failed with
+     * a NullPointerException.
+     */
+    public void testInsertNullIntoNonNullableColumn() throws SQLException {
+        setAutoCommit(false);
+
+        Statement s = createStatement();
+        s.execute("create table d4488_t1 (pk int primary key)");
+        s.execute("insert into d4488_t1 values 1");
+        s.execute("create table d4488_t2 (c1 int, c2 int not null)");
+        commit();
+
+        PreparedStatement ps = prepareStatement(
+                "insert into d4488_t2(c1) select 1 from d4488_t1");
+        for (int i = 0; i < 5; i++) {
+            // Expect this to fail, but not with NullPointerException.
+            assertStatementError(SQLSTATE_NULL_INTO_NON_NULL, ps);
+            // Need a rollback here in order to close the index scan on
+            // D4488_T1, otherwise the NPE won't reproduce. Alternatively,
+            // run with auto-commit enabled.
+            rollback();
+        }
+    }
 }



Mime
View raw message