db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r557886 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/CreateTableNode.java engine/org/apache/derby/impl/sql/compile/TableElementList.java testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Date Fri, 20 Jul 2007 06:36:21 GMT
Author: mamta
Date: Thu Jul 19 23:36:20 2007
New Revision: 557886

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

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/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.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/CreateTableNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java?view=diff&rev=557886&r1=557885&r2=557886
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java
Thu Jul 19 23:36:20 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/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=557886&r1=557885&r2=557886
==============================================================================
--- 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
Thu Jul 19 23:36:20 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.getType().getTypeId().isStringTypeId()) {
+					cdn.getType().setCollationType(collationType);
+					cdn.getType().setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+				}
+			}
 		}
 	}
 

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=557886&r1=557885&r2=557886
==============================================================================
--- 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
Thu Jul 19 23:36:20 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 {



Mime
View raw message