Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 15814 invoked from network); 29 May 2007 20:45:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 May 2007 20:45:42 -0000 Received: (qmail 10088 invoked by uid 500); 29 May 2007 20:45:46 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 10058 invoked by uid 500); 29 May 2007 20:45:46 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 10047 invoked by uid 99); 29 May 2007 20:45:46 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 May 2007 13:45:46 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 May 2007 13:45:39 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 991501A981A; Tue, 29 May 2007 13:45:19 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r542646 [1/2] - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/ Date: Tue, 29 May 2007 20:45:18 -0000 To: derby-commits@db.apache.org From: mamta@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070529204519.991501A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mamta Date: Tue May 29 13:45:17 2007 New Revision: 542646 URL: http://svn.apache.org/viewvc?view=rev&rev=542646 Log: DERBY-2599 Commiting the patch which makes sure that JDBC parameters take their collation type from the schema in which they are getting compiled. This involved quite a few classes. I have added quite a few test cases. Test cases are required for LIKE, user defined functions, IS NULL. The commit also implements the fact that the result character string types from UPPER, LOWER, TRIM(LTRIM, RTRIM), SUBSTR will have the same collation as their operand. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryOperatorNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java 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/InListOperatorNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/IsNullNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LengthOperatorNode.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/MethodCallNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumn.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SQLToJavaValueNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetOperatorNode.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/StaticMethodCallNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TimestampOperatorNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.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/BinaryListOperatorNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java Tue May 29 13:45:17 2007 @@ -23,19 +23,16 @@ import org.apache.derby.iapi.error.StandardException; -import org.apache.derby.iapi.sql.dictionary.DataDictionary; - import org.apache.derby.iapi.reference.SQLState; import org.apache.derby.iapi.types.DataTypeDescriptor; import org.apache.derby.iapi.types.TypeId; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.sql.compile.Visitor; import org.apache.derby.iapi.sql.compile.Visitable; import org.apache.derby.iapi.services.sanity.SanityManager; -import org.apache.derby.iapi.store.access.Qualifier; - import org.apache.derby.iapi.util.JBitSet; import java.util.Vector; @@ -163,6 +160,12 @@ /* Set the left operand to the type of right parameter. */ leftOperand.setType(rightOperandList.getTypeServices()); + //? parameter should pick up the collation type of the schema in + //which this statement is getting compiled. + leftOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + leftOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema().getCollationType()); } /* Is there a ? parameter on the right? */ Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryOperatorNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryOperatorNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryOperatorNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/BinaryOperatorNode.java Tue May 29 13:45:17 2007 @@ -316,6 +316,11 @@ /* Set the left operand to the type of right parameter. */ leftOperand.setType(rightOperand.getTypeServices()); + //collation of ? operand should be same as the current schema + leftOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + leftOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema().getCollationType()); } /* Is there a ? parameter on the right? */ @@ -323,6 +328,12 @@ { /* Set the right operand to the type of the left parameter. */ rightOperand.setType(leftOperand.getTypeServices()); + //collation of ? operand should be same as the current schema + rightOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + rightOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } return genSQLJavaSQLTree(); Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CastNode.java Tue May 29 13:45:17 2007 @@ -31,6 +31,7 @@ import org.apache.derby.iapi.sql.compile.C_NodeTypes; import org.apache.derby.iapi.types.DataTypeUtilities; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.types.TypeId; import org.apache.derby.iapi.reference.Limits; @@ -803,6 +804,12 @@ throws StandardException { castOperand.setType(castTarget); + //collation of ? operand should be same as the current schema + castOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + castOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } /** Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java Tue May 29 13:45:17 2007 @@ -36,6 +36,7 @@ import org.apache.derby.iapi.services.compiler.MethodBuilder; import org.apache.derby.iapi.sql.compile.Visitable; import org.apache.derby.iapi.sql.compile.Visitor; +import org.apache.derby.iapi.types.StringDataValue; import java.lang.reflect.Modifier; @@ -175,6 +176,14 @@ if (((ValueNode) argumentsList.elementAt(index)).requiresTypeFromContext()) { ((ValueNode)argumentsList.elementAt(index)).setType(getTypeServices()); + //collation of ? operand should be same as the current schema + ((ValueNode)argumentsList.elementAt(index)).getTypeServices() + .setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + ((ValueNode)argumentsList.elementAt(index)).getTypeServices() + .setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); break; } } 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?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- 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 May 29 13:45:17 2007 @@ -1,25 +1,25 @@ /* - Derby - Class org.apache.derby.impl.sql.compile.ConcatenationOperatorNode + Derby - Class org.apache.derby.impl.sql.compile.ConcatenationOperatorNode - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to you under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ -package org.apache.derby.impl.sql.compile; +package org.apache.derby.impl.sql.compile; import org.apache.derby.iapi.sql.compile.C_NodeTypes; @@ -45,231 +45,217 @@ import java.util.Vector; - /** * This node represents a concatenation comparison operator - * - * varying. + * + * varying. */ -public class ConcatenationOperatorNode extends BinaryOperatorNode -{ +public class ConcatenationOperatorNode extends BinaryOperatorNode { /** * Initializer for a ConcatenationOperatorNode - * - * @param leftOperand The left operand of the concatenation - * @param rightOperand The right operand of the concatenation + * + * @param leftOperand + * The left operand of the concatenation + * @param rightOperand + * The right operand of the concatenation */ - public void init(Object leftOperand, Object rightOperand) - { + public void init(Object leftOperand, Object rightOperand) { super.init(leftOperand, rightOperand, "||", "concatenate", ClassName.ConcatableDataValue, ClassName.ConcatableDataValue); } /** - * overrides BindOperatorNode.bindExpression because concatenation has special - * requirements for parameter binding. - * - * @exception StandardException thrown on failure + * overrides BindOperatorNode.bindExpression because concatenation has + * special requirements for parameter binding. + * + * @exception StandardException + * thrown on failure */ - public ValueNode bindExpression( - FromList fromList, SubqueryList subqueryList, - Vector aggregateVector) - throws StandardException - { + public ValueNode bindExpression(FromList fromList, + SubqueryList subqueryList, Vector aggregateVector) + throws StandardException { // deal with binding operands leftOperand = leftOperand.bindExpression(fromList, subqueryList, - aggregateVector); + aggregateVector); rightOperand = rightOperand.bindExpression(fromList, subqueryList, - aggregateVector); + aggregateVector); // deal with operand parameters /* - Is there a ? parameter on the left? - If so, it's type is the type of the other parameter, with - maximum length for that type. - */ - - if (leftOperand.requiresTypeFromContext()) - { - if (rightOperand.requiresTypeFromContext()) - { - throw StandardException.newException(SQLState.LANG_BINARY_OPERANDS_BOTH_PARMS, - operator); + * Is there a ? parameter on the left? If so, it's type is the type of + * the other parameter, with maximum length for that type. + */ + + if (leftOperand.requiresTypeFromContext()) { + if (rightOperand.requiresTypeFromContext()) { + throw StandardException.newException( + SQLState.LANG_BINARY_OPERANDS_BOTH_PARMS, operator); } - TypeId leftType; + TypeId leftType; /* - ** A ? on the left gets its type from the right. There are eight - ** legal types for the concatenation operator: CHAR, VARCHAR, - ** LONG VARCHAR, CLOB, BIT, BIT VARYING, LONG BIT VARYING, and BLOB. - ** If the right type is BLOB, set the parameter type to BLOB with max length. - ** If the right type is one of the other bit types, set the parameter type to - ** BIT VARYING with maximum length. - ** - ** If the right type is CLOB, set parameter type to CLOB with max length. - ** If the right type is anything else, set it to VARCHAR with - ** maximum length. We count on the resolveConcatOperation method to - ** catch an illegal type. - ** - ** NOTE: When I added the long types, I could have changed the - ** resulting parameter types to LONG VARCHAR and LONG BIT VARYING, - ** but they were already VARCHAR and BIT VARYING, and it wasn't - ** clear to me what effect it would have to change it. - Jeff - */ - if (rightOperand.getTypeId().isBitTypeId()) - { + * * A ? on the left gets its type from the right. There are eight * + * legal types for the concatenation operator: CHAR, VARCHAR, * LONG + * VARCHAR, CLOB, BIT, BIT VARYING, LONG BIT VARYING, and BLOB. * If + * the right type is BLOB, set the parameter type to BLOB with max + * length. * If the right type is one of the other bit types, set + * the parameter type to * BIT VARYING with maximum length. * * If + * the right type is CLOB, set parameter type to CLOB with max + * length. * If the right type is anything else, set it to VARCHAR + * with * maximum length. We count on the resolveConcatOperation + * method to * catch an illegal type. * * NOTE: When I added the + * long types, I could have changed the * resulting parameter types + * to LONG VARCHAR and LONG BIT VARYING, * but they were already + * VARCHAR and BIT VARYING, and it wasn't * clear to me what effect + * it would have to change it. - Jeff + */ + if (rightOperand.getTypeId().isBitTypeId()) { if (rightOperand.getTypeId().isBlobTypeId()) leftType = TypeId.getBuiltInTypeId(Types.BLOB); else leftType = TypeId.getBuiltInTypeId(Types.VARBINARY); - } - else - { + } else { if (rightOperand.getTypeId().isClobTypeId()) leftType = TypeId.getBuiltInTypeId(Types.CLOB); else leftType = TypeId.getBuiltInTypeId(Types.VARCHAR); } - + leftOperand.setType(new DataTypeDescriptor(leftType, true)); - if (rightOperand.getTypeId().isStringTypeId()) - {//collation of ? operand should be same as the other operand + if (rightOperand.getTypeId().isStringTypeId()) { + //collation of ? operand should be same as the current schema leftOperand.getTypeServices().setCollationDerivation( - rightOperand.getTypeServices().getCollationDerivation()); + StringDataValue.COLLATION_DERIVATION_IMPLICIT); leftOperand.getTypeServices().setCollationType( - rightOperand.getTypeServices().getCollationType()); + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } } /* - Is there a ? parameter on the right? - */ - if (rightOperand.requiresTypeFromContext()) - { - TypeId rightType; + * Is there a ? parameter on the right? + */ + if (rightOperand.requiresTypeFromContext()) { + TypeId rightType; /* - ** A ? on the right gets its type from the left. There are eight - ** legal types for the concatenation operator: CHAR, VARCHAR, - ** LONG VARCHAR, CLOB, BIT, BIT VARYING, LONG BIT VARYING, and BLOB. - ** If the left type is BLOB, set the parameter type to BLOB with max length. - ** If the left type is one of the other bit types, set the parameter type to - ** BIT VARYING with maximum length. - ** - ** If the left type is CLOB, set parameter type to CLOB with max length. - ** If the left type is anything else, set it to VARCHAR with - ** maximum length. We count on the resolveConcatOperation method to - ** catch an illegal type. - ** - ** NOTE: When I added the long types, I could have changed the - ** resulting parameter types to LONG VARCHAR and LONG BIT VARYING, - ** but they were already VARCHAR and BIT VARYING, and it wasn't - ** clear to me what effect it would have to change it. - Jeff - */ - if (leftOperand.getTypeId().isBitTypeId()) - { + * * A ? on the right gets its type from the left. There are eight * + * legal types for the concatenation operator: CHAR, VARCHAR, * LONG + * VARCHAR, CLOB, BIT, BIT VARYING, LONG BIT VARYING, and BLOB. * If + * the left type is BLOB, set the parameter type to BLOB with max + * length. * If the left type is one of the other bit types, set the + * parameter type to * BIT VARYING with maximum length. * * If the + * left type is CLOB, set parameter type to CLOB with max length. * + * If the left type is anything else, set it to VARCHAR with * + * maximum length. We count on the resolveConcatOperation method to * + * catch an illegal type. * * NOTE: When I added the long types, I + * could have changed the * resulting parameter types to LONG + * VARCHAR and LONG BIT VARYING, * but they were already VARCHAR and + * BIT VARYING, and it wasn't * clear to me what effect it would + * have to change it. - Jeff + */ + if (leftOperand.getTypeId().isBitTypeId()) { if (leftOperand.getTypeId().isBlobTypeId()) rightType = TypeId.getBuiltInTypeId(Types.BLOB); else rightType = TypeId.getBuiltInTypeId(Types.VARBINARY); - } - else - { + } else { if (leftOperand.getTypeId().isClobTypeId()) rightType = TypeId.getBuiltInTypeId(Types.CLOB); else rightType = TypeId.getBuiltInTypeId(Types.VARCHAR); } - rightOperand.setType( - new DataTypeDescriptor( - rightType, - true)); - if (leftOperand.getTypeId().isStringTypeId()) - {//collation of ? operand should be same as the other operand + rightOperand.setType(new DataTypeDescriptor(rightType, true)); + if (leftOperand.getTypeId().isStringTypeId()) { + //collation of ? operand should be same as the current schema rightOperand.getTypeServices().setCollationDerivation( - leftOperand.getTypeServices().getCollationDerivation()); + StringDataValue.COLLATION_DERIVATION_IMPLICIT); rightOperand.getTypeServices().setCollationType( - leftOperand.getTypeServices().getCollationType()); + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } } - /* If the left operand is not a built-in type, then generate a bound conversion - * tree to a built-in type. + /* + * If the left operand is not a built-in type, then generate a bound + * conversion tree to a built-in type. */ - if (leftOperand.getTypeId().userType()) - { + if (leftOperand.getTypeId().userType()) { leftOperand = leftOperand.genSQLJavaSQLTree(); } - /* If the right operand is not a built-in type, then generate a bound conversion - * tree to a built-in type. + /* + * If the right operand is not a built-in type, then generate a bound + * conversion tree to a built-in type. */ - if (rightOperand.getTypeId().userType()) - { + if (rightOperand.getTypeId().userType()) { rightOperand = rightOperand.genSQLJavaSQLTree(); } - /* If either the left or right operands are non-string, non-bit types, + /* + * If either the left or right operands are non-string, non-bit types, * then we generate an implicit cast to VARCHAR. */ TypeCompiler tc = leftOperand.getTypeCompiler(); - if (! (leftOperand.getTypeId().isStringTypeId() || leftOperand.getTypeId().isBitTypeId())) - { - leftOperand = (ValueNode) - getNodeFactory().getNode( - C_NodeTypes.CAST_NODE, - leftOperand, - DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, true, - tc.getCastToCharWidth( - leftOperand.getTypeServices())), - getContextManager()); + if (!(leftOperand.getTypeId().isStringTypeId() || leftOperand + .getTypeId().isBitTypeId())) { + leftOperand = (ValueNode) getNodeFactory().getNode( + C_NodeTypes.CAST_NODE, + leftOperand, + DataTypeDescriptor.getBuiltInDataTypeDescriptor( + Types.VARCHAR, true, tc + .getCastToCharWidth(leftOperand + .getTypeServices())), + getContextManager()); ((CastNode) leftOperand).bindCastNodeOnly(); } tc = rightOperand.getTypeCompiler(); - if (! (rightOperand.getTypeId().isStringTypeId() || rightOperand.getTypeId().isBitTypeId())) - { - rightOperand = (ValueNode) - getNodeFactory().getNode( - C_NodeTypes.CAST_NODE, - rightOperand, - DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR, true, - tc.getCastToCharWidth( - rightOperand.getTypeServices())), - getContextManager()); + if (!(rightOperand.getTypeId().isStringTypeId() || rightOperand + .getTypeId().isBitTypeId())) { + rightOperand = (ValueNode) getNodeFactory().getNode( + C_NodeTypes.CAST_NODE, + rightOperand, + DataTypeDescriptor.getBuiltInDataTypeDescriptor( + Types.VARCHAR, true, tc + .getCastToCharWidth(rightOperand + .getTypeServices())), + getContextManager()); ((CastNode) rightOperand).bindCastNodeOnly(); } - /* - ** Set the result type of this operator based on the operands. - ** By convention, the left operand gets to decide the result type - ** of a binary operator. - */ + * * Set the result type of this operator based on the operands. * By + * convention, the left operand gets to decide the result type * of a + * binary operator. + */ tc = leftOperand.getTypeCompiler(); - setType(resolveConcatOperation( - leftOperand.getTypeServices(), - rightOperand.getTypeServices())); + setType(resolveConcatOperation(leftOperand.getTypeServices(), + rightOperand.getTypeServices())); /* - ** Make sure the maximum width set for the result doesn't exceed the result type's maximum width - */ - if (SanityManager.DEBUG) - { - if (getTypeServices().getMaximumWidth() > getTypeId().getMaximumMaximumWidth()) - { - SanityManager.THROWASSERT("The maximum length " + getTypeServices().getMaximumWidth() + - " for the result type " + getTypeId().getSQLTypeName() + - " can't be greater than it's maximum width of result's typeid" + getTypeId().getMaximumMaximumWidth()); + * * Make sure the maximum width set for the result doesn't exceed the + * result type's maximum width + */ + if (SanityManager.DEBUG) { + if (getTypeServices().getMaximumWidth() > getTypeId() + .getMaximumMaximumWidth()) { + SanityManager + .THROWASSERT("The maximum length " + + getTypeServices().getMaximumWidth() + + " for the result type " + + getTypeId().getSQLTypeName() + + " can't be greater than it's maximum width of result's typeid" + + getTypeId().getMaximumMaximumWidth()); } } /* - ** Now that we know the target interface type, set it. This assumes - ** that both operands have the same interface type, which is a safe - ** assumption for the concatenation operator. - */ + * * Now that we know the target interface type, set it. This assumes * + * that both operands have the same interface type, which is a safe * + * assumption for the concatenation operator. + */ this.setLeftRightInterfaceType(tc.interfaceName()); return this; @@ -277,201 +263,212 @@ /** * Resolve a concatenation operator - * - * @param leftType The DataTypeDescriptor of the left operand - * @param rightType The DataTypeDescriptor of the right operand - * - * @return A DataTypeDescriptor telling the result type of the - * concatenate operation - * - * @exception StandardException BinaryOperatorNotSupported - * Thrown when a BinaryOperator is not supported - * on the operand types. + * + * @param leftType + * The DataTypeDescriptor of the left operand + * @param rightType + * The DataTypeDescriptor of the right operand + * + * @return A DataTypeDescriptor telling the result type of the concatenate + * operation + * + * @exception StandardException + * BinaryOperatorNotSupported Thrown when a BinaryOperator is + * not supported on the operand types. */ private DataTypeDescriptor resolveConcatOperation( - DataTypeDescriptor leftType, - DataTypeDescriptor rightType - ) throws StandardException - { - TypeId leftTypeId; - TypeId rightTypeId; - String higherType; - int resultLength; - boolean nullable; + DataTypeDescriptor leftType, DataTypeDescriptor rightType) + throws StandardException { + TypeId leftTypeId; + TypeId rightTypeId; + String higherType; + int resultLength; + boolean nullable; leftTypeId = leftType.getTypeId(); rightTypeId = rightType.getTypeId(); /* - ** Check the right type to be sure it's a concatable. By convention, - ** we call this method off the TypeId of the left operand, so if - ** we get here, we know the left operand is a concatable. - */ - /* - ** Make sure we haven't been given a char and a - ** bit to concatenate. - */ + * * Check the right type to be sure it's a concatable. By convention, * + * we call this method off the TypeId of the left operand, so if * we + * get here, we know the left operand is a concatable. + */ + /* + * * Make sure we haven't been given a char and a * bit to concatenate. + */ if (!leftTypeId.isConcatableTypeId() - || !rightTypeId.isConcatableTypeId() - || (rightTypeId.isBitTypeId() && leftTypeId.isStringTypeId()) - || (leftTypeId.isBitTypeId() && rightTypeId.isStringTypeId())) - throw StandardException.newException(SQLState.LANG_DB2_FUNCTION_INCOMPATIBLE, "||", "FUNCTION"); + || !rightTypeId.isConcatableTypeId() + || (rightTypeId.isBitTypeId() && leftTypeId.isStringTypeId()) + || (leftTypeId.isBitTypeId() && rightTypeId.isStringTypeId())) + throw StandardException.newException( + SQLState.LANG_DB2_FUNCTION_INCOMPATIBLE, "||", "FUNCTION"); /* - ** The types aren't the same. The result of the operation is the - ** type of higher precedence. - */ - - higherType = (leftTypeId.typePrecedence() >= - rightTypeId.typePrecedence()) ? - leftType.getTypeName() : rightType.getTypeName(); + * * The types aren't the same. The result of the operation is the * + * type of higher precedence. + */ + + higherType = (leftTypeId.typePrecedence() >= rightTypeId + .typePrecedence()) ? leftType.getTypeName() : rightType + .getTypeName(); /* Get the length of the result */ - resultLength = leftType.getMaximumWidth() + - rightType.getMaximumWidth(); + resultLength = leftType.getMaximumWidth() + rightType.getMaximumWidth(); /* - ** Use following chart to handle overflow - ** operands CHAR(A) CHAR(B) and A+B<255 then result is CHAR(A+B) - ** operands CHAR FOR BIT DATA(A) CHAR FOR BIT DATA(B) and A+B<255 then result is CHAR FOR BIT DATA(A+B) - ** - ** operands CHAR(A) CHAR(B) and A+B>254 then result is VARCHAR(A+B) - ** operands CHAR FOR BIT DATA(A) CHAR FOR BIT DATA(B) and A+B>254 then result is VARCHAR FOR BIT DATA(A+B) - ** - ** operands CHAR(A) VARCHAR(B) and A+B<4001 then result is VARCHAR(A+B) - ** operands CHAR FOR BIT DATA(A) VARCHAR FOR BIT DATA(B) and A+B<4001 then result is VARCHAR FOR BIT DATA(A+B) - ** - ** operands CHAR(A) VARCHAR(B) and A+B>4000 then result is LONG VARCHAR - ** operands CHAR FOR BIT DATA(A) VARCHAR FOR BIT DATA(B) and A+B>4000 then result is LONG VARCHAR FOR BIT DATA - ** - ** operands CHAR(A) LONG VARCHAR then result is LONG VARCHAR - ** operands CHAR FOR BIT DATA(A) LONG VARCHAR FOR BIT DATA then result is LONG VARCHAR FOR BIT DATA - ** - ** operands VARCHAR(A) VARCHAR(B) and A+B<4001 then result is VARCHAR(A+B) - ** operands VARCHAR FOR BIT DATA(A) VARCHAR FOR BIT DATA(B) and A+B<4001 then result is VARCHAR FOR BIT DATA(A+B) - ** - ** operands VARCHAR(A) VARCHAR(B) and A+B>4000 then result is LONG VARCHAR - ** operands VARCHAR FOR BIT DATA(A) VARCHAR FOR BIT DATA(B) and A+B>4000 then result is LONG VARCHAR FOR BIT DATA - ** - ** operands VARCHAR(A) LONG VARCHAR then result is LONG VARCHAR - ** operands VARCHAR FOR BIT DATA(A) LONG VARCHAR FOR BIT DATA then result is LONG VARCHAR FOR BIT DATA - ** - ** operands LONG VARCHAR, LONG VARCHAR then result is LONG VARCHAR - ** operands LONG VARCHAR FOR BIT DATA, LONG VARCHAR FOR BIT DATA then result is LONG VARCHAR FOR BIT DATA - ** - ** operands CLOB(A), CHAR(B) then result is CLOB(MIN(A+B,2G)) - ** operands CLOB(A), VARCHAR(B) then result is CLOB(MIN(A+B,2G)) - ** operands CLOB(A), LONG VARCHAR then result is CLOB(MIN(A+32K,2G)) - ** operands CLOB(A), CLOB(B) then result is CLOB(MIN(A+B,2G)) - ** - ** operands BLOB(A), CHAR FOR BIT DATA(B) then result is BLOB(MIN(A+B,2G)) - ** operands BLOB(A), VARCHAR FOR BIT DATA(B) then result is BLOB(MIN(A+B,2G)) - ** operands BLOB(A), LONG VARCHAR FOR BIT DATA then result is BLOB(MIN(A+32K,2G)) - ** operands BLOB(A), BLOB(B) then result is BLOB(MIN(A+B,2G)) - ** - ** operands CHAR(A)/VARCHAR(A)/LONGVARCHAR, LONGVARCHAR and "concatenated string length">32700 does not cause automatic escalation - ** to LOB for compatibility with previous releases. Any such cases would result in an error at runtime - ** - */ - //in the following code, I can assume that left and right operands both will be either char kind - //of datatypes or they will be both binary kind of datatypes. That's because operand datatypes + * * Use following chart to handle overflow * operands CHAR(A) CHAR(B) + * and A+B <255 then result is CHAR(A+B) * operands CHAR FOR BIT DATA(A) + * CHAR FOR BIT DATA(B) and A+B <255 then result is CHAR FOR BIT + * DATA(A+B) * * operands CHAR(A) CHAR(B) and A+B>254 then result is + * VARCHAR(A+B) * operands CHAR FOR BIT DATA(A) CHAR FOR BIT DATA(B) and + * A+B>254 then result is VARCHAR FOR BIT DATA(A+B) * * operands CHAR(A) + * VARCHAR(B) and A+B <4001 then result is VARCHAR(A+B) * operands CHAR + * FOR BIT DATA(A) VARCHAR FOR BIT DATA(B) and A+B <4001 then result is + * VARCHAR FOR BIT DATA(A+B) * * operands CHAR(A) VARCHAR(B) and + * A+B>4000 then result is LONG VARCHAR * operands CHAR FOR BIT DATA(A) + * VARCHAR FOR BIT DATA(B) and A+B>4000 then result is LONG VARCHAR FOR + * BIT DATA * * operands CHAR(A) LONG VARCHAR then result is LONG + * VARCHAR * operands CHAR FOR BIT DATA(A) LONG VARCHAR FOR BIT DATA + * then result is LONG VARCHAR FOR BIT DATA * * operands VARCHAR(A) + * VARCHAR(B) and A+B <4001 then result is VARCHAR(A+B) * operands + * VARCHAR FOR BIT DATA(A) VARCHAR FOR BIT DATA(B) and A+B <4001 then + * result is VARCHAR FOR BIT DATA(A+B) * * operands VARCHAR(A) + * VARCHAR(B) and A+B>4000 then result is LONG VARCHAR * operands + * VARCHAR FOR BIT DATA(A) VARCHAR FOR BIT DATA(B) and A+B>4000 then + * result is LONG VARCHAR FOR BIT DATA * * operands VARCHAR(A) LONG + * VARCHAR then result is LONG VARCHAR * operands VARCHAR FOR BIT + * DATA(A) LONG VARCHAR FOR BIT DATA then result is LONG VARCHAR FOR BIT + * DATA * * operands LONG VARCHAR, LONG VARCHAR then result is LONG + * VARCHAR * operands LONG VARCHAR FOR BIT DATA, LONG VARCHAR FOR BIT + * DATA then result is LONG VARCHAR FOR BIT DATA * * operands CLOB(A), + * CHAR(B) then result is CLOB(MIN(A+B,2G)) * operands CLOB(A), + * VARCHAR(B) then result is CLOB(MIN(A+B,2G)) * operands CLOB(A), LONG + * VARCHAR then result is CLOB(MIN(A+32K,2G)) * operands CLOB(A), + * CLOB(B) then result is CLOB(MIN(A+B,2G)) * * operands BLOB(A), CHAR + * FOR BIT DATA(B) then result is BLOB(MIN(A+B,2G)) * operands BLOB(A), + * VARCHAR FOR BIT DATA(B) then result is BLOB(MIN(A+B,2G)) * operands + * BLOB(A), LONG VARCHAR FOR BIT DATA then result is BLOB(MIN(A+32K,2G)) * + * operands BLOB(A), BLOB(B) then result is BLOB(MIN(A+B,2G)) * * + * operands CHAR(A)/VARCHAR(A)/LONGVARCHAR, LONGVARCHAR and + * "concatenated string length">32700 does not cause automatic + * escalation * to LOB for compatibility with previous releases. Any + * such cases would result in an error at runtime * + */ + //in the following code, I can assume that left and right operands both + // will be either char kind + //of datatypes or they will be both binary kind of datatypes. That's + // because operand datatypes //mismatch has already been handled earlier - if (leftTypeId.getJDBCTypeId() == Types.CHAR || leftTypeId.getJDBCTypeId() == Types.BINARY) - { - switch (rightTypeId.getJDBCTypeId()) - { - case Types.CHAR: - case Types.BINARY: - if (resultLength > Limits.DB2_CHAR_MAXWIDTH) { - if (rightTypeId.getJDBCTypeId() == Types.CHAR) - //operands CHAR(A) CHAR(B) and A+B>254 then result is VARCHAR(A+B) - higherType = TypeId.VARCHAR_NAME; - else - //operands CHAR FOR BIT DATA(A) CHAR FOR BIT DATA(B) and A+B>254 then result is VARCHAR FOR BIT DATA(A+B) - higherType = TypeId.VARBIT_NAME; - } - break; - - case Types.VARCHAR: - case Types.VARBINARY: - if (resultLength > Limits.DB2_CONCAT_VARCHAR_LENGTH) { - if (rightTypeId.getJDBCTypeId() == Types.VARCHAR) - //operands CHAR(A) VARCHAR(B) and A+B>4000 then result is LONG VARCHAR - higherType = TypeId.LONGVARCHAR_NAME; - else - //operands CHAR FOR BIT DATA(A) VARCHAR FOR BIT DATA(B) and A+B>4000 then result is LONG VARCHAR FOR BIT DATA - higherType = TypeId.LONGVARBIT_NAME; - } - break; - - case Types.CLOB: - case Types.BLOB: - //operands CHAR(A), CLOB(B) then result is CLOB(MIN(A+B,2G)) - //operands CHAR FOR BIT DATA(A), BLOB(B) then result is BLOB(MIN(A+B,2G)) - resultLength = clobBlobHandling(rightType, leftType); - break; - } - } else if (leftTypeId.getJDBCTypeId() == Types.VARCHAR) { - switch (rightTypeId.getJDBCTypeId()) - { - case Types.CHAR: //operands CHAR(A) VARCHAR(B) and A+B>4000 then result is LONG VARCHAR - case Types.VARCHAR: //operands VARCHAR(A) VARCHAR(B) and A+B>4000 then result is LONG VARCHAR - if (resultLength > Limits.DB2_CONCAT_VARCHAR_LENGTH) + if (leftTypeId.getJDBCTypeId() == Types.CHAR + || leftTypeId.getJDBCTypeId() == Types.BINARY) { + switch (rightTypeId.getJDBCTypeId()) { + case Types.CHAR: + case Types.BINARY: + if (resultLength > Limits.DB2_CHAR_MAXWIDTH) { + if (rightTypeId.getJDBCTypeId() == Types.CHAR) + //operands CHAR(A) CHAR(B) and A+B>254 then result is + // VARCHAR(A+B) + higherType = TypeId.VARCHAR_NAME; + else + //operands CHAR FOR BIT DATA(A) CHAR FOR BIT DATA(B) + // and A+B>254 then result is VARCHAR FOR BIT DATA(A+B) + higherType = TypeId.VARBIT_NAME; + } + break; + + case Types.VARCHAR: + case Types.VARBINARY: + if (resultLength > Limits.DB2_CONCAT_VARCHAR_LENGTH) { + if (rightTypeId.getJDBCTypeId() == Types.VARCHAR) + //operands CHAR(A) VARCHAR(B) and A+B>4000 then result + // is LONG VARCHAR higherType = TypeId.LONGVARCHAR_NAME; - break; + else + //operands CHAR FOR BIT DATA(A) VARCHAR FOR BIT DATA(B) + // and A+B>4000 then result is LONG VARCHAR FOR BIT DATA + higherType = TypeId.LONGVARBIT_NAME; + } + break; - case Types.CLOB: - //operands VARCHAR(A), CLOB(B) then result is CLOB(MIN(A+B,2G)) - resultLength = clobBlobHandling(rightType, leftType); - break; + case Types.CLOB: + case Types.BLOB: + //operands CHAR(A), CLOB(B) then result is CLOB(MIN(A+B,2G)) + //operands CHAR FOR BIT DATA(A), BLOB(B) then result is + // BLOB(MIN(A+B,2G)) + resultLength = clobBlobHandling(rightType, leftType); + break; + } + } else if (leftTypeId.getJDBCTypeId() == Types.VARCHAR) { + switch (rightTypeId.getJDBCTypeId()) { + case Types.CHAR: //operands CHAR(A) VARCHAR(B) and A+B>4000 then + // result is LONG VARCHAR + case Types.VARCHAR: //operands VARCHAR(A) VARCHAR(B) and A+B>4000 + // then result is LONG VARCHAR + if (resultLength > Limits.DB2_CONCAT_VARCHAR_LENGTH) + higherType = TypeId.LONGVARCHAR_NAME; + break; + + case Types.CLOB: + //operands VARCHAR(A), CLOB(B) then result is CLOB(MIN(A+B,2G)) + resultLength = clobBlobHandling(rightType, leftType); + break; } } else if (leftTypeId.getJDBCTypeId() == Types.VARBINARY) { - switch (rightTypeId.getJDBCTypeId()) - { - case Types.BINARY: //operands CHAR FOR BIT DATA(A) VARCHAR FOR BIT DATA(B) and A+B>4000 then result is LONG VARCHAR FOR BIT DATA - case Types.VARBINARY://operands VARCHAR FOR BIT DATA(A) VARCHAR FOR BIT DATA(B) and A+B>4000 then result is LONG VARCHAR FOR BIT DATA - if (resultLength > Limits.DB2_CONCAT_VARCHAR_LENGTH) - higherType = TypeId.LONGVARBIT_NAME; - break; - - case Types.BLOB: - //operands VARCHAR FOR BIT DATA(A), BLOB(B) then result is BLOB(MIN(A+B,2G)) - resultLength = clobBlobHandling(rightType, leftType); - break; + switch (rightTypeId.getJDBCTypeId()) { + case Types.BINARY: //operands CHAR FOR BIT DATA(A) VARCHAR FOR BIT + // DATA(B) and A+B>4000 then result is LONG + // VARCHAR FOR BIT DATA + case Types.VARBINARY://operands VARCHAR FOR BIT DATA(A) VARCHAR FOR + // BIT DATA(B) and A+B>4000 then result is LONG + // VARCHAR FOR BIT DATA + if (resultLength > Limits.DB2_CONCAT_VARCHAR_LENGTH) + higherType = TypeId.LONGVARBIT_NAME; + break; + + case Types.BLOB: + //operands VARCHAR FOR BIT DATA(A), BLOB(B) then result is + // BLOB(MIN(A+B,2G)) + resultLength = clobBlobHandling(rightType, leftType); + break; } - } else if (leftTypeId.getJDBCTypeId() == Types.CLOB || leftTypeId.getJDBCTypeId() == Types.BLOB) { + } else if (leftTypeId.getJDBCTypeId() == Types.CLOB + || leftTypeId.getJDBCTypeId() == Types.BLOB) { //operands CLOB(A), CHAR(B) then result is CLOB(MIN(A+B,2G)) //operands CLOB(A), VARCHAR(B) then result is CLOB(MIN(A+B,2G)) //operands CLOB(A), LONG VARCHAR then result is CLOB(MIN(A+32K,2G)) //operands CLOB(A), CLOB(B) then result is CLOB(MIN(A+B,2G)) - //operands BLOB(A), CHAR FOR BIT DATA(B) then result is BLOB(MIN(A+B,2G)) - //operands BLOB(A), VARCHAR FOR BIT DATA(B) then result is BLOB(MIN(A+B,2G)) - //operands BLOB(A), LONG VARCHAR FOR BIT DATA then result is BLOB(MIN(A+32K,2G)) + //operands BLOB(A), CHAR FOR BIT DATA(B) then result is + // BLOB(MIN(A+B,2G)) + //operands BLOB(A), VARCHAR FOR BIT DATA(B) then result is + // BLOB(MIN(A+B,2G)) + //operands BLOB(A), LONG VARCHAR FOR BIT DATA then result is + // BLOB(MIN(A+32K,2G)) //operands BLOB(A), BLOB(B) then result is BLOB(MIN(A+B,2G)) resultLength = clobBlobHandling(leftType, rightType); - } else if (rightTypeId.getJDBCTypeId() == Types.CLOB || rightTypeId.getJDBCTypeId() == Types.BLOB) { + } else if (rightTypeId.getJDBCTypeId() == Types.CLOB + || rightTypeId.getJDBCTypeId() == Types.BLOB) { //operands LONG VARCHAR, CLOB(A) then result is CLOB(MIN(A+32K,2G)) - //operands LONG VARCHAR FOR BIT DATA, BLOB(A) then result is BLOB(MIN(A+32K,2G)) + //operands LONG VARCHAR FOR BIT DATA, BLOB(A) then result is + // BLOB(MIN(A+32K,2G)) resultLength = clobBlobHandling(rightType, leftType); } - //bug - 5837. long varchar and long binary can't hold more data than their specific limits. If this length is violated by resulting + //bug - 5837. long varchar and long binary can't hold more data than + // their specific limits. If this length is violated by resulting //concatenated string, an exception will be thrown at execute time. if (higherType.equals(TypeId.LONGVARCHAR_NAME)) resultLength = TypeId.LONGVARCHAR_MAXWIDTH; else if (higherType.equals(TypeId.LONGVARBIT_NAME)) resultLength = TypeId.LONGVARBIT_MAXWIDTH; - /* - ** Result Length can't be negative - */ - if (SanityManager.DEBUG) - { - if (resultLength < 0) - { - SanityManager.THROWASSERT("There should not be an overflow of maximum length for any result type at this point. Overflow for BLOB/CLOB has already been handled earlier"); + * * Result Length can't be negative + */ + if (SanityManager.DEBUG) { + if (resultLength < 0) { + SanityManager + .THROWASSERT("There should not be an overflow of maximum length for any result type at this point. Overflow for BLOB/CLOB has already been handled earlier"); } } @@ -479,25 +476,23 @@ nullable = leftType.isNullable() || rightType.isNullable(); /* - ** Create a new DataTypeDescriptor that has the correct - ** type and nullability. - ** - ** It's OK to call the implementation of the DataTypeDescriptorFactory - ** here, because we're in the same package. - */ - DataTypeDescriptor returnDTD = new DataTypeDescriptor( - TypeId.getBuiltInTypeId(higherType), - nullable, - resultLength - ); + * * Create a new DataTypeDescriptor that has the correct * type and + * nullability. * * It's OK to call the implementation of the + * DataTypeDescriptorFactory * here, because we're in the same package. + */ + DataTypeDescriptor returnDTD = new DataTypeDescriptor(TypeId + .getBuiltInTypeId(higherType), nullable, resultLength); - //Check if collation derivations and collation types of 2 operands match? + //Check if collation derivations and collation types of 2 operands + // match? //If they do, then the result of the concatenation will get the smae //collation information. But if not, then the collation derivation of //the result will be NONE. - if (leftType.getCollationDerivation() != rightType.getCollationDerivation() - || leftType.getCollationType() != rightType.getCollationType()) - returnDTD.setCollationDerivation(StringDataValue.COLLATION_DERIVATION_NONE); + if (leftType.getCollationDerivation() != rightType + .getCollationDerivation() + || leftType.getCollationType() != rightType.getCollationType()) + returnDTD + .setCollationDerivation(StringDataValue.COLLATION_DERIVATION_NONE); else { returnDTD.setCollationDerivation(leftType.getCollationDerivation()); returnDTD.setCollationType(leftType.getCollationType()); @@ -506,49 +501,50 @@ } /* - *for conatenation operator, we generate code as follows - *field = method(p1, p2, field); - *what we are ensuring here is if field is null then initialize it to NULL SQLxxx type. - *Because of the following, at execution time, SQLxxx concatenate method do not have to - *worry about field coming in as null - */ - protected void initializeResultField(ExpressionClassBuilder acb, MethodBuilder mb, LocalField resultField) - throws StandardException - { + * for conatenation operator, we generate code as follows field = method(p1, + * p2, field); what we are ensuring here is if field is null then initialize + * it to NULL SQLxxx type. Because of the following, at execution time, + * SQLxxx concatenate method do not have to worry about field coming in as + * null + */ + protected void initializeResultField(ExpressionClassBuilder acb, + MethodBuilder mb, LocalField resultField) throws StandardException { mb.conditionalIfNull();//get the field on the stack and if it is null - acb.generateNull(mb, getTypeCompiler(), - getTypeServices().getCollationType());// yes, it is, hence create a NULL SQLxxx type object and put that on stack + acb.generateNull(mb, getTypeCompiler(), getTypeServices() + .getCollationType());// yes, it is, hence create a NULL SQLxxx + // type object and put that on stack mb.startElseCode(); //no, it is not null - mb.getField(resultField); //so put it back on the stack + mb.getField(resultField); //so put it back on the stack mb.completeConditional(); //complete if else block } - private static int clobBlobHandling( - DataTypeDescriptor clobBlobType, - DataTypeDescriptor otherType - ) throws StandardException - { + private static int clobBlobHandling(DataTypeDescriptor clobBlobType, + DataTypeDescriptor otherType) throws StandardException { int resultLength; - if (otherType.getTypeId().getJDBCTypeId() == Types.LONGVARCHAR || - otherType.getTypeId().getJDBCTypeId() == Types.LONGVARBINARY) { + if (otherType.getTypeId().getJDBCTypeId() == Types.LONGVARCHAR + || otherType.getTypeId().getJDBCTypeId() == Types.LONGVARBINARY) { //operands CLOB(A), LONG VARCHAR then result is CLOB(MIN(A+32K,2G)) - //operands BLOB(A), LONG VARCHAR FOR BIT DATA then result is BLOB(MIN(A+32K,2G)) + //operands BLOB(A), LONG VARCHAR FOR BIT DATA then result is + // BLOB(MIN(A+32K,2G)) resultLength = clobBlobType.getMaximumWidth() + 32768; } else { //operands CLOB(A), CHAR(B) then result is CLOB(MIN(A+B,2G)) //operands CLOB(A), VARCHAR(B) then result is CLOB(MIN(A+B,2G)) //operands CLOB(A), CLOB(B) then result is CLOB(MIN(A+B,2G)) - //operands BLOB(A), CHAR FOR BIT DATA(B) then result is BLOB(MIN(A+B,2G)) - //operands BLOB(A), VARCHAR FOR BIT DATA(B) then result is BLOB(MIN(A+B,2G)) + //operands BLOB(A), CHAR FOR BIT DATA(B) then result is + // BLOB(MIN(A+B,2G)) + //operands BLOB(A), VARCHAR FOR BIT DATA(B) then result is + // BLOB(MIN(A+B,2G)) //operands BLOB(A), BLOB(B) then result is BLOB(MIN(A+B,2G)) - resultLength = clobBlobType.getMaximumWidth() + otherType.getMaximumWidth(); + resultLength = clobBlobType.getMaximumWidth() + + otherType.getMaximumWidth(); } if (resultLength < 1) //this mean A+B or A+32K is bigger than 2G - return(Integer.MAX_VALUE); + return (Integer.MAX_VALUE); else - return(resultLength); + return (resultLength); } } Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java Tue May 29 13:45:17 2007 @@ -30,6 +30,7 @@ import org.apache.derby.iapi.sql.dictionary.DataDictionary; import org.apache.derby.iapi.reference.ClassName; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.types.TypeId; import org.apache.derby.iapi.types.DataTypeDescriptor; import org.apache.derby.iapi.types.DataValueDescriptor; @@ -319,6 +320,12 @@ getContextManager()); DataTypeDescriptor pType = srcVal.getTypeServices(); + //collation of ? operand should be same as the current schema + pType.setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + pType.setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); pNode.setDescriptors(new DataTypeDescriptor [] { pType }); pNode.setType(pType); Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/IsNullNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/IsNullNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/IsNullNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/IsNullNode.java Tue May 29 13:45:17 2007 @@ -38,6 +38,7 @@ import org.apache.derby.iapi.types.DataTypeDescriptor; import org.apache.derby.iapi.types.DataValueDescriptor; import org.apache.derby.iapi.types.DataValueFactory; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.types.TypeId; import org.apache.derby.iapi.types.Orderable; @@ -145,6 +146,12 @@ */ operand.setType(new DataTypeDescriptor(TypeId.getBuiltInTypeId(Types.VARCHAR), true)); + //collation of ? operand should be same as the current schema + operand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + operand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } /* RelationalOperator interface */ Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LengthOperatorNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LengthOperatorNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LengthOperatorNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/LengthOperatorNode.java Tue May 29 13:45:17 2007 @@ -26,6 +26,7 @@ import org.apache.derby.iapi.sql.compile.C_NodeTypes; import org.apache.derby.iapi.sql.dictionary.DataDictionary; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.types.TypeId; import org.apache.derby.iapi.types.DataTypeDescriptor; import org.apache.derby.iapi.types.ConcatableDataValue; @@ -147,6 +148,12 @@ operand.setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor(parameterType, true, parameterWidth)); + //collation of ? operand should be same as the current schema + operand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + operand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } /** 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?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- 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 May 29 13:45:17 2007 @@ -189,6 +189,12 @@ receiver.setType( new DataTypeDescriptor( TypeId.getBuiltInTypeId(Types.VARCHAR), true)); + //collation of ? operand should be same as the current schema + receiver.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + receiver.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } /* @@ -214,6 +220,12 @@ new DataTypeDescriptor( TypeId.getBuiltInTypeId(Types.VARCHAR), true)); } + //collation of ? operand should be same as the current schema + leftOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + leftOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } /* @@ -238,6 +250,12 @@ new DataTypeDescriptor( TypeId.getBuiltInTypeId(Types.VARCHAR), true)); } + //collation of ? operand should be same as the current schema + rightOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + rightOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } bindToBuiltIn(); Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/MethodCallNode.java Tue May 29 13:45:17 2007 @@ -29,6 +29,7 @@ import org.apache.derby.iapi.error.StandardException; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.types.TypeId; import org.apache.derby.iapi.types.JSQLType; @@ -783,6 +784,12 @@ we generate the metadata info for the return parameter and reset the flag in the compilercontext for future call statements*/ DataTypeDescriptor dts = DataTypeDescriptor.getSQLDataTypeDescriptor(typeName); + //collation of ? operand should be same as the current schema + dts.setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + dts.setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); if (getCompilerContext().getReturnParameterFlag()) { getCompilerContext().getParameterTypes()[0] = dts; } 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=542646&r1=542645&r2=542646 ============================================================================== --- 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 Tue May 29 13:45:17 2007 @@ -574,6 +574,12 @@ if (getTypeServices() != null) { expression.setType(getTypeServices()); + //collation of ? operand should be same as the current schema + expression.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + expression.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } } Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java Tue May 29 13:45:17 2007 @@ -48,6 +48,7 @@ import org.apache.derby.iapi.sql.Activation; import org.apache.derby.iapi.types.DataTypeDescriptor; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.sql.ResultColumnDescriptor; import org.apache.derby.iapi.sql.ResultDescription; import org.apache.derby.iapi.sql.ResultSet; @@ -335,6 +336,12 @@ ** corresponding column of the target table. */ re.setType(typeCol.getTypeServices()); + //collation of ? operand should be same as the current schema + re.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + re.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } else if (re instanceof CharConstantNode) { Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SQLToJavaValueNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SQLToJavaValueNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SQLToJavaValueNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SQLToJavaValueNode.java Tue May 29 13:45:17 2007 @@ -30,6 +30,7 @@ import org.apache.derby.iapi.types.DataValueDescriptor; import org.apache.derby.iapi.types.DataTypeDescriptor; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.sql.compile.TypeCompiler; @@ -165,6 +166,7 @@ else pn = (ParameterNode) (value); jsqlType = pn.getJSQLType(); + } else { Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetOperatorNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetOperatorNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetOperatorNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetOperatorNode.java Tue May 29 13:45:17 2007 @@ -37,6 +37,7 @@ import org.apache.derby.iapi.reference.SQLState; import org.apache.derby.iapi.types.DataTypeDescriptor; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.util.JBitSet; @@ -727,6 +728,12 @@ ** type array. */ rc.getExpression().setType(types[index]); + //collation of ? operand should be same as the current schema + rc.getExpression().getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + rc.getExpression().getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } } } 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?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- 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 May 29 13:45:17 2007 @@ -125,6 +125,12 @@ getCastToCharWidth(operand.getTypeServices()) ) ); + //Result of upper()/lower() will have the same collation as the + //argument to upper()/lower(). + getTypeServices().setCollationDerivation( + operand.getTypeServices().getCollationDerivation()); + getTypeServices().setCollationType( + operand.getTypeServices().getCollationType()); return this; } @@ -145,6 +151,12 @@ */ operand.setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.VARCHAR)); + //collation of ? operand should be same as the current schema + operand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + operand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } /** Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java Tue May 29 13:45:17 2007 @@ -30,6 +30,7 @@ import org.apache.derby.iapi.sql.compile.C_NodeTypes; import org.apache.derby.iapi.types.JSQLType; import org.apache.derby.iapi.types.DataTypeDescriptor; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.types.TypeId; import org.apache.derby.iapi.sql.dictionary.AliasDescriptor; @@ -624,6 +625,12 @@ pn = ((UnaryOperatorNode)sql2j.getSQLValueNode()).getParameterOperand(); else pn = (ParameterNode) (sql2j.getSQLValueNode()); + //collation of ? operand should be same as the current schema + pn.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + pn.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); // applicationParameterNumbers is only set up for a procedure. int applicationParameterNumber = pn.getParameterNumber(); Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SubqueryNode.java Tue May 29 13:45:17 2007 @@ -36,6 +36,7 @@ import org.apache.derby.iapi.reference.ClassName; import org.apache.derby.iapi.types.DataTypeDescriptor; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.sql.execute.ExecRow; @@ -531,6 +532,12 @@ { leftOperand.setType( ((ResultColumn) resultColumns.elementAt(0)).getTypeServices()); + //collation of ? operand should be same as the current schema + leftOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + leftOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } // Set the DataTypeServices 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?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- 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 May 29 13:45:17 2007 @@ -524,6 +524,12 @@ */ receiver.setType(getVarcharDescriptor()); + //collation of ? operand should be same as the current schema + receiver.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + receiver.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } /* Is there a ? parameter on the left? */ @@ -531,6 +537,12 @@ { /* Set the left operand type to varchar. */ leftOperand.setType(getVarcharDescriptor()); + //collation of ? operand should be same as the current schema + leftOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + leftOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } bindToBuiltIn(); @@ -570,6 +582,13 @@ ** The result type of trim is varchar. */ setResultType(resultType); + //Result of TRIM should pick up the collation of the 1st argument + //to TRIM. The 1st argument to TRIM is represented by the variable + //receiver in this class. + getTypeServices().setCollationDerivation( + receiver.getTypeServices().getCollationDerivation()); + getTypeServices().setCollationType( + receiver.getTypeServices().getCollationType()); return this; } @@ -616,6 +635,12 @@ leftOperand.getTypeServices()); } } + //collation of ? operand should be same as the current schema + receiver.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + receiver.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } /* @@ -636,6 +661,12 @@ receiver.getTypeServices()); } } + //collation of ? operand should be same as the current schema + leftOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + leftOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } /* @@ -645,6 +676,12 @@ { rightOperand.setType( new DataTypeDescriptor(TypeId.INTEGER_ID, true)); + //collation of ? operand should be same as the current schema + rightOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + rightOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } bindToBuiltIn(); @@ -720,6 +757,12 @@ */ receiver.setType(getVarcharDescriptor()); + //collation of ? operand should be same as the current schema + receiver.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + receiver.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); } /* Is there a ? parameter on the left? */ @@ -779,7 +822,13 @@ true, resultLen )); - + //Result of SUSBSTR should pick up the collation of the 1st argument + //to SUBSTR. The 1st argument to SUBSTR is represented by the variable + //receiver in this class. + getTypeServices().setCollationDerivation( + receiver.getTypeServices().getCollationDerivation()); + getTypeServices().setCollationType( + receiver.getTypeServices().getCollationType()); return this; } @@ -844,6 +893,12 @@ if( arg.requiresTypeFromContext() && arg.getTypeId() == null) { arg.setType( new DataTypeDescriptor(TypeId.getBuiltInTypeId( jdbcType), true)); + //collation of ? operand should be same as the current schema + arg.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + arg.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); return true; } return false; Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TimestampOperatorNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TimestampOperatorNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TimestampOperatorNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TimestampOperatorNode.java Tue May 29 13:45:17 2007 @@ -21,6 +21,7 @@ package org.apache.derby.impl.sql.compile; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.types.TypeId; import org.apache.derby.iapi.types.DataValueFactory; import org.apache.derby.iapi.types.DataTypeDescriptor; @@ -87,11 +88,25 @@ aggregateVector); //Set the type if there is a parameter involved here - if (leftOperand.requiresTypeFromContext()) + if (leftOperand.requiresTypeFromContext()) { leftOperand.setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor( Types.DATE)); + //collation of ? operand should be same as the current schema + leftOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + leftOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); + } //Set the type if there is a parameter involved here - if (rightOperand.requiresTypeFromContext()) + if (rightOperand.requiresTypeFromContext()) { rightOperand.setType(DataTypeDescriptor.getBuiltInDataTypeDescriptor( Types.TIME)); + //collation of ? operand should be same as the current schema + rightOperand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + rightOperand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); + } TypeId leftTypeId = leftOperand.getTypeId(); TypeId rightTypeId = rightOperand.getTypeId(); Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java Tue May 29 13:45:17 2007 @@ -23,6 +23,7 @@ import org.apache.derby.iapi.sql.dictionary.DataDictionary; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.types.TypeId; import org.apache.derby.iapi.types.DataTypeDescriptor; import org.apache.derby.iapi.reference.SQLState; @@ -252,6 +253,12 @@ public void setType(DataTypeDescriptor descriptor) throws StandardException { operand.setType(descriptor); + //collation of ? operand should be same as the current schema + operand.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + operand.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema() + .getCollationType()); super.setType(descriptor); //Derby-582 add support for dynamic parameters for unary plus and minus //Now that we know the type of this parameter node, we can do the Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java Tue May 29 13:45:17 2007 @@ -36,6 +36,7 @@ import org.apache.derby.iapi.services.compiler.LocalField; import org.apache.derby.iapi.services.io.StoredFormatIds; +import org.apache.derby.iapi.types.StringDataValue; import org.apache.derby.iapi.types.TypeId; import org.apache.derby.iapi.types.DataTypeDescriptor; import org.apache.derby.iapi.types.SqlXmlUtil; @@ -269,7 +270,7 @@ * * @return The parameter operand of this unary operator else null. */ - public ParameterNode getParameterOperand() + public ParameterNode getParameterOperand() throws StandardException { if (requiresTypeFromContext() == false) return null; Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java?view=diff&rev=542646&r1=542645&r2=542646 ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java Tue May 29 13:45:17 2007 @@ -549,6 +549,12 @@ if (valueNode.requiresTypeFromContext()) { valueNode.setType(descriptor); + //? parameter should pick up the collation type of the schema in + //which this statement is getting compiled. + valueNode.getTypeServices().setCollationDerivation( + StringDataValue.COLLATION_DERIVATION_IMPLICIT); + valueNode.getTypeServices().setCollationType( + getLanguageConnectionContext().getDefaultSchema().getCollationType()); } } }