db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r535738 - 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/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Mon, 07 May 2007 04:30:59 GMT
Author: mamta
Date: Sun May  6 21:30:51 2007
New Revision: 535738

URL: http://svn.apache.org/viewvc?view=rev&rev=535738
Log:
DERBY-2334 : Commiting patch(DERBY2335_correct_collation_for_constants_persistent_column_v1_diff.txt)
attached to DERBY-2334 which does 
couple of things 
1)It puts the correct collation type for character constants and for persistent character
columns. For character constants, the collation type will be the collation type of the schema
in which the query is getting compiled. This happens in 
CharConstantNode.bindExpression. The setting of collation type for the persistent columns
happens in a constructor for the DataTypeDescriptor. This could be found in the patch which
has changes for DataTypeDescriptor and TypeDescriptorImpl. 
2)Collation related methods (like and stringCompare) on collation sensitive DVDs has been
copied into WorkHorseForCollatorDatatypes. These methods get called by CollatorSQLxxx classes.

3)The final change went into CollationTest. The change now allows this test to test collations
for Norway, English and Polish. 
I will add more tests for these changes in a subsequent patch. 


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/CollatorSQLChar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CharConstantNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstantNode.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=535738&r1=535737&r2=535738
==============================================================================
--- 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
Sun May  6 21:30:51 2007
@@ -133,6 +133,25 @@
 		this.maximumWidth = maximumWidth;
 	}
 
+	public TypeDescriptorImpl(
+			TypeDescriptorImpl source, 
+			int precision,
+			int scale,
+			boolean isNullable,
+			int maximumWidth,
+			int collationType,
+			int collationDerivation)
+		{
+			this.typeId = source.typeId;
+			this.precision = precision;
+			this.scale = scale;
+			this.isNullable = isNullable;
+			this.maximumWidth = maximumWidth;
+			this.collationType = collationType;
+			this.collationDerivation = collationDerivation;
+		}
+	
+	
 	/**
 	 * Constructor for internal uses only
 	 *

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java?view=diff&rev=535738&r1=535737&r2=535738
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java Sun May
 6 21:30:51 2007
@@ -140,6 +140,13 @@
 			return s;
 		}
 	}
+	
+	/** @see SQLChar.stringCompare(SQLChar, SQLChar) */
+	 protected int stringCompare(SQLChar char1, SQLChar char2)
+	 throws StandardException
+	 {
+		 return holderForCollationSensitiveInfo.stringCompare(char2);
+	 }
 
 	/**
 	 * This method implements the like function for char (with no escape value).
@@ -158,5 +165,21 @@
 								throws StandardException
 	{
 		return(holderForCollationSensitiveInfo.like(pattern));
+	}
+	
+	/**
+	 * This method implements the like function for char with an escape value.
+	 * 
+	 * @param pattern		The pattern to use
+	 * 								 
+	 * @return	A SQL boolean value telling whether the first operand is
+	 * like the second operand
+	 *
+	 * @exception StandardException		Thrown on error
+	 */
+	public BooleanDataValue like(DataValueDescriptor pattern,
+			DataValueDescriptor escape) throws StandardException
+	{
+		return(holderForCollationSensitiveInfo.like(pattern, escape));
 	}
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java?view=diff&rev=535738&r1=535737&r2=535738
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java Sun May
 6 21:30:51 2007
@@ -140,6 +140,13 @@
 			return s;
 		}
 	}
+	
+	/** @see SQLChar.stringCompare(SQLChar, SQLChar) */
+	 protected int stringCompare(SQLChar char1, SQLChar char2)
+	 throws StandardException
+	 {
+		 return holderForCollationSensitiveInfo.stringCompare(char2);
+	 }
 
 	/**
 	 * This method implements the like function for char (with no escape value).
@@ -158,5 +165,21 @@
 								throws StandardException
 	{
 		return(holderForCollationSensitiveInfo.like(pattern));
+	}
+	
+	/**
+	 * This method implements the like function for char with an escape value.
+	 * 
+	 * @param pattern		The pattern to use
+	 * 								 
+	 * @return	A SQL boolean value telling whether the first operand is
+	 * like the second operand
+	 *
+	 * @exception StandardException		Thrown on error
+	 */
+	public BooleanDataValue like(DataValueDescriptor pattern,
+			DataValueDescriptor escape) throws StandardException
+	{
+		return(holderForCollationSensitiveInfo.like(pattern, escape));
 	}
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java?view=diff&rev=535738&r1=535737&r2=535738
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
Sun May  6 21:30:51 2007
@@ -140,6 +140,13 @@
 			return s;
 		}
 	}
