db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r644395 - in /db/derby/code/branches/10.4/java: engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java
Date Thu, 03 Apr 2008 16:24:31 GMT
Author: kmarsden
Date: Thu Apr  3 09:24:30 2008
New Revision: 644395

URL: http://svn.apache.org/viewvc?rev=644395&view=rev
Log:
DERBY-3566 Alter column set data type not allowed in soft upgrade with unique constraint

Contributed by Anurag Shekhar (anurag dot shekhar at sun dot com)


Modified:
    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/tests/upgradeTests/Changes10_4.java

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=644395&r1=644394&r2=644395&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
Thu Apr  3 09:24:30 2008
@@ -188,18 +188,20 @@
 			}	
 			else
 			{
-				//if a column is part of unique constraint it can't be
-				//made nullable in soft upgrade mode from a pre-10.4 db.
-				if ((existingConstraint.getConstraintType() == 
-								DataDictionary.UNIQUE_CONSTRAINT)) 
-                {
-					if (!dd.checkVersion(
-							DataDictionary.DD_VERSION_DERBY_10_4, null))
-                    {
+				if (!dd.checkVersion(
+					DataDictionary.DD_VERSION_DERBY_10_4, null)) 
+				{
+					//if a column is part of unique constraint it can't be
+					//made nullable in soft upgrade mode from a pre-10.4 db.
+					if ((getNodeType() == 
+						C_NodeTypes.MODIFY_COLUMN_CONSTRAINT_NODE) &&
+						(existingConstraint.getConstraintType() == 
+							DataDictionary.UNIQUE_CONSTRAINT)) 
+					{
 						throw StandardException.newException(
-								SQLState.LANG_MODIFY_COLUMN_EXISTING_CONSTRAINT,
-								name);
-                    }
+							SQLState.LANG_MODIFY_COLUMN_EXISTING_CONSTRAINT,
+							name);
+					}
 				}
 
 				// a column that is part of a primary key

Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java?rev=644395&r1=644394&r2=644395&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java
(original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_4.java
Thu Apr  3 09:24:30 2008
@@ -627,4 +627,31 @@
         }
         s.close();
     }
+    
+    /**
+     * Tests if alter column works for a column in unique constraint.
+     */
+    public void testAlterColumnOfUniqueConstraint () throws Exception {
+        Statement stmt = createStatement();
+        switch (getPhase()) {
+           case PH_CREATE:
+               stmt.executeUpdate("create table datatype_test (fl1 varchar (2) " +
+                       "not null)");
+               stmt.executeUpdate("alter table datatype_test " +
+                       "add constraint ucon_datatype_test unique (fl1)");
+               stmt.executeUpdate("alter table datatype_test alter column fl1" +
+                       " set data type varchar (3)");
+               break;
+           case PH_SOFT_UPGRADE:
+               stmt.executeUpdate("alter table datatype_test alter column fl1 " +
+                       " set data type varchar (4)");
+               break;
+
+           case PH_HARD_UPGRADE:
+               stmt.executeUpdate("alter table datatype_test alter column fl1 " +
+                       " set data type varchar (5)");
+               break;
+        }
+        stmt.close();
+    }
 }



Mime
View raw message