db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r733401 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Sun, 11 Jan 2009 00:02:57 GMT
Author: bpendleton
Date: Sat Jan 10 16:02:56 2009
New Revision: 733401

URL: http://svn.apache.org/viewvc?rev=733401&view=rev
Log:
DERBY-4006: ALTER COLUMN .. WITH DEFAULT NULL does not change the default

The code in ModifyColumnNode was having trouble distinguishing between
the case where the user didn't specify a default at all, versus the
case where they explicitly specified a default value of NULL. 

ModifyColumnNode wants to be able to ask if "no default value was specified",
so this change adds a boolean instance variable "keepCurrentDefault" to
the superclass ColumnDefinitionNode, and initializes it to TRUE if no
default clause was specified. Then ModifyColumnNode uses this variable
to decide whether to preserve the current default value when re-building
the column's definition.

Several new test cases are also added.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java?rev=733401&r1=733400&r2=733401&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
Sat Jan 10 16:02:56 2009
@@ -76,6 +76,7 @@
 	DataValueDescriptor			defaultValue;
 	DefaultInfoImpl				defaultInfo;
 	DefaultNode					defaultNode;
+	boolean						keepCurrentDefault;
     GenerationClauseNode   generationClauseNode;
 	long						autoincrementIncrement;
 	long						autoincrementStart;
@@ -174,6 +175,17 @@
                     setNullability(false);
 			}
 		}
+		// ColumnDefinitionNode instances can be subclassed by
+		// ModifyColumnNode for use in ALTER TABLE .. ALTER COLUMN
+		// statements, in which case the node represents the intended
+		// changes to the column definition. For such a case, we
+		// record whether or not the statement specified that the
+		// column's default value should be changed. If we are to
+		// keep the current default, ModifyColumnNode will re-read
+		// the current default from the system catalogs prior to
+		// performing the column alteration. See DERBY-4006
+		// for more discussion of this behavior.
+		this.keepCurrentDefault = (defaultNode == null);
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java?rev=733401&r1=733400&r2=733401&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
Sat Jan 10 16:02:56 2009
@@ -343,7 +343,7 @@
 		// and re-use it. This way, the column alteration only changes the
 		// aspects of the autoincrement settings that it intends to change,
 		// and does not lose the other aspecs.
-		if (defaultNode == null)
+		if (keepCurrentDefault)
         { defaultInfo = (DefaultInfoImpl)cd.getDefaultInfo(); }
         else
         {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out?rev=733401&r1=733400&r2=733401&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
Sat Jan 10 16:02:56 2009
@@ -2068,4 +2068,48 @@
 0 rows inserted/updated/deleted
 ij(CONN2)> drop table t2902_c;
 0 rows inserted/updated/deleted
+ij(CONN2)> -- DERBY-4006: can't alter a column's default value to NULL. This problem
+-- was a regression from the fixes for DERBY-1495 and DERBY-1645, and
+-- involved an inability to distinguish between not specifying the DEFAULT
+-- clause on the ALTER COLUMN statement at all, versus specify the clause
+-- DEFAULT NULL
+create table d4006 (x varchar(5) default 'abc');
+0 rows inserted/updated/deleted
+ij(CONN2)> insert into d4006 values default;
+1 row inserted/updated/deleted
+ij(CONN2)> alter table d4006 alter column x with default null;
+0 rows inserted/updated/deleted
+ij(CONN2)> insert into d4006 values default;
+1 row inserted/updated/deleted
+ij(CONN2)> alter table d4006 alter column x with default 'def';
+0 rows inserted/updated/deleted
+ij(CONN2)> insert into d4006 values default;
+1 row inserted/updated/deleted
+ij(CONN2)> select * from d4006;
+X    
+-----
+abc  
+NULL 
+def  
+ij(CONN2)> -- Demonstrate that you can't change the default value for a generated column:
+alter table d4006 add column y int generated always as (-1);
+0 rows inserted/updated/deleted
+ij(CONN2)> alter table d4006 alter column y default 42;
+ERROR 42XA7: 'Y' is a generated column. You cannot change its default value.
+ij(CONN2)> alter table d4006 alter column y default null;
+ERROR 42XA7: 'Y' is a generated column. You cannot change its default value.
+ij(CONN2)> drop table d4006;
+0 rows inserted/updated/deleted
+ij(CONN2)> -- Note that if the column is GENERATED ALWAYS the default CAN be altered,
+-- but this is probably incorrect. See DERBY-4011 for more discussion.
+create table d4006_a (z int generated always as identity);
+0 rows inserted/updated/deleted
+ij(CONN2)> alter table d4006_a alter column z default 99;
+0 rows inserted/updated/deleted
+ij(CONN2)> -- should fail DERBY-4011
+alter table d4006_a alter column z default null;
+0 rows inserted/updated/deleted
+ij(CONN2)> -- should fail DERBY-4011
+drop table d4006_a;
+0 rows inserted/updated/deleted
 ij(CONN2)> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql?rev=733401&r1=733400&r2=733401&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
Sat Jan 10 16:02:56 2009
@@ -1095,3 +1095,27 @@
 drop table t2902_b;
 drop table t2902_c;
 
+-- DERBY-4006: can't alter a column's default value to NULL. This problem
+-- was a regression from the fixes for DERBY-1495 and DERBY-1645, and
+-- involved an inability to distinguish between not specifying the DEFAULT
+-- clause on the ALTER COLUMN statement at all, versus specify the clause
+-- DEFAULT NULL
+create table d4006 (x varchar(5) default 'abc');
+insert into d4006 values default;
+alter table d4006 alter column x with default null;
+insert into d4006 values default;
+alter table d4006 alter column x with default 'def';
+insert into d4006 values default;
+select * from d4006;
+-- Demonstrate that you can't change the default value for a generated column:
+alter table d4006 add column y int generated always as (-1);
+alter table d4006 alter column y default 42;
+alter table d4006 alter column y default null;
+drop table d4006;
+-- Note that if the column is GENERATED ALWAYS the default CAN be altered,
+-- but this is probably incorrect. See DERBY-4011 for more discussion.
+create table d4006_a (z int generated always as identity);
+alter table d4006_a alter column z default 99; -- should fail DERBY-4011
+alter table d4006_a alter column z default null; -- should fail DERBY-4011
+drop table d4006_a;
+



Mime
View raw message