+	
+	/** @see SQLChar.stringCompare(SQLChar, SQLChar) */
+	 protected int stringCompare(SQLChar char1, SQLChar char2)
+	 throws StandardException
+	 {
+		 return holderForCollationSensitiveInfo.stringCompare(char2);
+	 }
 
 	/**
 	 * This method implements the like function for char (with no escape value).
@@ -158,5 +165,21 @@
 								throws StandardException
 	{
 		return(holderForCollationSensitiveInfo.like(pattern));
+	}
+	
+	/**
+	 * This method implements the like function for char with an escape value.
+	 * 
+	 * @param pattern		The pattern to use
+	 * 								 
+	 * @return	A SQL boolean value telling whether the first operand is
+	 * like the second operand
+	 *
+	 * @exception StandardException		Thrown on error
+	 */
+	public BooleanDataValue like(DataValueDescriptor pattern,
+			DataValueDescriptor escape) throws StandardException
+	{
+		return(holderForCollationSensitiveInfo.like(pattern, escape));
 	}
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java?view=diff&rev=535738&r1=535737&r2=535738
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java Sun
May  6 21:30:51 2007
@@ -140,6 +140,13 @@
 			return s;
 		}
 	}
+	
+	/** @see SQLChar.stringCompare(SQLChar, SQLChar) */
+	 protected int stringCompare(SQLChar char1, SQLChar char2)
+	 throws StandardException
+	 {
+		 return holderForCollationSensitiveInfo.stringCompare(char2);
+	 }
 
 	/**
 	 * This method implements the like function for char (with no escape value).
@@ -158,5 +165,21 @@
 								throws StandardException
 	{
 		return(holderForCollationSensitiveInfo.like(pattern));
+	}
+	
+	/**
+	 * This method implements the like function for char with an escape value.
+	 * 
+	 * @param pattern		The pattern to use
+	 * 								 
+	 * @return	A SQL boolean value telling whether the first operand is
+	 * like the second operand
+	 *
+	 * @exception StandardException		Thrown on error
+	 */
+	public BooleanDataValue like(DataValueDescriptor pattern,
+			DataValueDescriptor escape) throws StandardException
+	{
+		return(holderForCollationSensitiveInfo.like(pattern, escape));
 	}
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java?view=diff&rev=535738&r1=535737&r2=535738
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataTypeDescriptor.java Sun
May  6 21:30:51 2007
@@ -328,12 +328,20 @@
 	}
 	public DataTypeDescriptor(DataTypeDescriptor source, boolean isNullable)
 	{
+		//There might be other places, but one place this method gets called
+		//from is ResultColumn.init. When the ResultColumn(RC) is for a 
+		//ColumnDescriptor(CD), the RC's TypeDescriptorImpl(TDI) should get 
+		//all the attributes of CD's TDI. So, if the CD is for a user table's
+		//character type column, then this call by RC.init should have CD's 
+		//collation attributes copied into RC along with other attributes. 
 		this.typeId = source.typeId;
 		typeDescriptor = new TypeDescriptorImpl(source.typeDescriptor,
 												source.getPrecision(),
 												source.getScale(),
 												isNullable,
-												source.getMaximumWidth());
+												source.getMaximumWidth(),
+												source.getCollationType(),
+												source.getCollationDerivation());
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java?view=diff&rev=535738&r1=535737&r2=535738
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java
Sun May  6 21:30:51 2007
@@ -24,12 +24,14 @@
 import org.apache.derby.iapi.types.DataValueDescriptor;
 import org.apache.derby.iapi.types.BooleanDataValue;
 
+import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
 
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
 import java.text.CollationElementIterator;
+import java.text.CollationKey;
 import java.text.RuleBasedCollator;
 
 /**
@@ -69,6 +71,9 @@
 	 */
 	private int		countOfCollationElements;
 
+	// For null strings, cKey = null.
+	private CollationKey cKey; 
+
 	public WorkHorseForCollatorDatatypes(
 			RuleBasedCollator collatorForCharacterDatatypes,
 			SQLChar stringData)
@@ -76,7 +81,29 @@
 		this.collatorForCharacterDatatypes = collatorForCharacterDatatypes;
 		this.stringData = stringData;
 	}
