db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r570546 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Tue, 28 Aug 2007 19:52:07 GMT
Author: kmarsden
Date: Tue Aug 28 12:52:06 2007
New Revision: 570546

URL: http://svn.apache.org/viewvc?rev=570546&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.

This change changes implicit casts in SimpleStringOperatorNode, ConcatenationOperatorNode,
and TernaryOperatorNode to use the current schema collation when doing an implicit cast. Since
the SQL Spec had no specific rules for implicit casts, I matched the explicit cast behavior
described in 6.1.2 (10).




Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.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/ConcatenationOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java?rev=570546&r1=570545&r2=570546&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConcatenationOperatorNode.java
Tue Aug 28 12:52:06 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/trunk/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java?rev=570546&r1=570545&r2=570546&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java
Tue Aug 28 12:52:06 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/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java?rev=570546&r1=570545&r2=570546&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
Tue Aug 28 12:52:06 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/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java?rev=570546&r1=570545&r2=570546&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java
Tue Aug 28 12:52:06 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/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?rev=570546&r1=570545&r2=570546&view=diff
==============================================================================
--- 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
Tue Aug 28 12:52:06 2007
@@ -1057,8 +1057,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