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/09/21 08:19:29 UTC

[jira] Created: (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."

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
 Assigned to: Mamta A. Satoor 


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


[jira] Resolved: (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."

Posted by "Mamta A. Satoor (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-582?page=all ]
     
Mamta A. Satoor resolved DERBY-582:
-----------------------------------

    Fix Version: 10.2.0.0
     Resolution: Fixed

Satheesh checked in the fix for this in 10.2 codeline with revision r329295.

> 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
>      Fix For: 10.2.0.0
>  Attachments: Derby582UnaryDynamic092605.txt, Derby582UnaryMinusDynamic104005.txt, Derby582UnaryParameter101105.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


[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."

Posted by "Mamta A. Satoor (JIRA)" <de...@db.apache.org>.
     [ 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


[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."

Posted by "Mamta A. Satoor (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-582?page=all ]

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

    Attachment: Derby582UnaryDynamic092605.txt

The patch fixes the problem and allows parameters for unary minus and unary plus. The parameter will be bound to DOUBLE. Can a committer please commit this if it looks good?

> 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
>
> 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


[jira] Closed: (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."

Posted by "Mamta A. Satoor (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-582?page=all ]
     
Mamta A. Satoor closed 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."
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>          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
>      Fix For: 10.2.0.0
>  Attachments: Derby582UnaryDynamic092605.txt, Derby582UnaryMinusDynamic104005.txt, Derby582UnaryParameter101105.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


[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."

Posted by "Mamta A. Satoor (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-582?page=all ]

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

    Attachment: Derby582UnaryParameter101105.txt

I have a new patch to allow dynamic parameters for unary minus and unary plus operator. This is based on the feedback from Jeff and Dan. The unary minus/plus parameters will determine their types depending on the context. For this, I have added requiresTypeFromContext to ValueNode which always returns false. ParameterNode always returns true for this method. UnaryOperatorNode's requiresTypeFromContext calls the operand's requiresTypeFromContext if operand is not null. SimpleStringOperatorNode(subclass of UnaryOperatorNode) ends up overriding this method and returns false because functions lower and upper are always typed to String and do not need to get their type from the context.

I have added 2 methods to UnaryOperatorNode.java, namely getParameterOperand() and isUnaryMinusOrPlusWithParameter(). There are few places in engine, where we need to access the underlying parameter and that is when getParameterOperand() gets used. This is required to directly call the ParameterNode methods such as  getDefaultValue(), getParameterNumber() etc isUnaryMinusOrPlusWithParameter() is required so that engine can catch edge cases like select * from t1 where -? and c11=c11 or +? ie such a use of -?/+? should be disallowed, same as what we do for ? parameters.

Also, as mentioned in the earlier review packages, the binding code for unary minus/unary plus dynamic parameters will not be executed until the type of these parameters can be determined. The type gets detemined when the setType method is called. For this reason, setType method is overridden in UnaryArithmeticOperatorNode. After setting the type, this method calls the binding code to make sure all the bind time rules are enforced.

I have also consolidated the 2 type setting methods into one, namely setType. This setType is overwritten in ParameterNode so it can also set the type in the array of parameter types in StatementNode. Hopefully, this will make the type setting code much cleaner. 

I have added several new tests to check this functionality and these tests are in unaryArithmeticDynamicParameter.java. The test will get run in both embedded and network server modes.

svn stat
M      java\engine\org\apache\derby\impl\sql\compile\CastNode.java
M      java\engine\org\apache\derby\impl\sql\compile\ResultSetNode.java
M      java\engine\org\apache\derby\impl\sql\compile\TernaryOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\HasVariantValueNodeVisitor.java
M      java\engine\org\apache\derby\impl\sql\compile\ParameterNode.java
M      java\engine\org\apache\derby\impl\sql\compile\LikeEscapeOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\Predicate.java
M      java\engine\org\apache\derby\impl\sql\compile\BinaryOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\StaticClassFieldReferenceNode.java
M      java\engine\org\apache\derby\impl\sql\compile\MethodCallNode.java
M      java\engine\org\apache\derby\impl\sql\compile\SelectNode.java
M      java\engine\org\apache\derby\impl\sql\compile\SubqueryNode.java
M      java\engine\org\apache\derby\impl\sql\compile\ResultColumn.java
M      java\engine\org\apache\derby\impl\sql\compile\VirtualColumnNode.java
M      java\engine\org\apache\derby\impl\sql\compile\ColumnDefinitionNode.java
M      java\engine\org\apache\derby\impl\sql\compile\UnaryArithmeticOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\ConditionalNode.java
M      java\engine\org\apache\derby\impl\sql\compile\TimestampOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\SimpleStringOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\JoinNode.java
M      java\engine\org\apache\derby\impl\sql\compile\SQLToJavaValueNode.java
M      java\engine\org\apache\derby\impl\sql\compile\BinaryRelationalOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\HashJoinStrategy.java
M      java\engine\org\apache\derby\impl\sql\compile\FromBaseTable.java
M      java\engine\org\apache\derby\impl\sql\compile\IsNullNode.java
M      java\engine\org\apache\derby\impl\sql\compile\SetOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\ValueNodeList.java
M      java\engine\org\apache\derby\impl\sql\compile\JavaValueNode.java
M      java\engine\org\apache\derby\impl\sql\compile\sqlgrammar.jj
M      java\engine\org\apache\derby\impl\sql\compile\CoalesceFunctionNode.java
M      java\engine\org\apache\derby\impl\sql\compile\BaseColumnNode.java
M      java\engine\org\apache\derby\impl\sql\compile\BinaryLogicalOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\LengthOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\ConcatenationOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\UnaryOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\PredicateList.java
M      java\engine\org\apache\derby\impl\sql\compile\BinaryListOperatorNode.java
M      java\engine\org\apache\derby\impl\sql\compile\NonStaticMethodCallNode.java
M      java\engine\org\apache\derby\impl\sql\compile\ColumnReference.java
M      java\engine\org\apache\derby\impl\sql\compile\ValueNode.java
M      java\engine\org\apache\derby\impl\sql\compile\ResultColumnList.java
M      java\engine\org\apache\derby\impl\sql\compile\StaticMethodCallNode.java
M      java\engine\org\apache\derby\iapi\sql\compile\OptimizablePredicate.java
M      java\engine\org\apache\derby\iapi\sql\compile\JoinStrategy.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

The patch is attached to the JIRA entry. As always, any feedback will be very appreciated.

> 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, Derby582UnaryParameter101105.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