You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ma...@apache.org on 2007/07/31 22:53:06 UTC

svn commit: r561518 - in /db/derby/code/branches/10.3/java/engine/org/apache/derby: iapi/types/DataTypeDescriptor.java impl/sql/compile/LikeEscapeOperatorNode.java

Author: mamta
Date: Tue Jul 31 13:53:05 2007
New Revision: 561518

URL: http://svn.apache.org/viewvc?view=rev&rev=561518
Log:
Migrating changes for DERBY-2793 from main(561494, 561514) into 10.3 codeline. The commit comments for main were as follows

Collation comparison algorithm for LIKE is incorrect. Rather than duplicating the code in 2 places, I am including a genric method in DataTypeDescriptor which can be called whenever needed.


Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/LikeEscapeOperatorNode.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java?view=diff&rev=561518&r1=561517&r2=561518
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java Tue Jul 31 13:53:05 2007
@@ -38,7 +38,7 @@
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.sql.conn.ConnectionUtil;
 
-/**
+/** 
  * This is an implementation of DataTypeDescriptor from the generic language
  * datatype module interface.
  *
@@ -1046,17 +1046,7 @@
     		//If both the types are string types, then we need to make sure
     		//they have the same collation set on them
     		if (compareWithTypeID.isStringTypeId() && typeId.isStringTypeId()) {
-    			//both the operands can not have the collation derivation of 
-    			//NONE. This is because in that case, we do not know what kind 
-    			//of collation to use for comparison.
-    			if (getCollationDerivation() == compareWithDTD.getCollationDerivation() &&
-    					getCollationDerivation() == StringDataValue.COLLATION_DERIVATION_NONE)
-    				return false;
-    			if (getCollationDerivation() == compareWithDTD.getCollationDerivation() &&
-    					getCollationType() == compareWithDTD.getCollationType())
-    				return true;//collation matches
-    			else
-    				return false;//collation does not match
+    			return compareCollationInfo(compareWithDTD);    			
     		} else
     			return false;//can't be compared			
 		}
@@ -1121,7 +1111,39 @@
 		return false;
 	}
 	
-		
+	/**
+	 * Compare the collation info on this DTD with the passed DTD. The rules
+	 * are as follows
+	 * 1)If both the DTDs have collation derivation of NONE, then they can't be
+	 * compared and we return false.
+	 * 2)If both the DTDs have same collation derivation (which in Derby's case
+	 * at this point will mean collation derivation of IMPLICIT), then check
+	 * the collation types. If they match, then return true. If they do not 
+	 * match, then they can't be compared and hence return false.
+	 * 
+	 * In future, when we do support collation derivation of EXPLICIT, we will
+	 * need to change this method so that we follow the correct SQL standard
+	 * rules about what should happen if one collation derivation is EXPLICIT
+	 * and other is NONE/IMPLICIT.
+	 * 
+	 * @param compareWithDTD compare this DTD's collation info
+	 *  
+	 * @return value depends on the algorithm above.
+	 */
+	public boolean compareCollationInfo(DataTypeDescriptor compareWithDTD){
+		//both the operands can not have the collation derivation of
+		//NONE. This is because in that case, we do not know what kind
+		//of collation to use for comparison.
+		if (getCollationDerivation() == compareWithDTD.getCollationDerivation() &&
+				getCollationDerivation() == StringDataValue.COLLATION_DERIVATION_NONE)
+			return false;
+		if (getCollationDerivation() == compareWithDTD.getCollationDerivation() &&
+				getCollationType() == compareWithDTD.getCollationType())
+			return true;//collation matches
+		else
+			return false;//collation does not match
+		}
+		 				
 	/**
 	 * Converts this data type descriptor (including length/precision)
 	 * to a string. E.g.

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?view=diff&rev=561518&r1=561517&r2=561518
==============================================================================
--- 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 Jul 31 13:53:05 2007
@@ -53,7 +53,7 @@
 
 import java.util.Vector;
 
-
+  
 /**
     This node represents a like comparison operator (no escape)
 
@@ -339,11 +339,8 @@
 
         // The left and the pattern of the LIKE must be same collation type
         // and derivation.
-        if (receiver.getTypeServices().getCollationType() !=
-                leftOperand.getTypeServices().getCollationType() ||
-                receiver.getTypeServices().getCollationDerivation() !=
-                	leftOperand.getTypeServices().getCollationDerivation()
-                )
+        if (!receiver.getTypeServices().compareCollationInfo(
+        		leftOperand.getTypeServices()))
         {
             // throw error.
             throw StandardException.newException(