You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ma...@apache.org on 2007/07/27 18:43:43 UTC

svn commit: r560307 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/

Author: mamta
Date: Fri Jul 27 09:43:40 2007
New Revision: 560307

URL: http://svn.apache.org/viewvc?view=rev&rev=560307
Log:
Merging changes(Revision: 560289) from main into 10.3 codeline for DERBY-2973. The commit comments from main were as follows.

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/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java?view=diff&rev=560307&r1=560306&r2=560307
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ModifyColumnNode.java Fri Jul 27 09:43:40 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;
 
@@ -212,8 +213,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 (getDataTypeServices() != null) {
+			if (getDataTypeServices().getTypeId().isStringTypeId()) {
+				this.getDataTypeServices().setCollationType(cd.getType().getCollationType());
+				this.getDataTypeServices().setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+			
+			}
+		}
+    }
 	/**
 	 * Get the action associated with this node.
 	 *

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

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?view=diff&rev=560307&r1=560306&r2=560307
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java Fri Jul 27 09:43:40 2007
@@ -985,7 +985,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 {