db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r541381 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
Date Thu, 24 May 2007 18:46:41 GMT
Author: mamta
Date: Thu May 24 11:46:40 2007
New Revision: 541381

URL: http://svn.apache.org/viewvc?view=rev&rev=541381
ResultColumn's convertConstant method has 2 calls to DataValueFactory.getVarcharDataValue(String)
which will always create SQLVarchar
and disregard any collation information that it should be using. This gets called for an INSERT
statement while trying to do
column type and length matching from the source resultset into the target. The change through
this commit makes sure we set the correct 
collation type and derivation. Some background information on this change from a thread titled
"Possible missing collation info for DVDs?" 
on Derby dev mailing list (http://www.nabble.com/Possible-missing-collation-info-for-DVDs--tf3798563.html#a10745343)

Snippet start from the thread mentioned above.
I looked at ResultColumn's convertConstant method which has the 2 calls to DataValueFactory.getVarcharDataValue(String).
This method gets 
called in following sequence
convertConstant(TypeId, int, DataValueDescriptor) - org.apache.derby.impl.sql.compile.ResultColumn
 columnTypeAndLengthMatch(ResultColumn) - org.apache.derby.impl.sql.compile.ResultColumn
  columnTypesAndLengthsMatch(ResultColumnList) - org.apache.derby.impl.sql.compile.ResultColumnList
   bindStatement() - org.apache.derby.impl.sql.compile.InsertNode
It looks like InsertNode's bindStatement method calls columnTypesAndLengthsMatch to make sure
that the source and target column types and 
lengths match and if not, then it should insert a NormalizeResultSetNode  on top of the source.
If the source happens to have constants, 
then we try to convert the constant to the type of the target(this happens in ResultColumn's
convertConstant method). 
Since none of this code flow happens for a collation operation, in theory, it will be ok with
not setting the correct collation type and 
derivation and hence the code should not run into any problem even if it stayed as it is.
If my understanding is wrong about how the 
constants in the insert statement can't be part of a collation operation, then please let
me know. Ideally though, it will not hurt to 
have the correct collation type and derivation setting on constants in this case whether or
not they get used in a collation method. So, 
I will go ahead and do that. 
Snippet end from the thread mentioned above.


Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java?view=diff&rev=541381&r1=541380&r2=541381
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java Thu
May 24 11:46:40 2007
@@ -1090,10 +1090,10 @@
 				ConstantNode constant = (ConstantNode)otherColumn.getExpression();
 				DataValueDescriptor oldValue = constant.getValue();
 				DataValueDescriptor newValue = convertConstant(
-					resultColumnType.getMaximumWidth(), oldValue);
+					resultColumnType.getMaximumWidth(), 
+					oldValue);
 				if ((oldValue != newValue) &&
 					(oldValue instanceof StringDataValue ==
@@ -1104,6 +1104,21 @@
 					otherResultColumnType = otherColumn.getType();
+				//If we are dealing with StringDataValue, then make sure we 
+				//have correct collation type and derivaiton set and the value
+				//represented by collation is either SQLxxx or CollatorSQLxxx
+				//depending on the collation type.
+				if (newValue instanceof StringDataValue)
+				{
+					constant.getTypeServices().setCollationDerivation(
+							resultColumnType.getCollationDerivation());
+					constant.getTypeServices().setCollationType(
+							resultColumnType.getCollationType());
+					DataValueFactory dvf = getDataValueFactory();
+					newValue = ((StringDataValue)newValue).getValue(dvf.getCharacterCollator(
+							constant.getTypeServices().getCollationType()));
+					constant.setValue(newValue);
+				}
 			if ( ! resultColumnType.getTypeId().equals(
@@ -1613,7 +1628,8 @@
 	 * @exception StandardException		Thrown on error
-	private DataValueDescriptor convertConstant(TypeId toTypeId, int maxWidth, DataValueDescriptor
+	private DataValueDescriptor convertConstant(TypeId toTypeId, int maxWidth,
+			DataValueDescriptor constantValue)
 		throws StandardException
 		int formatId = toTypeId.getTypeFormatId();

View raw message