db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r570562 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Tue, 28 Aug 2007 20:26:16 GMT
Author: kmarsden
Date: Tue Aug 28 13:26:16 2007
New Revision: 570562

URL: http://svn.apache.org/viewvc?rev=570562&view=rev
Log:
DERBY-2910  SimpleStringOperatorNode in it's bindExpression method generates a character string
CAST if required but does not set the correct collation.

port change 570546 from trunk
 

Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.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/ConcatenationOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java?rev=570562&r1=570561&r2=570562&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java
Tue Aug 28 13:26:16 2007
@@ -199,26 +199,37 @@
 		TypeCompiler tc = leftOperand.getTypeCompiler();
 		if (!(leftOperand.getTypeId().isStringTypeId() || leftOperand
 				.getTypeId().isBitTypeId())) {
+			DataTypeDescriptor dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+					Types.VARCHAR, true, tc
+					.getCastToCharWidth(leftOperand							.getTypeServices()));	
+			// DERBY-2910 - Match current schema collation for implicit cast as we do for
+			// explicit casts per SQL Spec 6.12 (10)									
+			dtd.setCollationType(getSchemaDescriptor(null).getCollationType());
+			dtd.setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+
 			leftOperand = (ValueNode) getNodeFactory().getNode(
 					C_NodeTypes.CAST_NODE,
 					leftOperand,
-					DataTypeDescriptor.getBuiltInDataTypeDescriptor(
-							Types.VARCHAR, true, tc
-									.getCastToCharWidth(leftOperand
-											.getTypeServices())),
+					dtd,
 					getContextManager());
 			((CastNode) leftOperand).bindCastNodeOnly();
 		}
 		tc = rightOperand.getTypeCompiler();
 		if (!(rightOperand.getTypeId().isStringTypeId() || rightOperand
 				.getTypeId().isBitTypeId())) {
+			DataTypeDescriptor dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(
+					Types.VARCHAR, true, tc
+							.getCastToCharWidth(rightOperand
+									.getTypeServices()));
+			// DERBY-2910 - Match current schema collation for implicit cast as we do for
+			// explicit casts per SQL Spec 6.12 (10)					
+			dtd.setCollationType(getSchemaDescriptor(null).getCollationType());
+			dtd.setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+
 			rightOperand = (ValueNode) getNodeFactory().getNode(
 					C_NodeTypes.CAST_NODE,
 					rightOperand,
-					DataTypeDescriptor.getBuiltInDataTypeDescriptor(
-							Types.VARCHAR, true, tc
-									.getCastToCharWidth(rightOperand
-											.getTypeServices())),
+					dtd,
 					getContextManager());
 			((CastNode) rightOperand).bindCastNodeOnly();
 		}

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java?rev=570562&r1=570561&r2=570562&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java
Tue Aug 28 13:26:16 2007
@@ -454,25 +454,7 @@
         return this;
     }
 
-    private ValueNode castArgToNationalString(
-    ValueNode       vn, 
-    TypeCompiler    vnTC, 
-    TypeId          vnTypeId)
-        throws StandardException
-    {
-        ValueNode newNode =  (ValueNode)
-            getNodeFactory().getNode(
-                C_NodeTypes.CAST_NODE,
-                vn, 
-                new DataTypeDescriptor(vnTypeId, 
-                true,
-                vnTC.getCastToCharWidth(vn.getTypeServices())), 
-                getContextManager());
-
-        ((CastNode) newNode).bindCastNodeOnly();
-
-        return newNode;
-    }
+  
 
     private void finishBindExpr()
     throws StandardException

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java?rev=570562&r1=570561&r2=570562&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
Tue Aug 28 13:26:16 2007
@@ -102,16 +102,22 @@
 				}
 
 				default:
+					DataTypeDescriptor dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR,
true, 
+							  operand.getTypeCompiler().
+								getCastToCharWidth(
+									operand.getTypeServices()));
+				// DERBY-2910 - Match current schema collation for implicit cast as we do for
+				// explicit casts per SQL Spec 6.12 (10)					
+				dtd.setCollationType(getSchemaDescriptor(null).getCollationType());
+				dtd.setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
+			
 					operand =  (ValueNode)
 						getNodeFactory().getNode(
 							C_NodeTypes.CAST_NODE,
 							operand,
-							DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, true, 
-										  operand.getTypeCompiler().
-											getCastToCharWidth(
-												operand.getTypeServices())),
+							dtd,
 							getContextManager());
-					((CastNode) operand).bindCastNodeOnly();
+				((CastNode) operand).bindCastNodeOnly();
 					operandType = operand.getTypeId();
 		}
 

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java?rev=570562&r1=570561&r2=570562&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java
Tue Aug 28 13:26:16 2007
@@ -734,13 +734,18 @@
 		TypeCompiler vnTC = vn.getTypeCompiler();
 		if (! vn.getTypeId().isStringTypeId())
 		{
+			DataTypeDescriptor dtd = DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR,
true,
+	                vnTC.getCastToCharWidth(
+		                    vn.getTypeServices()));
+			// DERBY-2910 - Match current schema collation for implicit cast as we do for
+			// explicit casts per SQL Spec 6.12 (10)							                    
+			dtd.setCollationType(getSchemaDescriptor(null).getCollationType());
+			dtd.setCollationDerivation(StringDataValue.COLLATION_DERIVATION_IMPLICIT);
 			ValueNode newNode = (ValueNode)
 						getNodeFactory().getNode(
 							C_NodeTypes.CAST_NODE,
 							vn,
-							DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, true,
-							                vnTC.getCastToCharWidth(
-							                    vn.getTypeServices())),
+							dtd,
 							getContextManager());
 			((CastNode) newNode).bindCastNodeOnly();
 			return newNode;

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?rev=570562&r1=570561&r2=570562&view=diff
==============================================================================
--- 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
Tue Aug 28 13:26:16 2007
@@ -1004,8 +1004,23 @@
         		" FROM DERBY_2961 ORDER BY 1",
         		new String[][] {{"1",null}});
     }
+    
+    //DERBY-2910 
+    // Test proper collation is set for  implicit cast with 
+    // UPPER(CURRENT_DATE) and concatonation.
+    
+    s.executeUpdate("create table a (vc varchar(30))");
+    s.executeUpdate("insert into a values(CURRENT_DATE)");
+    rs = s.executeQuery("select vc from a where vc = CURRENT_DATE");
+    assertEquals(1,JDBC.assertDrainResults(rs));
+    rs = s.executeQuery("select vc from a where vc = UPPER(CURRENT_DATE)");
+    JDBC.assertDrainResults(rs,1);
+    rs = s.executeQuery("select vc from a where vc =  '' || CURRENT_DATE");
+    JDBC.assertDrainResults(rs,1);
+    rs = s.executeQuery("select vc from a where '' || CURRENT_DATE = vc");
+    assertEquals(1,JDBC.assertDrainResults(rs));
+    assertStatementError("42818",s,"select TABLENAME FROM SYS.SYSTABLES WHERE UPPER(CURRENT_DATE)
= TABLENAME");
     s.close();
- 
 }
 
 private void setUpTable(Statement s) throws SQLException {



Mime
View raw message