db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r552531 - in /db/derby/code/trunk/java: engine/org/apache/derby/catalog/types/ engine/org/apache/derby/iapi/types/ engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testi...
Date Mon, 02 Jul 2007 16:23:04 GMT
Author: mamta
Date: Mon Jul  2 09:23:02 2007
New Revision: 552531

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

Derby currently requires all the character columns in a table to have the same collation as
the collation of the schema in
which the table is getting defined. In order to implement this behavior, CreateTableNods's
bind method will check the
collation of it's character columns against the schema's collation and if there is a mismatch,
an exception will be thrown.

In addition, this patch does minor cleanup. The string constants for the 2 collation types
in Derby were declared in both
StringDataValue.java and Property.java I have removed it from StringDataValue so we don't
have duplicate constants.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.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/catalog/types/TypeDescriptorImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java?view=diff&rev=552531&r1=552530&r2=552531
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/TypeDescriptorImpl.java
Mon Jul  2 09:23:02 2007
@@ -28,6 +28,7 @@
 
 import org.apache.derby.iapi.types.DataTypeDescriptor;
 import org.apache.derby.iapi.types.StringDataValue;
+import org.apache.derby.iapi.reference.Property;
 
 import java.io.ObjectOutput;
 import java.io.ObjectInput;
@@ -426,8 +427,8 @@
     {
         return(
             collationType == StringDataValue.COLLATION_TYPE_UCS_BASIC ? 
-                StringDataValue.COLLATION_TYPE_UCS_BASIC_STRING : 
-                StringDataValue.COLLATION_TYPE_TERRITORY_BASED_STRING);
+                Property.UCS_BASIC_COLLATION : 
+                Property.TERRITORY_BASED_COLLATION);
     }
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java?view=diff&rev=552531&r1=552530&r2=552531
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/StringDataValue.java Mon Jul
 2 09:23:02 2007
@@ -65,11 +65,6 @@
 	/** @see StringDataValue#COLLATION_TYPE_UCS_BASIC */
 	public	static final int COLLATION_TYPE_TERRITORY_BASED = 1;
 
-    public  static final String COLLATION_TYPE_UCS_BASIC_STRING = 
-        "USC_BASIC";
-    public  static final String COLLATION_TYPE_TERRITORY_BASED_STRING = 
-        "TERRITORY_BASED";
-
 	/**
 	 * The SQL concatenation '||' operator.
 	 *

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=552531&r1=552530&r2=552531
==============================================================================
--- 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
Mon Jul  2 09:23:02 2007
@@ -290,6 +290,9 @@
 				qeRCL.copyResultColumnNames(resultColumns);
 			}
 			
+			SchemaDescriptor sd = getSchemaDescriptor();
+			int schemaCollationType = sd.getCollationType();
+	    
 			/* Create table element list from columns in query expression */
 			tableElementList = new TableElementList();
 			
@@ -314,6 +317,30 @@
 							SQLState.LANG_INVALID_COLUMN_TYPE_CREATE_TABLE,
 							dtd.getFullSQLTypeName(),
 							rc.getName());
+				}
+				//DERBY-2879  CREATE TABLE AS <subquery> does not maintain the 
+				//collation for character types. 
+				//eg for a territory based collation database
+				//create table t as select tablename from sys.systables with no data;
+				//Derby at this point does not support for a table's character 
+				//columns to have a collation different from it's schema's
+				//collation. Which means that in a territory based database, 
+				//the query above will cause table t's character columns to
+				//have collation of UCS_BASIC but the containing schema of t
+				//has collation of territory based. This is not supported and
+				//hence we will throw an exception below for the query above in
+				//a territory based database. 
+				if (dtd.getCollationType() != schemaCollationType)
+				{
+					String schemaCollationName =
+			        	(schemaCollationType == 
+			        		StringDataValue.COLLATION_TYPE_UCS_BASIC ? 
+			                Property.UCS_BASIC_COLLATION : 
+			                Property.TERRITORY_BASED_COLLATION);
+					throw StandardException.newException(
+							SQLState.LANG_CAN_NOT_CREATE_TABLE,
+							dtd.getCollationName(),
+							schemaCollationName);
 				}
 
 				ColumnDefinitionNode column = new ColumnDefinitionNode();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?view=diff&rev=552531&r1=552530&r2=552531
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Mon Jul  2 09:23:02
2007
@@ -2477,6 +2477,13 @@
                 <arg>value</arg>
             </msg>
 
+            <msg>
+                <name>42ZA3</name>
+                <text>The table will have collation type {0} which is different than
the collation of the schema {1} hence this operation is not supported .</text>
+                <arg>type</arg>
+                <arg>type</arg>
+            </msg>
+
         </family>
 
 

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?view=diff&rev=552531&r1=552530&r2=552531
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Mon Jul  2 09:23:02 2007
@@ -1047,6 +1047,7 @@
     String LANG_QUERY_TOO_COMPLEX                                     = "42ZA0";
     String LANG_INVALID_SQL_IN_BATCH                                  = "42ZA1";
     String LANG_LIKE_COLLATION_MISMATCH                               = "42ZA2";
+    String LANG_CAN_NOT_CREATE_TABLE                               = "42ZA3";
 
 	//following 3 matches the DB2 sql states
 	String LANG_DECLARED_GLOBAL_TEMP_TABLE_ONLY_IN_SESSION_SCHEMA = "428EK";

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=552531&r1=552530&r2=552531
==============================================================================
--- 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
Mon Jul  2 09:23:02 2007
@@ -912,6 +912,16 @@
     rs = s.executeQuery("SELECT COUNT(*) FROM APP.CUSTOMER ");
     JDBC.assertFullResultSet(rs,new String[][] {{"8"}});
     //End of parameter testing
+    
+    //The user table has to adhere to the collation type of the schema in which
+    //it resides. If the table creation breaks that rule, then an exception 
+    //will be thrown. DERBY-2879
+    s.executeUpdate("set schema APP");
+    //following fails as expected because otherwise character types in T will
+    //have collation type of UCS_BASIC but the APP schema has collation of
+    //territory based
+    assertStatementError("42ZA3", s, "CREATE TABLE T AS SELECT TABLENAME " +
+    		" FROM SYS.SYSTABLES WITH NO DATA");
 }
 
 private void setUpTable(Statement s) throws SQLException {



Mime
View raw message