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 ka...@apache.org on 2010/07/13 09:36:12 UTC

svn commit: r963617 - in /db/derby/code/branches/10.6: ./ java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java

Author: kahatlen
Date: Tue Jul 13 07:36:11 2010
New Revision: 963617

URL: http://svn.apache.org/viewvc?rev=963617&view=rev
Log:
DERBY-4449: ArrayIndexOutOfBoundsException when inserting DEFAULT into unspecified column

Merged fix from trunk (revision 951366).

Backported and tested by Lily Wei.

Modified:
    db/derby/code/branches/10.6/   (props changed)
    db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
    db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java

Propchange: db/derby/code/branches/10.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 13 07:36:11 2010
@@ -1,2 +1,2 @@
-/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,952138,952237,952581,954344,954421,954544,954748,955001,955634,956075,956234,956445,956569,956659,957260,958163,958618,959550,962716
+/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,951366,952138,952237,952581,954344,954421,954544,954748,955001,955634,956075,956234,956445,956569,956659,957260,958163,958618,959550,962716
 /db/derby/docs/trunk:954344

Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?rev=963617&r1=963616&r2=963617&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java (original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java Tue Jul 13 07:36:11 2010
@@ -4046,12 +4046,12 @@ public class ResultColumnList extends Qu
 
 				//				DefaultNode defaultNode = (DefaultNode) rc.getExpression();
 				// Get ColumnDescriptor by name or by position?
-				ColumnDescriptor cd;
+				ColumnDescriptor cd = null;
 				if (tcl == null)
 				{
 					cd = ttd.getColumnDescriptor(index + 1);
 				}
-				else
+				else if (index < tcl.size())
 				{
 					ResultColumn trc = (ResultColumn) tcl.elementAt(index);
 					cd = ttd.getColumnDescriptor(trc.getName());

Modified: db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java?rev=963617&r1=963616&r2=963617&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java (original)
+++ db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java Tue Jul 13 07:36:11 2010
@@ -35,6 +35,7 @@ import org.apache.derbyTesting.junit.Tes
 public class InsertTest extends BaseJDBCTestCase {
 
     private static final String PARAMETER_IN_SELECT_LIST = "42X34";
+    private static final String TOO_MANY_RESULT_COLUMNS = "42X06";
 
     public InsertTest(String name) {
         super(name);
@@ -187,4 +188,23 @@ public class InsertTest extends BaseJDBC
                 "insert into derby4671 select ? from derby4671 "
                 + "intersect select ? from derby4671");
     }
+
+    /**
+     * Regression test case for DERBY-4449. INSERT statements with an explicit
+     * target column list used to fail with ArrayIndexOutOfBoundsException if
+     * the table constructor had more columns than the target column list and
+     * one of the extra columns was specified as DEFAULT.
+     */
+    public void testInsertTooManyDefaultColumns() throws SQLException {
+        createStatement().execute("create table derby4449(x int)");
+        // This statement has always failed gracefully (no explicit target
+        // column list)
+        assertCompileError(
+                TOO_MANY_RESULT_COLUMNS,
+                "insert into derby4449 values (default, default)");
+        // This statement used to fail with ArrayIndexOutOfBoundsException
+        assertCompileError(
+                TOO_MANY_RESULT_COLUMNS,
+                "insert into derby4449 (x) values (default, default)");
+    }
 }