db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r710071 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ResultColumnList.java testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Date Mon, 03 Nov 2008 14:45:17 GMT
Author: rhillegas
Date: Mon Nov  3 06:45:16 2008
New Revision: 710071

URL: http://svn.apache.org/viewvc?rev=710071&view=rev
Log:
DERBY-481: Allow DEFAULT literal on INSERTs into generated columns which don't have explicity
target lists.

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/GeneratedColumnsTest.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=710071&r1=710070&r2=710071&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
Mon Nov  3 06:45:16 2008
@@ -3899,7 +3899,16 @@
 				} // end of if ()
 				
 				DefaultInfoImpl defaultInfo = (DefaultInfoImpl) cd.getDefaultInfo();
-				if (defaultInfo != null)
+
+                //
+                // For generated columns, we don't have enough context at this
+                // point to bind the generation clause (the default) and
+                // unfortunately that step occurs very soon after defaults are substituted
in. The
+                // parsing and binding of generation clauses happens considerably
+                // later on. At this juncture, we can be patient and just plug
+                // in a NULL literal as a placeholder.
+                //
+				if ( (defaultInfo != null) && !defaultInfo.isGeneratedColumn() )
 				{
 					/* Query is dependent on the DefaultDescriptor */
 					DefaultDescriptor defaultDescriptor = cd.getDefaultDescriptor(getDataDictionary());

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java?rev=710071&r1=710070&r2=710071&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Mon Nov  3 06:45:16 2008
@@ -407,6 +407,11 @@
              conn,
              "create unique index t_insert_2_b on t_insert_2( b )"
              );
+        goodStatement
+            (
+             conn,
+             "create table t_insert_3( a int, b int generated always as ( -a ) )"
+             );
         
         goodStatement
             (
@@ -442,6 +447,17 @@
              "insert into t_insert_2( a, b ) values ( 6, default )"
              );
         
+        goodStatement
+            (
+             conn,
+             "insert into t_insert_3 values ( 1, default )"
+             );
+        goodStatement
+            (
+             conn,
+             "insert into t_insert_3 values ( 2, default ), ( 3, default ), ( 4, default
)"
+             );
+        
         //
         // Verify that all of the expected rows are in the table having the
         // generated column.
@@ -465,6 +481,20 @@
              false
              );
         
+        assertResults
+            (
+             conn,
+             "select * from t_insert_3 order by a",
+             new String[][]
+             {
+                 { "1" ,         "-1" },
+                 { "2" ,         "-2" },
+                 { "3" ,         "-3" },
+                 { "4" ,         "-4" },
+             },
+             false
+             );
+        
         // fails trying to override a generation clause
         expectCompilationError
             (



Mime
View raw message