db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r544180 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Date Mon, 04 Jun 2007 16:47:15 GMT
Author: mamta
Date: Mon Jun  4 09:47:05 2007
New Revision: 544180

URL: http://svn.apache.org/viewvc?view=rev&rev=544180
Log:
DERBY-2724
Commiting changes so that the resultant character string from CURRENT ISOLATION, CURRENT_USER,
SESSION_USER, SYSTEM_USER, CURRENT SCHEMA 
and CURRENT SQLID will take the collation type of UCS_BASIC.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.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/SpecialFunctionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java?view=diff&rev=544180&r1=544179&r2=544180
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SpecialFunctionNode.java
Mon Jun  4 09:47:05 2007
@@ -24,6 +24,7 @@
 import org.apache.derby.iapi.sql.compile.CompilerContext;
 
 import org.apache.derby.iapi.types.DataTypeDescriptor;
+import org.apache.derby.iapi.types.StringDataValue;
 
 import org.apache.derby.iapi.services.compiler.MethodBuilder;
 import org.apache.derby.iapi.services.compiler.LocalField;
@@ -41,7 +42,6 @@
 import org.apache.derby.iapi.services.classfile.VMOpcode;
 import org.apache.derby.iapi.sql.compile.C_NodeTypes;
 
-
 import java.sql.Types;
 
 import java.util.Vector;
@@ -134,6 +134,13 @@
 			methodName = "getAuthorizationId";
 			methodType = "java.lang.String";
 			dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, false, 128);
+			//SQL spec Section 6.4 Syntax Rule 4 says that the collation type 
+			//of these functions will be the collation of character set 
+			//SQL_IDENTIFIER. In Derby's case, that will mean, the collation of
+			//these functions will be UCS_BASIC. The collation derivation will 
+			//be implicit. 
+			dtd.setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+			dtd.setCollationType(StringDataValue.COLLATION_TYPE_UCS_BASIC);
 			break;
 
 		case C_NodeTypes.CURRENT_SCHEMA_NODE:
@@ -141,6 +148,12 @@
 			methodName = "getCurrentSchemaName";
 			methodType = "java.lang.String";
 			dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, false, 128);
+			//This is a Derby specific function but it's collation type will
+			//be based on the same rules as for SESSION_USER/CURRENT_USER etc. 
+			//ie there collation type will be UCS_BASIC. The collation 
+			//derivation will be implicit. 
+			dtd.setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+			dtd.setCollationType(StringDataValue.COLLATION_TYPE_UCS_BASIC);
 			break;
 
 		case C_NodeTypes.IDENTITY_VAL_NODE:
@@ -155,6 +168,12 @@
 			methodName = "getCurrentIsolationLevelStr";
 			methodType = "java.lang.String";
 			dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.CHAR, 2);
+			//This is a Derby specific function but it's collation type will
+			//be based on the same rules as for SESSION_USER/CURRENT_USER etc. 
+			//ie there collation type will be UCS_BASIC. The collation 
+			//derivation will be implicit. 
+			dtd.setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+			dtd.setCollationType(StringDataValue.COLLATION_TYPE_UCS_BASIC);
 			break;
 		default:
 			if (SanityManager.DEBUG)

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=544180&r1=544179&r2=544180
==============================================================================
--- 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 Jun  4 09:47:05 2007
@@ -203,6 +203,11 @@
 			" 'SYSCOLUMNS'",
       		new String[][] {{"SYSCOLUMNS"} });   
 
+      //Test USER/CURRENT_USER/SESSION_USER
+      checkLangBasedQuery(s, "SELECT count(*) FROM CUSTOMER WHERE "+ 
+      		"CURRENT_USER = 'APP'",
+      		new String[][] {{"7"}});   
+      
       //Do some testing with MAX/MIN operators
       checkLangBasedQuery(s, "SELECT MAX(NAME) maxName FROM CUSTOMER ORDER BY maxName ",
       		new String[][] {{"\u017Bebra"}});   
@@ -613,6 +618,40 @@
     		" CHAR(TABLENAME)= (CAST (TABLENAME AS CHAR(12))) AND " + 
 			" VARCHAR(TABLENAME) = 'SYSCOLUMNS'",
     		new String[][] {{"SYSCOLUMNS"} });  
+
+    //Test USER/CURRENT_USER/SESSION_USER/CURRENT SCHMEA/ CURRENT ISOLATION
+    //following will fail because we are trying to compare UCS_BASIC 
+    //(CURRENT_USER) with territory based ("APP" taking it's collation from
+    //compilation schema which is user schema at this time). 
+    assertStatementError("42818", s, "SELECT count(*) FROM CUSTOMER WHERE "+
+    		"CURRENT_USER = 'APP'");  
+    //The problem above can be fixed by CASTing CURRENT_USER so that the 
+    //collation type will be picked up from compilation schema which is user
+    //schema at this point.
+    checkLangBasedQuery(s, "SELECT count(*) FROM CUSTOMER WHERE "+ 
+    		"CAST(CURRENT_USER AS CHAR(12)) = 'APP'",
+    		new String[][] {{"7"}});   
+    //following comparison will not cause compilation error because both the
+    //operands around = have collation type of UCS_BASIC
+    checkLangBasedQuery(s, "SELECT count(*) FROM CUSTOMER WHERE "+ 
+    		"SESSION_USER = USER", new String[][] {{"7"}});
+    //following will fail because we are trying to compare UCS_BASIC 
+    //(CURRENT ISOLATION) with territory based ("CS" taking it's collation from
+    //compilation schema which is user schema at this time). 
+    assertStatementError("42818", s, "SELECT count(*) FROM CUSTOMER WHERE "+
+	"CURRENT ISOLATION = 'CS'");  
+    //Following will not give compilation error because both sides in = have 
+    //the same collation type 
+    checkLangBasedQuery(s, "SELECT count(*) FROM CUSTOMER WHERE "+ 
+    		"CAST(CURRENT ISOLATION AS CHAR(12)) = 'CS'",
+    		new String[][] {{"7"}});   
+    //Following will not cause compilation error because both the operands
+    //around the = have collation type of UCS_BASIC. We are in the SYS
+    //schema and hence character string constant 'APP' has picked the collation
+    //type of SYS schema which is UCS_BASIC
+    s.executeUpdate("set schema SYS");
+    checkLangBasedQuery(s, "SELECT count(*) FROM APP.CUSTOMER WHERE "+ 
+    		"CURRENT SCHEMA = 'SYS'", new String[][] {{"7"}});   
     
     s.executeUpdate("set schema APP");
     if (XML.classpathMeetsXMLReqs()) {
@@ -624,7 +663,6 @@
     			" CAST(TABLENAME AS CHAR(10))",
         		null);
     }
-
 
     //Start of parameter testing
     //Start with simple ? param in a string comparison



Mime
View raw message