db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r734585 - in /db/derby/code/branches/10.4/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Thu, 15 Jan 2009 00:38:34 GMT
Author: bpendleton
Date: Wed Jan 14 16:38:33 2009
New Revision: 734585

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

Merged the trunk revision 733401 to the 10.4 branch. Modified the change
by removing the tests for generated columns, which are not present in 10.4.


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

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java?rev=734585&r1=734584&r2=734585&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/ColumnDefinitionNode.java
Wed Jan 14 16:38:33 2009
@@ -76,6 +76,7 @@
 	DataValueDescriptor			defaultValue;
 	DefaultInfoImpl				defaultInfo;
 	DefaultNode					defaultNode;
+	boolean						keepCurrentDefault;
 	long						autoincrementIncrement;
 	long						autoincrementStart;
 	//This variable tells if the autoincrement column is participating 
@@ -169,6 +170,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/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java?rev=734585&r1=734584&r2=734585&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
Wed Jan 14 16:38:33 2009
@@ -338,7 +338,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();
 		if (autoinc_create_or_modify_Start_Increment ==
 				ColumnDefinitionNode.MODIFY_AUTOINCREMENT_RESTART_VALUE)

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out?rev=734585&r1=734584&r2=734585&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/master/autoincrement.out
Wed Jan 14 16:38:33 2009
@@ -2065,4 +2065,41 @@
 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)> 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/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql?rev=734585&r1=734584&r2=734585&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
Wed Jan 14 16:38:33 2009
@@ -1095,3 +1095,23 @@
 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;
+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