db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1301671 - in /db/derby/code/branches/10.7: ./ java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Date Fri, 16 Mar 2012 17:56:42 GMT
Author: kmarsden
Date: Fri Mar 16 17:56:42 2012
New Revision: 1301671

URL: http://svn.apache.org/viewvc?rev=1301671&view=rev
Log:
DERBY-4779 NPE while inserting into a table which has a generated column and an insert trigger
DERBY-5304 fix for DERBY-4779 test on jdk 142

Contributed by Siddharth Srivastava akssps011 at gmail dot com
merged revisions 1140222 , 140744 from trunk 


Modified:
    db/derby/code/branches/10.7/   (props changed)
    db/derby/code/branches/10.7/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java
    db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java

Propchange: db/derby/code/branches/10.7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar 16 17:56:42 2012
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.8:1209227-1209228,1209284
-/db/derby/code/trunk:1035603,1036769,1038514,1038813,1039084,1039268,1040658,1041338,1043227,1043389,1044096,1051026,1053724,1055169,1059888,1060480,1062096,1063809,1065061,1066290,1067250,1067357,1069661,1071463,1071886,1076335,1076387,1078461,1078608,1078693,1081072,1081455,1081568,1085078,1086527,1091000,1097247,1103681,1103718,1128243,1129136,1130632,1130895,1131272,1132664,1136363,1138341,1138444,1139449,1141924,1164370,1203050,1207729,1208775,1209228,1243878,1293494,1294512,1294522,1295085
+/db/derby/code/trunk:1035603,1036769,1038514,1038813,1039084,1039268,1040658,1041338,1043227,1043389,1044096,1051026,1053724,1055169,1059888,1060480,1062096,1063809,1065061,1066290,1067250,1067357,1069661,1071463,1071886,1076335,1076387,1078461,1078608,1078693,1081072,1081455,1081568,1085078,1086527,1091000,1097247,1103681,1103718,1128243,1129136,1130632,1130895,1131272,1132664,1136363,1138341,1138444,1139449,1140222,1140744,1141924,1164370,1203050,1207729,1208775,1209228,1243878,1293494,1294512,1294522,1295085

Modified: db/derby/code/branches/10.7/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java?rev=1301671&r1=1301670&r2=1301671&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java
(original)
+++ db/derby/code/branches/10.7/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java
Fri Mar 16 17:56:42 2012
@@ -150,26 +150,30 @@ abstract class DMLWriteResultSet extends
 					heapIx :
 					baseRowReadMap[heapIx];
 
-                
 				DataValueDescriptor col = row.getColumn(readIx+1);
-				InputStream stream = ((StreamStorable)col).returnStream();
-				((StreamStorable)col).loadStream();
-				// DERBY-3238 
-				// fix up any duplicate streams, for instance in the case of an update with a trigger,
-				// all the columns are read as update columns even if they are not updated, so 
-				// the update column will still have a reference to the original stream.
-				// If we knew from this context that this was an update and we knew the number
-				// of columns in the base table we would be able to calculate exactly the offset to 
-				// check, but we don't have that information from this context.
-				// If DERBY-1482 is fixed, perhaps this code can be removed.
 				
-				if (stream != null)
-					for (int i = 1; i <= row.nColumns(); i++)
-					{
-						DataValueDescriptor c = row.getColumn(i);
-						if (c instanceof StreamStorable)
-							if (((StreamStorable)c).returnStream() == stream)
-								row.setColumn(i, col.cloneValue(false));
+				// Derby-4779
+				if ( col != null ) {
+					InputStream stream = ((StreamStorable)col).returnStream();
+					((StreamStorable)col).loadStream();
+
+					// DERBY-3238
+					// fix up any duplicate streams, for instance in the case of an update with a trigger,
+					// all the columns are read as update columns even if they are not updated, so 
+					// the update column will still have a reference to the original stream.
+					// If we knew from this context that this was an update and we knew the number
+					// of columns in the base table we would be able to calculate exactly the offset to

+					// check, but we don't have that information from this context.
+					// If DERBY-1482 is fixed, perhaps this code can be removed.
+
+					if (stream != null)
+						for (int i = 1; i <= row.nColumns(); i++)
+						{
+							DataValueDescriptor c = row.getColumn(i);
+							if (c instanceof StreamStorable)
+								if (((StreamStorable)c).returnStream() == stream)
+									row.setColumn(i, col.cloneValue(false));
+						}
 					}
 				}
 			}

Modified: db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java?rev=1301671&r1=1301670&r2=1301671&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
(original)
+++ db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Fri Mar 16 17:56:42 2012
@@ -986,7 +986,7 @@ public class GeneratedColumnsTest extend
                  { "before_insert_statement_trigger: [ -1, -1, -1 ]" },
                  { "after_insert_row_trigger: [ 1, -1, null ]" },
                  { "after_insert_row_trigger: [ 2, -2, null ]" },
-                 { "after_insert_row_trigger: [ 3, -3, null ]" },                       
                                   
+                 { "after_insert_row_trigger: [ 3, -3, null ]" },
                  { "after_insert_statement_trigger: [ -1, -1, -1 ]" },
              }
              );
@@ -5472,7 +5472,69 @@ public class GeneratedColumnsTest extend
                 new String[][] { {"1","2"},{"2","4"},{"3","6"}}, false);
     }
 
+    // Derby 4779
+    public void test_derby_4779()
+        throws Exception
+    {
+    	Connection conn = getConnection();
 
+        goodStatement
+        (
+         conn,
+         "create function f_getRegion\n" +
+         "(\n" +
+         "    v int\n" +
+         ")\n" +
+         "returns int\n" +
+         "language java\n" +
+         "parameter style java\n" +
+         "deterministic\n" +
+         "no sql\n" +
+         "external name 'org.apache.derbyTesting.functionTests.tests.lang.GeneratedColumnsTest.signum'\n"
+        );
+
+        goodStatement
+        (
+         conn,
+         "create table t1_orders( price int, region generated always as " +
+         "( f_getRegion(price) ) )\n"
+        );
+        
+        goodStatement
+        (
+         conn,
+         "create table t1_dummy(a int)\n"
+        );
+
+        goodStatement
+        (
+         conn,
+         "create trigger t1_trig_after_insert_row_trigger_4779\n" +
+         "after insert on t1_orders\n" +
+         "referencing new as ar\n" +
+         "for each row\n" +
+         "insert into t1_dummy( a ) values ( 1 )\n"
+        );
+
+        goodStatement
+        (
+         conn, 
+         "insert into t1_orders(price) values (1), (2)"
+        );
+
+        assertResults
+        ( 
+         conn,
+         "select a from t1_dummy",
+         new String[][]
+                      {
+                          { "1" },
+                          { "1" }
+                      },
+                      false
+         
+        );
+    }
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -5595,6 +5657,13 @@ public class GeneratedColumnsTest extend
         return _minusCounter;
     }
 
+    public static   int signum( int i )
+    {
+        if ( i > 0 ) { return 1; }
+        else if ( i == 0 ) { return 0; }
+        else { return -1; }
+    }
+
     public  static  void    clearTriggerReports()
     {
         _triggerReports.clear();



Mime
View raw message