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 rh...@apache.org on 2009/04/08 15:11:54 UTC

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

Author: rhillegas
Date: Wed Apr  8 13:11:53 2009
New Revision: 763235

URL: http://svn.apache.org/viewvc?rev=763235&view=rev
Log:
DERBY-4146: Ported 763230 from trunk to 10.5 branch.

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

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?rev=763235&r1=763234&r2=763235&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java Wed Apr  8 13:11:53 2009
@@ -4096,6 +4096,8 @@
                 {
                     throw StandardException.newException(SQLState.LANG_CANT_OVERRIDE_GENERATION_CLAUSE, rc.getName());
                 }
+
+                if ( sourceRC != null ) { sourceRC.setColumnDescriptor(cd.getTableDescriptor(), cd); }
             }
 			
 			if ((cd != null) && (cd.isAutoincrement()))

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=763235&r1=763234&r2=763235&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 Wed Apr  8 13:11:53 2009
@@ -5117,6 +5117,148 @@
              );
     }
     
+    /**
+     * <p>
+     * Test that a generated column can refer to an identity column.
+     * </p>
+     */
+    public  void    test_030_derby_4146()
+        throws Exception
+    {
+        Connection  conn = getConnection();
+
+        //
+        // Schema
+        //
+        goodStatement
+            (
+             conn,
+             "create table t_4146 (c1 int generated always as identity, c2 generated always as (c1+100))"
+             );
+        goodStatement
+            (
+             conn,
+             "create table t_4146_2 (c1 int generated always as identity, c2 generated always as (c1+100), c3 int default 1000)"
+             );
+
+        goodStatement
+            (
+             conn,
+             "insert into t_4146 values ( default, default )"
+             );
+        expectCompilationError
+            (
+             CANT_MODIFY_IDENTITY,
+             "insert into t_4146 values ( -1, default )"
+             );
+        expectCompilationError
+            (
+             CANT_OVERRIDE_GENERATION_CLAUSE,
+             "insert into t_4146 values ( default, -1 )"
+             );
+        goodStatement
+            (
+             conn,
+             "insert into t_4146 (c1, c2) values ( default, default )"
+             );
+        expectCompilationError
+            (
+             CANT_MODIFY_IDENTITY,
+             "insert into t_4146 (c1, c2) values ( -1, default )"
+             );
+        expectCompilationError
+            (
+             CANT_OVERRIDE_GENERATION_CLAUSE,
+             "insert into t_4146 (c1, c2) values ( default, -1 )"
+             );
+        assertResults
+            (
+             conn,
+             "select * from t_4146 order by c1",
+             new String[][]
+             {
+                 { "1", "101", },
+                 { "2", "102", },
+             },
+             false
+             );
+
+        goodStatement
+            (
+             conn,
+             "insert into t_4146_2 values ( default, default, default )"
+             );
+        expectCompilationError
+            (
+             CANT_MODIFY_IDENTITY,
+             "insert into t_4146_2 values ( -1, default, default )"
+             );
+        expectCompilationError
+            (
+             CANT_OVERRIDE_GENERATION_CLAUSE,
+             "insert into t_4146_2 values ( default, -1, default )"
+             );
+        goodStatement
+            (
+             conn,
+             "insert into t_4146_2 (c1, c2) values ( default, default )"
+             );
+        expectCompilationError
+            (
+             CANT_MODIFY_IDENTITY,
+             "insert into t_4146_2 (c1, c2) values ( -1, default )"
+             );
+        expectCompilationError
+            (
+             CANT_OVERRIDE_GENERATION_CLAUSE,
+             "insert into t_4146_2 (c1, c2) values ( default, -1 )"
+             );
+        goodStatement
+            (
+             conn,
+             "insert into t_4146_2 (c1, c2, c3) values ( default, default, default )"
+             );
+        expectCompilationError
+            (
+             CANT_MODIFY_IDENTITY,
+             "insert into t_4146_2 (c1, c2, c3) values ( -1, default, default )"
+             );
+        expectCompilationError
+            (
+             CANT_OVERRIDE_GENERATION_CLAUSE,
+             "insert into t_4146_2 (c1, c2, c3) values ( default, -1, default )"
+             );
+        goodStatement
+            (
+             conn,
+             "insert into t_4146_2 (c1, c2, c3) values ( default, default, 2000 )"
+             );
+        expectCompilationError
+            (
+             CANT_MODIFY_IDENTITY,
+             "insert into t_4146_2 (c1, c2, c3) values ( -1, default, 3000 )"
+             );
+        expectCompilationError
+            (
+             CANT_OVERRIDE_GENERATION_CLAUSE,
+             "insert into t_4146_2 (c1, c2, c3) values ( default, -1, 4000 )"
+             );
+        assertResults
+            (
+             conn,
+             "select * from t_4146_2 order by c1",
+             new String[][]
+             {
+                 { "1", "101", "1000", },
+                 { "2", "102", "1000", },
+                 { "3", "103", "1000", },
+                 { "4", "104", "2000", },
+             },
+             false
+             );
+
+    }
+    
 
     ///////////////////////////////////////////////////////////////////////////////////
     //