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/06/04 13:09:49 UTC

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

Author: kahatlen
Date: Fri Jun  4 11:09:49 2010
New Revision: 951366

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

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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?rev=951366&r1=951365&r2=951366&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java Fri Jun  4 11:09:49 2010
@@ -3913,12 +3913,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/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java?rev=951366&r1=951365&r2=951366&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/InsertTest.java Fri Jun  4 11:09:49 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)");
+    }
 }