+	
+	/** @see SQLChar.stringCompare(SQLChar, SQLChar) */
+	protected int stringCompare(SQLChar str2)
+	throws StandardException
+	{
+		CollationKey ckey1 = stringData.getCollationKey();
+		CollationKey ckey2 = str2.getCollationKey();
+		
+		/*
+		** By convention, nulls sort High, and null == null
+		*/
+		if (ckey1 == null || ckey2 == null)
+		{
+			if (ckey1 != null)	// str2 == null
+				return -1;
+			if (ckey2 != null)	// this == null
+				return 1;
+			return 0;			// both == null
+		}
 
+		return ckey1.compareTo(ckey2);
+	}
+	
 	/**
 	 * This method implements the like function for char (with no escape value).
 	 * The difference in this method and the same method in SQLChar is that 
@@ -110,6 +137,60 @@
 		return SQLBoolean.truthValue(stringData,
 									 pattern,
 									 likeResult);
+	}
+	
+	/**
+	 * This method implements the like function for char with an escape value.
+	 * 
+	 * @param pattern		The pattern to use
+	 * 
+	 * @return	A SQL boolean value telling whether the first operand is
+	 * 			like the second operand
+	 *
+	 * @exception StandardException		Thrown on error
+	 */
+	public BooleanDataValue like(DataValueDescriptor pattern, 
+			DataValueDescriptor escape)	throws StandardException
+	{
+		Boolean likeResult;
+
+		if (SanityManager.DEBUG)
+			SanityManager.ASSERT(
+							 pattern instanceof CollationElementsInterface &&
+							 escape instanceof CollationElementsInterface,
+			"All three operands must be instances of CollationElementsInterface");
+		
+		// ANSI states a null escape yields 'unknown' results 
+		//
+		// This method is only called when we have an escape clause, so this 
+		// test is valid
+
+		if (escape.isNull())
+		{
+			throw StandardException.newException(SQLState.LANG_ESCAPE_IS_NULL);
+		}
+
+		CollationElementsInterface patternToCheck = (CollationElementsInterface) pattern;
+		CollationElementsInterface escapeCharacter = (CollationElementsInterface) escape;
+
+		if (escapeCharacter.getCollationElementsForString() != null && 
+				(escapeCharacter.getCountOfCollationElements() != 1))
+		{
+			throw StandardException.newException(SQLState.LANG_INVALID_ESCAPE_CHARACTER,
+					new String(escapeCharacter.toString()));
+		}
+		likeResult = Like.like(
+				getCollationElementsForString(),
+				getCountOfCollationElements(),
+				patternToCheck.getCollationElementsForString(),
+				patternToCheck.getCountOfCollationElements(),
+				escapeCharacter.getCollationElementsForString(),
+				escapeCharacter.getCountOfCollationElements(),
+				collatorForCharacterDatatypes);
+
+		return SQLBoolean.truthValue(stringData,
+								 pattern,
+								 likeResult);
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CharConstantNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CharConstantNode.java?view=diff&rev=535738&r1=535737&r2=535738
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CharConstantNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CharConstantNode.java
Sun May  6 21:30:51 2007
@@ -24,6 +24,8 @@
 import org.apache.derby.iapi.types.StringDataValue;
 import org.apache.derby.iapi.types.TypeId;
 
+import org.apache.derby.iapi.sql.conn.ConnectionUtil;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 
 import org.apache.derby.iapi.error.StandardException;
 
@@ -35,6 +37,7 @@
 import org.apache.derby.iapi.util.ReuseFactory;
 
 import java.sql.Types;
+import java.util.Vector;
 
 public final class CharConstantNode extends ConstantNode
 {
@@ -147,6 +150,24 @@
 	Object getConstantValueAsObject() throws StandardException 
 	{
 		return value.getString();
+	}
+	
+	public ValueNode bindExpression(
+			FromList fromList, SubqueryList subqueryList,
+			Vector	aggregateVector)
+	throws StandardException
+	{
+		try {
+			//The DTD for this character constant should get its collation type
+			//from the schema it is getting compiled in.
+			LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
+		    getTypeServices().setCollationType(lcc.getDefaultSchema().getCollationType());
+		}
+		catch( java.sql.SQLException sqle)
+		{
+			throw StandardException.plainWrapException( sqle);
+		}
+		return this;
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstantNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstantNode.java?view=diff&rev=535738&r1=535737&r2=535738
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstantNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstantNode.java Sun
May  6 21:30:51 2007
@@ -170,10 +170,15 @@
 	 * @param aggregateVector	The aggregate vector being built as we find AggregateNodes
 	 *
 	 * @return	The new top of the expression tree.
+	 *
+	 * @exception StandardException		Thrown on error. Although this class
+	 * doesn't throw this exception, it's subclasses do and hence this method
+	 * signature here needs to have throws StandardException 
 	 */
 	public ValueNode bindExpression(
 			FromList fromList, SubqueryList subqueryList,
 			Vector	aggregateVector)
+	throws StandardException
 	{
 		/*
 		** This has to be here for binding to work, but it doesn't

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=535738&r1=535737&r2=535738
==============================================================================
--- 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
Sun May  6 21:30:51 2007
@@ -71,7 +71,7 @@
    * Test order by with polish collation
    * @throws SQLException
    */
-public void xtestPolishCollation() throws SQLException {
+public void testPolishCollation() throws SQLException {
       DataSource ds = JDBCDataSource.getDataSourceLogical("poldb");
       JDBCDataSource.setBeanProperty(ds, "connectionAttributes", 
                   "create=true;territory=pl;collation=TERRITORY_BASED");
@@ -85,7 +85,7 @@
    * 
    * @throws SQLException
    */
-public void xtestNorwayCollation() throws SQLException {
+public void testNorwayCollation() throws SQLException {
       DataSource ds = JDBCDataSource.getDataSourceLogical("nordb");
       JDBCDataSource.setBeanProperty(ds, "connectionAttributes", 
                   "create=true;territory=no;collation=TERRITORY_BASED");
@@ -99,7 +99,7 @@
    * 
   * @throws SQLException
   */
-public void xtestEnglishCollation() throws SQLException {
+public void testEnglishCollation() throws SQLException {
       DataSource ds = JDBCDataSource.getDataSourceLogical("endb");
       JDBCDataSource.setBeanProperty(ds, "connectionAttributes", 
                   "create=true;territory=en;collation=TERRITORY_BASED");



Mime
View raw message