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/20 09:40:41 UTC

svn commit: r557910 - 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 20 00:40:39 2007
New Revision: 557910

URL: http://svn.apache.org/viewvc?view=rev&rev=557910
Log:
Migrating changes 557886 for DERBY-2955 from main into 10.3 codeline. The commit comments in main were as follows

We used to set the collation type of character string columns in the generate phase rather than the bind phase of create table. But this will cause problem with following query
       CREATE TABLE STAFF9 (EMPNAME CHAR(20),
       CONSTRAINT STAFF9_EMPNAME CHECK (EMPNAME NOT LIKE 'T%'))
For the query above, when run in a territory based db, we need to have the correct collation set in bind phase of create table so that when LIKE is handled in LikeEscapeOperatorNode, we have the correct collation set for EMPNAME otherwise it will throw an exception for 'T%' having collation of territory based and EMPNAME having the default collation of UCS_BASIC. The change in this commit will ensure that character string columns get their collation set early on in the bind phase so when the bind code for LIKE kicks in, we are all set with correct collation information.



Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.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/CreateTableNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java?view=diff&rev=557910&r1=557909&r2=557910
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java Fri Jul 20 00:40:39 2007
@@ -348,6 +348,24 @@
 				column.init(rc.getName(), null, rc.getType(), null);
 				tableElementList.addTableElement(column);
 			}
+		} else {
+			//Set the collation type and collation derivation of all the 
+			//character type columns. Their collation type will be same as the 
+			//collation of the schema they belong to. Their collation 
+			//derivation will be "implicit". 
+			//Earlier we did this in makeConstantAction but that is little too 
+			//late (DERBY-2955)
+			//eg 
+			//CREATE TABLE STAFF9 (EMPNAME CHAR(20),
+			//  CONSTRAINT STAFF9_EMPNAME CHECK (EMPNAME NOT LIKE 'T%'))
+			//For the query above, when run in a territory based db, we need 
+			//to have the correct collation set in bind phase of create table 
+			//so that when LIKE is handled in LikeEscapeOperatorNode, we have 
+			//the correct collation set for EMPNAME otherwise it will throw an 
+			//exception for 'T%' having collation of territory based and 
+			//EMPNAME having the default collation of UCS_BASIC
+			tableElementList.setCollationTypesOnCharacterStringColumns(
+					getSchemaDescriptor());
 		}
 
 		tableElementList.validate(this, dataDictionary, (TableDescriptor) null);
@@ -464,18 +482,6 @@
 
 		SchemaDescriptor sd = getSchemaDescriptor();
 		
-		//Set the collation type and collation derivation of all the character
-		//type columns. Their collation type will be same as the collation of
-		//the schema they belong to. Theie collation derivation will be 
-		//"implicit".
-        for (int i = 0; i < colInfos.length; i++) {
-        	DataTypeDescriptor dts = colInfos[i].dataType;
-        	if (dts.getTypeId().isStringTypeId()) {
-        		dts.setCollationType(sd.getCollationType());
-        		dts.setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
-        	}
-        }
-
 		if (numConstraints > 0)
 		{
 			conActions =

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=557910&r1=557909&r2=557910
==============================================================================
--- 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 20 00:40:39 2007
@@ -29,6 +29,7 @@
 import org.apache.derby.iapi.sql.compile.C_NodeTypes;
 
 import org.apache.derby.iapi.types.DataTypeDescriptor;
+import org.apache.derby.iapi.types.StringDataValue;
 
 import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
@@ -104,6 +105,29 @@
 		else
 		{
 			return "";
+		}
+	}
+
+	/**
+	 * Use the passed schema descriptor's collation type to set the collation
+	 * of the character string types in create table node
+	 * @param sd
+	 */
+	void setCollationTypesOnCharacterStringColumns(SchemaDescriptor sd) {
+		int			size = size();
+		int collationType = sd.getCollationType();
+		for (int index = 0; index < size; index++)
+		{
+			TableElementNode tableElement = (TableElementNode) elementAt(index);
+
+			if (tableElement instanceof ColumnDefinitionNode)
+			{
+				ColumnDefinitionNode cdn = (ColumnDefinitionNode) elementAt(index);
+				if (cdn.getDataTypeServices().getTypeId().isStringTypeId()) {
+					cdn.getDataTypeServices().setCollationType(collationType);
+					cdn.getDataTypeServices().setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+				}
+			}
 		}
 	}
 

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=557910&r1=557909&r2=557910
==============================================================================
--- 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 20 00:40:39 2007
@@ -947,7 +947,7 @@
     assertStatementError("42ZA3", s, "CREATE TABLE T AS SELECT TABLENAME " +
     		" FROM SYS.SYSTABLES WITH NO DATA");
     //But following will work because there is no character string type
-    //involved.
+    //involved. (DERBY-2959)
     s.executeUpdate("CREATE TABLE T AS SELECT COLUMNNUMBER FROM " +
     		" SYS.SYSCOLUMNS WITH NO DATA");
     
@@ -960,7 +960,13 @@
     ps = conn.prepareStatement("insert into assoc values (?, 'hello')");
     ps.setString(1, new Integer(10).toString());
     ps.executeUpdate();     
-
+    
+    //DERBY-2955
+    //We should set the collation type in the bind phase of create table rather
+    //than in code generation phase. Otherwise, following sql will give 
+    //incorrect exception about collation mismatch for the LIKE clause
+    s.execute("CREATE TABLE DERBY_2955 (EMPNAME CHAR(20), CONSTRAINT " +
+    		" STAFF9_EMPNAME CHECK (EMPNAME NOT LIKE 'T%'))");
 }
 
 private void setUpTable(Statement s) throws SQLException {