You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Mamta A. Satoor (JIRA)" <de...@db.apache.org> on 2005/10/05 06:22:49 UTC

[jira] Updated: (DERBY-582) Dynamic parameter should be allowed to be the operand of unary operator "-". Derby throws exception 42X36: The '-' operator is not allowed to take a ? parameter as an operand."

     [ http://issues.apache.org/jira/browse/DERBY-582?page=all ]

Mamta A. Satoor updated DERBY-582:
----------------------------------

    Attachment: Derby582UnaryMinusDynamic104005.txt

This patch tries to support the type setting of unary-/unary+ parameter similar to what is done for ? parameter ie the type of the -?/+? will be dependent on the context in which it is used. And hence the type setting rules for -?/+? will be same as for a regular ? parameter. 

In order to achieve this, I have changed UnaryOperatorNode to extend ParameterNode. In addition, it has the method isParameterNode which will return true only if its operand is an instance of ParameterNode and it's method isParameterNode returns true AND the unary operator is of the type unary-/unary+. What this means is that just because a class is instance of ParameterNode doesn't automatically mean it indeed is a ParameterNode. An additional check of the isParameterNode is required to make sure there is a parameter underneath. This change in rule has required adding a new class called HasParameterNodeVisitor which gets used by the sqlgrammar to make sure there are no parameters allowed in views and triggers. HasParameterNodeVisitor checks if the node is of the type ParameterNode AND checks if the isParameterNode returns true. If yes, then the HasParameterNodeVisitor's visit method will return that node and grammar will throw an exception for parameter usage in views/trigge
 rs. 

One additional change is to not do any binding of -?/+? if the type of the parameter is not yet determined. When the type does get set using setDescriptor method, it will call the binding code on the -?/+?. 
An example here will make things clearer select * from t1 where c1 = -? 
During the bind phase of compilation, BinaryOperatorNode's bindExpression method gets called. This method first calls bindExpression on c1 and then it calls bindExpression on -?. But at this point, we don't know the type of -? and hence the bindExpression of UnaryOperatorNode simply returns w/o trying to do any binding. After the binding calls on the 2 operands, bindExpression in BinaryOperatorNode checks if the right operand is a parameter and if so, it calls setDescriptor method on it to set it's type to the type of the left operand. This is when the actual binding of -? will happen and this is accomplished by overwriting the setDescriptor method in the UnaryArithmeticOperatorNode. This method after setting the type of -? calls the binding code on it which among other checks will make sure that the type is getting set to a numeric type. 

I hope this explanation, the comments in the code and the new test makes it easier to understand the patch.

svn stat
M      java\engine\org\apache\derby\impl\sql\compile\ParameterNode.java
M      java\engine\org\apache\derby\impl\sql\compile\UnaryDateTimestampOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\UnaryArithmeticOperatorNode.java 
M      java\engine\org\apache\derby\impl\sql\compile\CollectNodesVisitor.java
M      java\engine\org\apache\derby\impl\sql\compile\HasNodeVisitor.java
M      java\engine\org\apache\derby\impl\sql\compile\sqlgrammar.jj 
A      java\engine\org\apache\derby\impl\sql\compile\HasParameterNodeVisitor.java
M      java\engine\org\apache\derby\impl\sql\compile\UnaryOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\ValueNode.java 
M      java\testing\org\apache\derbyTesting\functionTests\tests\lang\build.xml
A      java\testing\org\apache\derbyTesting\functionTests\tests\lang\unaryArithmeticDynamicParameter.java
A      java\testing\org\apache\derbyTesting\functionTests\master\unaryArithmeticDynamicParameter.out 
M      java\testing\org\apache\derbyTesting\functionTests\suites\derbylang.runall
M      java\testing\org\apache\derbyTesting\functionTests\suites\derbynetmats.runall

I have run all the tests and no new failures. I have added a new test which is part of this patch. The patch is attached to the JIRA entry. Any comments, feedback would be great.



> Dynamic parameter should be allowed to be the operand of unary operator "-". Derby throws exception 42X36: The '-' operator is not allowed to take a ? parameter as an operand."
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-582
>          URL: http://issues.apache.org/jira/browse/DERBY-582
>      Project: Derby
>         Type: Bug
>   Components: JDBC
>     Versions: 10.2.0.0
>     Reporter: Mamta A. Satoor
>     Assignee: Mamta A. Satoor
>  Attachments: Derby582UnaryDynamic092605.txt, Derby582UnaryMinusDynamic104005.txt
>
> A simple test program which uses dynamic parameter for unary operator "-" fails with an exception. Following is the snippet of the code
> 	ps = con.prepareStatement("select * from t1 where c11 = -?");
> 	ps.setInt(1,1);
> 	rs = ps.executeQuery();
> The prepareStatement call fails with following exception
> SQLSTATE(42X36):ERROR 42X36: The '-' operator is not allowed to take a ? parameter as an operand.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira