db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r560289 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java engine/org/apache/derby/impl/sql/compile/TableElementList.java testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Date Fri, 27 Jul 2007 15:53:48 GMT
Author: mamta
Date: Fri Jul 27 08:53:45 2007
New Revision: 560289

URL: http://svn.apache.org/viewvc?view=rev&rev=560289
Log:
DERBY-2973

ALTER TABLE MODIFY COLUMN should maintain the collation info when the column being altered
is character string type. The changes for this went into as a new method in ModifyColumnNode
which gets called during the bind phase.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java

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?view=diff&rev=560289&r1=560288&r2=560289
==============================================================================
--- 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
Fri Jul 27 08:53:45 2007
@@ -37,6 +37,7 @@
 
 import org.apache.derby.iapi.types.TypeId;
 import org.apache.derby.iapi.types.DataTypeDescriptor;
+import org.apache.derby.iapi.types.StringDataValue;
 
 import org.apache.derby.iapi.reference.SQLState;
 
@@ -211,8 +212,39 @@
 				getCompilerContext().createDependency(existingConstraint);
 			}
 		}
+    }
 
-	}
+	/**
+	 * If the column being modified is of character string type, then it should
+	 * get it's collation from the corresponding column in the TableDescriptor.
+	 * This will ensure that at alter table time, the existing character string
+	 * type columns do not loose their collation type. If the alter table is 
+	 * doing a drop column, then we do not need to worry about collation info.
+	 * 
+	 * @param td Table Descriptor that holds the column which is being altered
+	 * @throws StandardException
+	 */
+	public void useExistingCollation(TableDescriptor td)
+    throws StandardException
+    {
+		ColumnDescriptor cd;
+
+		// First verify that the column exists
+		cd = td.getColumnDescriptor(name);
+		if (cd == null)
+		{
+			throw StandardException.newException(SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE, name, td.getName());
+		}
+		//getType() == null means we are dealing with drop column and hence 
+		//no need to worry about collation info
+		if (getType() != null) {
+			if (getType().getTypeId().isStringTypeId()) {
+				this.getType().setCollationType(cd.getType().getCollationType());
+				this.getType().setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+			
+			}
+		}
+    }
 	/**
 	 * Get the action associated with this node.
 	 *

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java?view=diff&rev=560289&r1=560288&r2=560289
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
Fri Jul 27 08:53:45 2007
@@ -204,6 +204,7 @@
 				{
 					ModifyColumnNode mcdn = (ModifyColumnNode)cdn;
 					mcdn.checkExistingConstraints(td);
+					mcdn.useExistingCollation(td);
 				} else if (cdn.isAutoincrementColumn())
 					numAutoCols ++;
 			}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?view=diff&rev=560289&r1=560288&r2=560289
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Fri Jul 27 08:53:45 2007
@@ -987,7 +987,15 @@
     rs.moveToInsertRow();
     rs.close();
     ps.close();
-
+    
+    //DERBY-2973
+    //alter table modify column should not give an error
+    s.execute("CREATE TABLE DERBY_2973 (V VARCHAR(40))");
+    s.execute("CREATE INDEX DERBY_2973_I1 ON DERBY_2973 (V)");
+    s.execute("ALTER TABLE DERBY_2973 ALTER V SET DATA TYPE VARCHAR(4096)");
+    s.execute("INSERT INTO DERBY_2973 VALUES('hello')");
+    s.close();
+ 
 }
 
 private void setUpTable(Statement s) throws SQLException {



Mime
View raw message