db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r552897 - in /db/derby/code/branches/10.3/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Tue, 03 Jul 2007 16:23:17 GMT
Author: djd
Date: Tue Jul  3 09:23:09 2007
New Revision: 552897

URL: http://svn.apache.org/viewvc?view=rev&rev=552897
Log:
DERBY-2809 Ensure that non-boolean expressions are not forced
as boolean expressions in conditionals.
Merge of 582822,551183,551764 from trunk


Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/DB2LengthOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ExtractOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/LengthOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/TestConstraintNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryComparisonOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryDateTimestampOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryLogicalOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java
    db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/AggregateNode.java
Tue Jul  3 09:23:09 2007
@@ -287,13 +287,11 @@
 		/* Add ourselves to the aggregateVector before we do anything else */
 		aggregateVector.addElement(this);
 
-		super.bindExpression(
-				fromList, subqueryList,
-				aggregateVector);
-
         // operand being null means a count(*)
 		if (operand != null)
 		{
+            bindOperand(fromList, subqueryList, aggregateVector);
+            
 			/*
 			** Make sure that we don't have an aggregate 
 			** IMMEDIATELY below us.  Don't search below

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/BinaryListOperatorNode.java
Tue Jul  3 09:23:09 2007
@@ -146,8 +146,6 @@
 		/* Is there a ? parameter on the left? */
 		if (leftOperand.requiresTypeFromContext())
 		{
-			ValueNode rightOperand = (ValueNode) rightOperandList.elementAt(0);
-
 			/*
 			** It's an error if both operands are all ? parameters.
 			*/

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/DB2LengthOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/DB2LengthOperatorNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/DB2LengthOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/DB2LengthOperatorNode.java
Tue Jul  3 09:23:09 2007
@@ -81,7 +81,7 @@
 		Vector	aggregateVector)
 			throws StandardException
 	{
-        ValueNode boundExpression = super.bindExpression( fromList, subqueryList, aggregateVector);
+        bindOperand( fromList, subqueryList, aggregateVector);
 
         // This operator is not allowed on XML types.
         TypeId operandType = operand.getTypeId();
@@ -93,7 +93,7 @@
 
         setType( new DataTypeDescriptor( TypeId.getBuiltInTypeId( Types.INTEGER),
                                          operand.getTypeServices().isNullable()));
-        return boundExpression;
+        return this;
     }
 
 	/**

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ExtractOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ExtractOperatorNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ExtractOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ExtractOperatorNode.java
Tue Jul  3 09:23:09 2007
@@ -90,7 +90,7 @@
 		int	operandType;
 		TypeId opTypeId;
 
-		super.bindExpression(fromList, subqueryList,
+		bindOperand(fromList, subqueryList,
 				aggregateVector);
 
 		opTypeId = operand.getTypeId();

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/LengthOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/LengthOperatorNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/LengthOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/LengthOperatorNode.java
Tue Jul  3 09:23:09 2007
@@ -94,7 +94,7 @@
 	{
 		TypeId	operandType;
 
-		super.bindExpression(fromList, subqueryList,
+		bindOperand(fromList, subqueryList,
 				aggregateVector);
 
 		/*

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/SimpleStringOperatorNode.java
Tue Jul  3 09:23:09 2007
@@ -77,7 +77,7 @@
 	{
 		TypeId	operandType;
 
-		super.bindExpression(fromList, subqueryList, 
+		bindOperand(fromList, subqueryList, 
 				aggregateVector);
 
 		/*
@@ -162,15 +162,5 @@
 	 */
 	public String getReceiverInterfaceName() {
 	    return ClassName.StringDataValue;
-	}
-
-	/**
-	 * @see ValueNode#requiresTypeFromContext
-	 */
-	public boolean requiresTypeFromContext()
-	{
-	    //should return false because lower(?)/upper(?) are bound to varchar and hence don't
-	    //require their type to be set from the context. 
-	    return false;
 	}
 }

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/TestConstraintNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/TestConstraintNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/TestConstraintNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/TestConstraintNode.java
Tue Jul  3 09:23:09 2007
@@ -89,14 +89,13 @@
 		Vector	aggregateVector)
 			throws StandardException
 	{
-		bindUnaryOperator(fromList, subqueryList, aggregateVector);
+		bindOperand(fromList, subqueryList, aggregateVector);
 
 		/*
 		** If the operand is not boolean, cast it.
 		*/
 
-		if ( ! operand.getTypeServices().getTypeId().getSQLTypeName().equals(
-														TypeId.BOOLEAN_NAME))
+		if (!operand.getTypeServices().getTypeId().isBooleanTypeId())
 		{
 			operand = (ValueNode)
 				getNodeFactory().getNode(

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryArithmeticOperatorNode.java
Tue Jul  3 09:23:09 2007
@@ -52,23 +52,6 @@
 	private final static String[] UNARY_METHODS = {"plus","minus","sqrt", "absolute"};
 
 	private int operatorType;
-
-	//when the bindExpression method is called during the normal binding phase,
-	//unary minus and unary plus dynamic parameters are not ready for
-	//binding because the type of these dynamic parameters is not yet set.
-	//For eg, consider sql select * from t1 where c1 = -?
-	//bindExpression on -? gets called from BinaryComparisonOperatorNode's
-	//bindExpression but the parameter type has not been set yet for -?
-	//Later on, in BinaryComparisonOperatorNode's bindExpression, the type
-	//of the -? gets set to the type of c1 by the setType call. 
-	//Now, at this point, we are ready to finish binding phase for -? 
-	//(This class's setType method calls the bindExpression to finish binding)
-	//In order to accomplish binding later on, we need to save the following 
-	//3 objects during first call to bindExpression and then later this 
-	//gets used in setType method when it calls the bindExpression method.
-	FromList localCopyFromList;
-	SubqueryList localCopySubqueryList;
-	Vector localAggregateVector;
   
 	/**
 	 * Initializer for a UnaryArithmeticOperatorNode
@@ -101,13 +84,26 @@
 		init(operand, UNARY_OPERATORS[this.operatorType], 
 				UNARY_METHODS[this.operatorType]);
 	}
+    
+    /**
+     * Unary + and - require their type to be set if
+     * they wrap another node (e.g. a parameter) that
+     * requires type from its context.
+     * @see ValueNode#requiresTypeFromContext
+     */
+    public boolean requiresTypeFromContext()
+    {
+        if (operatorType == UNARY_PLUS || operatorType == UNARY_MINUS)
+            return operand.requiresTypeFromContext(); 
+        return false;
+    }
 
 	/**
-	 * By default unary operators don't accept ? parameters as operands.
-	 * This can be over-ridden for particular unary operators.
-	 *
-	 *	We throw an exception if the parameter doesn't have a datatype
-	 *	assigned to it yet.
+     * For SQRT and ABS the parameter becomes a DOUBLE.
+     * For unary + and - no change is made to the
+     * underlying node. Once this node's type is set
+     * using setType, then the underlying node will have
+     * its type set.
 	 *
 	 * @exception StandardException		Thrown if ?  parameter doesn't
 	 *									have a type bound to it yet.
@@ -120,15 +116,19 @@
 		{
 			operand.setType(
 				new DataTypeDescriptor(TypeId.getBuiltInTypeId(Types.DOUBLE), true));
+            return;
 		}
+        
 		//Derby-582 add support for dynamic parameter for unary plus and minus
-		else if (operatorType == UNARY_MINUS || operatorType == UNARY_PLUS) 
+		if (operatorType == UNARY_MINUS || operatorType == UNARY_PLUS) 
 			return;
-		else if (operand.getTypeServices() == null)
-		{
-			throw StandardException.newException(SQLState.LANG_UNARY_OPERAND_PARM, operator);
-		}
+        
+        // Not expected to get here since only the above types are supported
+        // but the super-class method will throw an exception
+        super.bindParameter();
+        
 	}
+    
 	/**
 	 * Bind this operator
 	 *
@@ -146,15 +146,12 @@
 		Vector	aggregateVector)
 			throws StandardException
 	{
-		localCopyFromList = fromList;
-		localCopySubqueryList = subqueryList;
-		localAggregateVector = aggregateVector;
 		//Return with no binding, if the type of unary minus/plus parameter is not set yet.
 		if (operand.requiresTypeFromContext() && ((operatorType == UNARY_PLUS || operatorType
== UNARY_MINUS))
 				&& operand.getTypeServices() == null)
 				return this;
 
-		super.bindExpression(fromList, subqueryList,
+		bindOperand(fromList, subqueryList,
 				aggregateVector);
 
 		if (operatorType == SQRT || operatorType == ABSOLUTE)
@@ -163,15 +160,7 @@
 		}
 		else if (operatorType == UNARY_PLUS || operatorType == UNARY_MINUS)
 		{
-			TypeId operandType = operand.getTypeId();
-
-			if ( ! operandType.isNumericTypeId())
-			{
-			
-				throw StandardException.newException(SQLState.LANG_UNARY_ARITHMETIC_BAD_TYPE, 
-					(operatorType == UNARY_PLUS) ? "+" : "-", 
-					operandType.getSQLTypeName());
-			}
+            checkOperandIsNumeric(operand.getTypeId());
 		}
 		/*
 		** The result type of a +, -, SQRT, ABS is the same as its operand.
@@ -179,6 +168,22 @@
 		super.setType(operand.getTypeServices());
 		return this;
 	}
+    
+    /**
+     * Only called for Unary +/-.
+     *
+     */
+	private void checkOperandIsNumeric(TypeId operandType) throws StandardException
+	{
+	    if (!operandType.isNumericTypeId())
+	    {
+	        throw StandardException.newException(
+                    SQLState.LANG_UNARY_ARITHMETIC_BAD_TYPE, 
+	                (operatorType == UNARY_PLUS) ? "+" : "-", 
+	                        operandType.getSQLTypeName());
+	    }
+	    
+	}
 
 	/**
 	 * Do code generation for this unary plus operator
@@ -245,18 +250,17 @@
 		}
 	}
 
-	/** @see ValueNode#setType */
-	/* We are overwriting this method here because for -?/+?, we now know
+	/** We are overwriting this method here because for -?/+?, we now know
 	the type of these dynamic parameters and hence we can do the parameter
 	binding. The setType method will call the binding code after setting
 	the type of the parameter*/
 	public void setType(DataTypeDescriptor descriptor) throws StandardException
 	{
-		operand.setType(descriptor);
+        if (operand.requiresTypeFromContext() && operand.getTypeServices() == null)
+        {
+            checkOperandIsNumeric(descriptor.getTypeId());
+		    operand.setType(descriptor);
+        }
 		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
-		//binding.
-		bindExpression(localCopyFromList, localCopySubqueryList, localAggregateVector);
 	}
 }

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryComparisonOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryComparisonOperatorNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryComparisonOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryComparisonOperatorNode.java
Tue Jul  3 09:23:09 2007
@@ -74,7 +74,7 @@
 		Vector	aggregateVector)
 			throws StandardException
 	{
-		super.bindExpression(fromList, subqueryList, 
+		bindOperand(fromList, subqueryList, 
 							 aggregateVector);
 
 		/* Set type info for this node */

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryDateTimestampOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryDateTimestampOperatorNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryDateTimestampOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryDateTimestampOperatorNode.java
Tue Jul  3 09:23:09 2007
@@ -97,7 +97,7 @@
 	 *
 	 * @exception StandardException		Thrown on error
 	 */
-	protected ValueNode bindUnaryOperator(
+	public ValueNode bindExpression (
 					FromList fromList, SubqueryList subqueryList,
 					Vector aggregateVector)
 				throws StandardException
@@ -105,7 +105,7 @@
         boolean isIdentity = false; // Is this function the identity operator?
         boolean operandIsNumber = false;
         
-        super.bindUnaryOperator( fromList, subqueryList, aggregateVector);
+        bindOperand( fromList, subqueryList, aggregateVector);
         DataTypeDescriptor operandType = operand.getTypeServices();
         switch( operandType.getJDBCTypeId())
         {

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryLogicalOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryLogicalOperatorNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryLogicalOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryLogicalOperatorNode.java
Tue Jul  3 09:23:09 2007
@@ -71,7 +71,7 @@
 		Vector	aggregateVector)
 			throws StandardException
 	{
-		super.bindExpression(fromList, subqueryList,
+		bindOperand(fromList, subqueryList,
 							 aggregateVector);
 
 		/*
@@ -84,9 +84,8 @@
 		** the grammar, so this test will become useful.
 		*/
 
-		if ( ! operand.getTypeServices().getTypeId().equals(TypeId.BOOLEAN_ID))
+		if ( ! operand.getTypeServices().getTypeId().isBooleanTypeId())
 		{
-operand.treePrint();
 			throw StandardException.newException(SQLState.LANG_UNARY_LOGICAL_NON_BOOLEAN);
 		}
 

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/UnaryOperatorNode.java
Tue Jul  3 09:23:09 2007
@@ -62,7 +62,11 @@
 {
 	String	operator;
 	String	methodName;
-	int operatorType;
+    
+    /**
+     * Operator type, only valid for XMLPARSE and XMLSERIALIZE.
+     */
+	private int operatorType;
 
 	String		resultInterfaceType;
 	String		receiverInterfaceType;
@@ -72,11 +76,6 @@
 	 */
 	ValueNode	operand;
 
-	public final static int UNARY_PLUS	= 1;
-	public final static int UNARY_MINUS	= 2;
-	public final static int NOT		= 3;
-	public final static int IS_NULL		= 4;
-
 	// At the time of adding XML support, it was decided that
 	// we should avoid creating new OperatorNodes where possible.
 	// So for the XML-related unary operators we just add the
@@ -84,6 +83,12 @@
 	// TernarnyOperatorNode. Subsequent unary operators (whether
 	// XML-related or not) should follow this example when
 	// possible.
+    //
+    // This has lead to this class having somewhat of
+    // a confused personality. In one mode it is really
+    // a parent (abstract) class for various unary operator
+    // node implementations, in its other mode it is a concrete
+    // class for XMLPARSE and XMLSERIALIZE.
 
 	public final static int XMLPARSE_OP = 0;
 	public final static int XMLSERIALIZE_OP = 1;
@@ -286,6 +291,9 @@
 	/**
 	 * Bind this expression.  This means binding the sub-expressions,
 	 * as well as figuring out what the return type is for this expression.
+     * This method is the implementation for XMLPARSE and XMLSERIALIZE.
+     * Sub-classes need to implement their own bindExpression() method
+     * for their own specific rules.
 	 *
 	 * @param fromList		The FROM list for the query this
 	 *				expression is in, for binding columns.
@@ -302,36 +310,37 @@
 					Vector	aggregateVector)
 				throws StandardException
 	{
-		return bindUnaryOperator(fromList, subqueryList, aggregateVector);
+		bindOperand(fromList, subqueryList, aggregateVector);
+        if (operatorType == XMLPARSE_OP)
+            bindXMLParse();
+        else if (operatorType == XMLSERIALIZE_OP)
+            bindXMLSerialize();
+        return this;
 	}
 
 	/**
-	 * Workhorse for bindExpression. This exists so it can be called
-	 * by child classes.
+	 * Bind the operand for this unary operator.
+     * Binding the operator may change the operand node.
+     * Sub-classes bindExpression() methods need to call this
+     * method to bind the operand.
 	 */
-	protected ValueNode bindUnaryOperator(
+	protected void bindOperand(
 					FromList fromList, SubqueryList subqueryList,
 					Vector	aggregateVector)
 				throws StandardException
 	{
-		/*
-		** Operand can be null for COUNT(*) which
-		** is treated like a normal aggregate.
-		*/
-		if (operand == null)
-		{
-			return this;
-		}
-
-		//Return with no binding, if the type of unary minus/plus parameter is not set yet.
-		if (operand.requiresTypeFromContext() && ((operator.equals("-") || operator.equals("+")))
&& operand.getTypeServices() == null)
-			return this;
-
 		operand = operand.bindExpression(fromList, subqueryList,
 								aggregateVector);
 
-		if (operand.requiresTypeFromContext())
+		if (operand.requiresTypeFromContext()) {
 			bindParameter();
+            // If not bound yet then just return.
+            // The node type will be set by either
+            // this class' bindExpression() or a by
+            // a node that contains this expression.
+            if (operand.getTypeServices() == null)
+                return;
+        }
 
 		/* If the operand is not a built-in type, then generate a bound conversion
 		 * tree to a built-in type.
@@ -342,13 +351,6 @@
 		{
 			operand = operand.genSQLJavaSQLTree();
 		}
-
-		if (operatorType == XMLPARSE_OP)
-			bindXMLParse();
-		else if (operatorType == XMLSERIALIZE_OP)
-			bindXMLSerialize();
-
-		return this;
 	}
 
     /**
@@ -357,7 +359,7 @@
      *
      * @exception StandardException Thrown on error
      */
-    public void bindXMLParse() throws StandardException
+    private void bindXMLParse() throws StandardException
     {
         // Check the type of the operand - this function is allowed only on
         // string value (char) types.
@@ -397,7 +399,7 @@
      *
      * @exception StandardException Thrown on error
      */
-    public void bindXMLSerialize() throws StandardException
+    private void bindXMLSerialize() throws StandardException
     {
         TypeId operandType;
 
@@ -549,18 +551,6 @@
 					true :
 					operand.constantExpression(whereClause);
 	}
-
-	/**
-	 * @see ValueNode#requiresTypeFromContext
-	 */
-	public boolean requiresTypeFromContext()
-	{
-		if (operand == null)
-			return false;
-		else
-			return (operand.requiresTypeFromContext()); 
-	}
-
 
 	/**
 	 * Returns true if this UnaryOperatorNode is for -?/+?.

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java
Tue Jul  3 09:23:09 2007
@@ -1324,7 +1324,9 @@
 
 	/**
 	 * Returns TRUE if the type of this node will be determined from the
-	 * context in which it is getting used.
+	 * context in which it is getting used. If true is returned then
+     * after bindExpression() is called on the node, its type
+     * must be set (from the relevant context) using setType().
 	 *
 	 * @return Whether this node's type will be determined from the context
 	 */

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java
(original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ValueNodeList.java
Tue Jul  3 09:23:09 2007
@@ -283,24 +283,20 @@
 	 */
 	public DataTypeDescriptor getTypeServices() throws StandardException
 	{
-		DataTypeDescriptor	firstDTS = null;
 		int size = size();
 
 		for (int index = 0; index < size; index++)
 		{
-			ValueNode			valueNode;
-
-			valueNode = (ValueNode) elementAt(index);
+			ValueNode valueNode = (ValueNode) elementAt(index);
 			DataTypeDescriptor valueNodeDTS = valueNode.getTypeServices();
 
-			if ((firstDTS == null) && (valueNodeDTS != null))
+			if (valueNodeDTS != null)
 			{
-				firstDTS = valueNodeDTS;
-				break;
+				return valueNodeDTS;
 			}
 		}
 
-		return firstDTS;
+		return null;
 	}
 
 	/**
@@ -574,11 +570,10 @@
 						throws StandardException
 	{
 		int size = size();
-		ValueNode	valueNode;
 
 		for (int index = 0; index < size; index++)
 		{
-			valueNode = (ValueNode) elementAt(index);
+			ValueNode valueNode = (ValueNode) elementAt(index);
 			if (valueNode.requiresTypeFromContext())
 			{
 				valueNode.setType(descriptor);

Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java?view=diff&rev=552897&r1=552896&r2=552897
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
(original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
Tue Jul  3 09:23:09 2007
@@ -113,6 +113,28 @@
     public CaseExpressionTest(String name) {
         super(name);
     }
+    
+    /**
+     * Test various statements that 
+     *
+     */
+    public void testWhenNonBoolean() {
+        
+        // DERBY-2809: BOOLEAN datatype was forced upon
+        // unary expressions that were not BOOLEAN, such
+        // as SQRT(?)
+        String[] unaryOperators = {
+                "SQRT(?)", "SQRT(9)",
+                "UPPER(?)", "UPPER('haight')",
+                "LOWER(?)", "LOWER('HAIGHT')",
+        };
+        for (int i = 0; i < unaryOperators.length; i++)
+        {
+            assertCompileError("42X88",
+               "VALUES CASE WHEN " + unaryOperators[i] +
+               " THEN 3 ELSE 4 END");
+        }
+    }
 
     public void testAllDatatypesCombinationsForCaseExpressions()
     throws SQLException



Mime
View raw message