db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1301677 - in /db/derby/code/branches/10.5: ./ java/ 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 18:10:21 GMT
Author: kmarsden
Date: Fri Mar 16 18:10:21 2012
New Revision: 1301677

URL: http://svn.apache.org/viewvc?rev=1301677&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.5/   (props changed)
    db/derby/code/branches/10.5/java/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar 16 18:10:21 2012
@@ -1,4 +1,4 @@
 /db/derby/code/branches/10.6:942027,957000,957287,958621,962738,965351,987678,997790*,1031623,1055601,1068474,1071167
 /db/derby/code/branches/10.7:1294731
 /db/derby/code/branches/10.8:1209227-1209228,1209284
-/db/derby/code/trunk:757811,764912,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792001,792254,792434,793089,793588,794106,794276,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803336,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,826263,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,891350,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915177,915733,916075,916897,917771,918152,918359,921028,927430,928065,929085,931076,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952237,952581,954748,955001,955634,956075,956445,956659,957260,958163,958618,959550,961892,962716,964039,964402,96
 5647,966393,967201,967304,980089,980684,986689,986834,987539,989099,997325*,998170,999119,999485,1002291,1002682,1002853,1021426,1024511,1024528,1025615,1025795,1030043,1040658,1053724,1055169,1062096,1063809,1065061,1067250,1069661,1071886,1081455,1085078,1136363,1138341,1138444,1141924,1203050,1207729,1208775,1293494,1294512
+/db/derby/code/trunk:757811,764912,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792001,792254,792434,793089,793588,794106,794276,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803336,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,826263,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,891350,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915177,915733,916075,916897,917771,918152,918359,921028,927430,928065,929085,931076,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952237,952581,954748,955001,955634,956075,956445,956659,957260,958163,958618,959550,961892,962716,964039,964402,96
 5647,966393,967201,967304,980089,980684,986689,986834,987539,989099,997325*,998170,999119,999485,1002291,1002682,1002853,1021426,1024511,1024528,1025615,1025795,1030043,1040658,1053724,1055169,1062096,1063809,1065061,1067250,1069661,1071886,1081455,1085078,1136363,1138341,1138444,1140222,1140744,1141924,1203050,1207729,1208775,1293494,1294512

Propchange: db/derby/code/branches/10.5/java/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar 16 18:10:21 2012
@@ -1,4 +1,4 @@
 /db/derby/code/branches/10.6/java:942027,957000,957287,958621,962738,965351,987678,1031623,1055601,1068474,1071167
 /db/derby/code/branches/10.7/java:1294731
 /db/derby/code/branches/10.8/java:1209227-1209228,1209284
-/db/derby/code/trunk/java:757811,764912,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792001,792254,792434,793089,793588,794106,794276,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803336,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,826263,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,891350,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915177,915733,916075,916897,917771,918152,918359,921028,927430,928065,929085,931076,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952237,952581,954748,955001,955634,956075,956445,956659,957260,958163,958618,959550,961892,962716,964039,9644
 02,965647,966393,967201,967304,980089,980684,986689,986834,987539,989099,998170,999119,999485,1002291,1002682,1002853,1021426,1024511,1024528,1025615,1025795,1030043,1040658,1053724,1055169,1062096,1063809,1065061,1067250,1069661,1071886,1081455,1085078,1136363,1138341,1138444,1141924,1294512
+/db/derby/code/trunk/java:757811,764912,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792001,792254,792434,793089,793588,794106,794276,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803336,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,826263,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,891350,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915177,915733,916075,916897,917771,918152,918359,921028,927430,928065,929085,931076,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952237,952581,954748,955001,955634,956075,956445,956659,957260,958163,958618,959550,961892,962716,964039,9644
 02,965647,966393,967201,967304,980089,980684,986689,986834,987539,989099,998170,999119,999485,1002291,1002682,1002853,1021426,1024511,1024528,1025615,1025795,1030043,1040658,1053724,1055169,1062096,1063809,1065061,1067250,1069661,1071886,1081455,1085078,1136363,1138341,1138444,1140744,1141924,1294512

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java?rev=1301677&r1=1301676&r2=1301677&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java
Fri Mar 16 18:10:21 2012
@@ -151,28 +151,35 @@ abstract class DMLWriteResultSet extends
 					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.getClone());
-					}
-				}
-			}
+                DataValueDescriptor col = row.getColumn(readIx + 1);
+                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.getClone());
+                        }
+                }
+            }
+        }
 	}
 
 	/**

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java?rev=1301677&r1=1301676&r2=1301677&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Fri Mar 16 18:10:21 2012
@@ -949,7 +949,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 ]" },
              }
              );
@@ -5435,6 +5435,70 @@ 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
+         
+        );
+    }
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS
@@ -5556,6 +5620,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