Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 3497 invoked from network); 12 Oct 2005 06:26:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 12 Oct 2005 06:26:37 -0000 Received: (qmail 2507 invoked by uid 500); 12 Oct 2005 06:26:37 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 2267 invoked by uid 500); 12 Oct 2005 06:26:36 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Development" Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 2256 invoked by uid 99); 12 Oct 2005 06:26:36 -0000 X-ASF-Spam-Status: No, hits=1.3 required=10.0 tests=SPF_FAIL X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Oct 2005 23:26:36 -0700 Received: from ajax.apache.org (ajax.apache.org [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id 0968E516 for ; Wed, 12 Oct 2005 08:26:15 +0200 (CEST) Message-ID: <1218601819.1129098375036.JavaMail.jira@ajax.apache.org> Date: Wed, 12 Oct 2005 08:26:15 +0200 (CEST) From: "Mamta A. Satoor (JIRA)" To: derby-dev@db.apache.org Subject: [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." In-Reply-To: <1689560796.1127283569600.JavaMail.jira@ajax.apache.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N [ 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